is there anyway to go over 2147483647

Blitz3D Forums/Blitz3D Beginners Area/is there anyway to go over 2147483647

Polarix(Posted 2016) [#1]
.


Zethrax(Posted 2016) [#2]
For integer values you're limited to 32 bit signed integers with Blitz3D. If you need to store larger values then you're going to need to store them in multiple integer variables, and you'll need to detect if a value has exceeded the max positive value. Max positve + 1 will wrap over to the maximum negative value, so you can check if the resulting value is less than zero and then subtract the max positive value from the result to get the amount over max positive that you've ended up.

eg (untested).

Const MAX_POSITIVE = 2147483647

val1 = 2147483647
val2 = 10

low = 0
high = 0

;-

wrapped = 0

result = val1 + val2

If result < 0 Then wrapped = 1

If wrapped
low = MAX_POSITIVE
high = result - MAX_POSITIVE
Else
low = result
high = 0
EndIf

--

But unless you have an actual need to accommodate large numbers then you're far better off trying to find a way to keep things clipped to within a sane and predictable range.

max_gumdrops = 10000
num_gumdrops = 10001
If num_gumdrops > max_gumdrops
num_gumdrops = max_gumdrops
Print "You've run out of space for your gumdrops, bud. No more gumdrops for you."
EndIf


Bobysait(Posted 2016) [#3]
Floating point variable can exceed this limit, but with a loss of precision.

Else, you can also encode your variable with a string, but you'll have to create functions to add/subsctract/divide/etc strings
And ... it will be pretty slow, so it would really be in there is a real need for that.

ps : unless very large data base with unique ID that could exceed billions, I've never seen a case where Long variable was really a need.
Maybe your problem can be solved with another way ?


steve_ancell(Posted 2016) [#4]
@RealEyesRealiseRealLies

May I ask what you are trying to deal with 2147483647 of?