Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiplication result greater than 255 in UINTEGER var
#1
First of all, as usual, sorry if this was discussed before... at a first sight around the arguments, i didn't find a solution.

The below code works till the "32*(PEEK 32044)" multiplicaton returns a a value within 255, but why?...

Code:
REM 32043 and 32044 store line and column values
REM the routine should return the screen attr address
DIM a AS UINTEGER
a = 22528+PEEK 32043+(32*(PEEK 32044))
REM it doesn't work if the result of the multiplication exceeds 255!
Reply
#2
...damn, it isn't the first time i find the solution my own, just after posting the topic here... :lol:

So here's the way to declare the operations:

Code:
DIM a AS UINTEGER
a = 22528+PEEK 32043+(32*(PEEK (UINTEGER, 32044)))

Thanks for watching :oops:
Reply
#3
Hi

No worries. Yes it's been discussed before and will be changed in future releases.
ZXbasic does type promoting sometimes but not always. So by default when multiplying two Byte values it will get the result as a Byte hence truncating the result. You can enforce a typecast with CAST of one of the multiplication operands and this should fix it. Try using CAST(Uinteger, 32) and tell me. :wink:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)