[Closed] weird rounding errors
function bscrc32_lower str =
(
bscrctable = #(
0, 1996959894, 3993919788, 2567524794
)
bscrctable2 = #(
0, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419
)
bscrctable3=#(
0 as Integer64, 0x77073096 as Integer64, 0xEE0E612C as Integer64, 0x990951BA as Integer64,
0x076DC419 as Integer64
)
print (bscrctable[4] as string)
print (bscrctable2[4] as string)
print (bscrctable3[4] as string)
gives
“2.56752e+009”
“2.56752e+009”
“2567524864L”
Just why!? And it’s not just when converting to string. If I use it in calculations it does the same error. Is there a way to get past it?
from mxs help (as an explanation)
[quote=]The range of valid Integers in MAXScript is -2,147,483,648 to 2,147,483,647. If you perform calculations that result in integers outside of this range, you will get integer
overflow errors that are not detected by MAXScript. You must take care in designing your code to prevent or
detect this overflow yourself. The result of an overflow is typically a large
number of the wrong sign.
which,by the way, is valid range of any signed 32 bit integer value
But what can I do to prevent it? And even if I did that int64 it did the same…
well it should be 2567524794 in decimal by all other calculations…
https://www.rapidtables.com/convert/number/hex-to-decimal.html for example
yep I wasn’t really looking
though
2567524794L * 2
gives the correct answer
0x990951BA as Integer64 = 2567524864
looks mxs is converting 0x990951BA to a signed int (-1727442432) then converting (-1727442432) to an unsigned 64 bit integer.
this works though
0x990951BAL as Integer64 = 2567524794L
Ah, that worked! Thanks a lot. Have been so confused by this! So weird error!
Another way, maybe clearer:
bit.hexAsInt “0x990951BA” = -1727442502
bit.hexAsInt “0x990951BAL” = 2567524794L
the as Integer64 isn’t needed btw
bscrctable3=#(0L 0x77073096L, 0xEE0E612CL, 0x990951BAL,0x076DC419L)
should do