Big Integers and Wrapping

Aloha world of Dynamo!

Have you ever been weirded out about really big Integers becoming, all of a sudden, really really small? Then look no further, because I have the answer below to that burning question :smiley:

//Maximum Integer allowed
maxInt = 9223372036854775807;
//If we add one to this number, it wraps
//to the negative minimum
negativeWrap = maxInt + 1;
//We can convert it to a Double (Decimal
//placed number) by multiplying by 1.0
makeDouble = maxInt * 1.0;
//Now that we have a Double, we have a
//much larger number range supported!
biggerDouble = makeDouble + 10;
11 Likes

You are one step ahead of me @solamour :slight_smile:

This phenomenon of wrapping is something technically called integer overflow. To put it simply, integers are like an odometer, once you get past the largest number it can fit, it will wrap to the lowest number.

This mention is related to a fix that went into Dynamo recently, and will be available for 2.9. This fix will not really prevent wrapping, because changing that could result in loss of backwards compatibility, but will raise a warning whenever it happens. This way users can be aware of the problem and maybe apply the solution Sol shared above.

One thing over which we can’t really act is external packages. These may or may not take the necessary measures to detect or prevent the problem. So, a message to package authors is to be aware of the problem and maybe considering following our lead with respect to how to handle it. Feel free to reach out if you would like us to point you to how it’s done in Dynamo.

Thank you and have a good day!

2 Likes

I’ve encountered this issue with Math.Ceiling and Math.Floor nodes, so I’ve used the functions in Python to get the intended results: math.ceil() and math.floor()

1 Like