• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Mixing variable types in a numerical calculation boriel Administrator Posts: 1,733 Threads: 54 Joined: Aug 2019 Reputation: 24 01-05-2021, 05:58 PM (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: Code:`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. « Next Oldest | Next Newest »

 Messages In This Thread Mixing variable types in a numerical calculation - by patters - 01-05-2021, 12:50 AM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 12:13 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 01:15 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 01:22 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 01:42 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 01:51 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 03:31 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 04:06 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 04:44 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 05:58 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 06:25 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:36 AM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:55 AM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 02:59 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 05:14 PM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 06:00 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 06:19 PM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 06:51 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:10 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)