Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug or Feature?
#2
LCD Wrote:Hi Boriel, I ran into following Problem:
Code:
print at 17,0;(peek 3)*9
gives me back 247. Why is this a Problem? PEEK 3 is 255, so (PEEK 3)*9 should be calculated as 255*9=2295, so it looks like the result of this calculation is stored in UBYTE. No problem because PEEK gives back UBYTE, but a multiplication is a little bit more problematic.
Code:
dim c1 as uinteger
c1=peek(adr)
print c1*9
Works, but
Code:
dim c1 as ubyte
c1=peek(adr)
print c1*9
does not work. The same if I use such a calculation as Parameter for a sub.
Any chance to fix this?
Hmmm. I'm afraid not. This is a feature, the same way as in C, due to truncation. c1 is always uByte and you can't gues in compile time it's value, so there might be a chance that, effectively, c1 * 9 > 255. C does the same. What you get is (PEEK(x) * 9 bAND 0xFFh)
LCD Wrote:Another Problem:
Code:
print at 17,0;1<<3+2
Usually bit shifting should have the highest poriority, not the addition, thats why the result is 1<<(3+2)=32, but it should be (1<<3)+2=10.
I will check priorities, but I used C/C++ priorities. According to this Wikipedia article << and >> has lower priority than + and -
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)