Unsigned Long Integers

Blitz3D Forums/Blitz3D Beginners Area/Unsigned Long Integers

_PJ_(Posted 2013) [#1]
I am sure I had this issue before, but I couldn't find it on the search.

Basically I need to ensure that I always return an Unsigned Integer yet Blitz seems to automatically assume a sign:

You can see how the sign is 'attached' to the (256*256*256*255)
x=(256*256*256*255)+(256*256*255)+(255*256)+(255)
Print x

a=(256*256*256*255);Here's where the signed bit comes in!
b=(256*256*255)
c=(256*255)
d=255
Print a+"+"+b+"+"+c+"+"+d
Print b
Print c
Print a+b+c+d







Yasha(Posted 2013) [#2]
B3D simply doesn't support them.

Depending upon what you want to do, you have several options:

-- if you only want to add and subtract, the particularities of two's-complement mean that the math will actually be correct even though the number displays incorrectly, you only need to write special code to display the number, so go forth and add! You can even multiply and divide by powers of two by using shifts.

-- if you don't care much about performance, there's at least one "string math" package in the code archives that does big-integer maths using string digits (megacalculs). This will let you multiply and divide, and is not subject to the four-byte limit (it's seriously slow for division though). There are some bignum libs for BlitzMax as well, which would need to be converted but might have faster logic.

-- you could use a DLL that unlocks support for other operations. TCC can do this as C supports unsigned and also 64-bit integers, and is very easy to use (do ask and I will be delighted to demonstrate).

-- if you need really big numbers, and also performance, you could investigate wrapping a bignum library like libGMP (which is the fastest math lib out there), or farm your math out to a scripting language like Scheme that allows arbitrary-precision soft math (not my TinyScheme wrapper, that actually doesn't support it - most other Schemes would though. Gambit has the fastest math of the ones that don't just use libGMP).


_PJ_(Posted 2013) [#3]
Thanks, Yasha that really helps :)

I need big numbers but can take the perf hit!