Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mixing variable types in a numerical calculation
(01-05-2021, 04:44 PM)patters Wrote: Ok, thanks for the update

Below is the part of my code where I originally ran into this issue. I eventually arrived at the above example while painstakingly debugging it:

castleIntactAttr=(64*CAST(UINTEGER, PEEK (n+4))+8*skyCol+PEEK (n+5)+64*PEEK (n+6)+8*skyCol+PEEK (n+7))*2

Without that CAST, it just gives the wrong answer since all the PEEK results are UBYTE.
In the above expression, did I put the CAST in the correct location?

As a "rule of thumb" whenever you use a multiplication with an UByte, you better use it.
If "SkyCol" is Ubyte, you better cast it too.

However in this case I guess 'castleIntactAttr' is a 8-bit variable?? If so, there should be not overflow. What are you trying to do there? You're adding

Also remember you can use bit shift << and >> in this case:
64 * n  is (n SHL 6) for example. Which can also be written as (n << 6) (I guess that's BRIGHT).
What happens if you set BRIGHT 1 in peek(n + 4) and peek(n + 6) ?? does this work in Sinclair BASIC??

Better use bAND, bOR, bXOR, SHL, and SHR operators for this.

Messages In This Thread
RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 05:58 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)