Working with large numbers

Sep 19, 2013 at 7:50am

Working with large numbers

Hello Forum!

I’m quite new to MAX and I’m currently trying to do the following operation:

X * (2^40)

For this I’m using the following expression:

[expr $f1*pow(2,(40))]

The problem is that said X value is normally between 200 and 3000 and the output value seems to be a bit too large for Max to process, all I get in return are odd values such as “-551903297536″, am I doing something wrong? Are these negative what I’m actually looking for? I feel a little dumb, Please help

Thanks in advance!

Sep 19, 2013 at 9:20am

max numbers are in 32 bits if you are using Max 32 bits, 64 if you’re using max 64 bits. That said, it means maximum integer in 32 bits is 2^31 – 1 (because there are negative value stoo), which is inherently smaller than 2^40 so you can’t have that result.

In 64 bits : maximum signed is 2^63 – 1 : 9,223,372,036,854,775,807. Now 2^7 < 200 < 2^8 and 2^11 < 3000 < 2^12 so your maximum will be < 2^12 * 2^40 = 2^52 ; sooo you will be able to compute an INTEGER that is the result of that operation, using max 64 bits, but not using max 32 bits.

Details :

That beeing said, i have ot ask why you are needing such values. Usually, useful values should stay inside "usual" computing range, so maybe you're trying to do something with a way that is not the right one ?… i might be wrong obviously, but maybe there's another solution.

Sep 20, 2013 at 7:08am

2^40 is no problem for floating point values, and that’s what [expr] will be giving you. But since you’re talking about integer results, somewhere in your patch you must be forcing a conversion to int. That’s still not a problem with 64-bit arithmetic (as Vichug indicated), but won’t work with 32 bit signed integers. Also, even in Max 6.1 set to 64-bit, there may still be a couple of objects that only have one leg in 64-bit land and do something odd that is 32-bit based.

How about an example of that portion of your patch where this happens? Otherwise we’re just guessing in the dark.

Sep 20, 2013 at 10:51am

i would question that you really need to do 3000^40, maybe it would be a good idea to just do something totally different. ;)


You must be logged in to reply to this topic.