Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 8, 2011 8:52:39 GMT -5
I've noticed a few things going on in BEX with numbers that's really rattling my brain.
If I do z = 0 - 1, then print z, I get 65335 (long integer), if I do z = 65335+10000, I get 9799. If I do: if z = 65335+10000 then print "meh", it'll print "meh". How do I get it to display the correct value?
Is there something funny with BEX & numbers?
|
|
|
Post by jlf65 on May 8, 2011 13:13:43 GMT -5
An unsigned word is only capable of holding the values 0 to 65535. Subtract 1 from the lowest value and it wraps to the highest (0 becomes 65535). Similarly, if you add enough to exceed 65535, it wraps around to 0. This is generally called an unsigned short int on the 68000. You need a long int, and signed if you wish negative numbers. Not sure how bex handles variable types... look at the examples.
|
|
|
Post by Tom Maneiro on May 8, 2011 18:01:17 GMT -5
BEX only provides UNSIGNED types. Integers on BEX are 16-bit, and since there is no sign, the range goes to 0..65535.
For performance reasons, BEX doesn't do bounds checking on arithmetic operations, so wrapping is unavoidable here. You will need to do your own arithmetic overflow checks.
|
|
|
Post by jlf65 on May 8, 2011 22:06:12 GMT -5
No bytes or longs? Weird...
I guess he'll have to use assembly to do ints other than unsigned short.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 9, 2011 9:55:47 GMT -5
You can print unsigned longs without any problems as well .. just don't forget the & suffix. For example .. dim number as long number& = 123456789 print number&
|
|