multiplication float accuracy

Pieter Volger's icon

Hi all. when I multiplicate a float by 100000.0 sometimes the result is truncated but sometimes I get results I don't understand:

Max Patch
Copy patch and select New From Clipboard in Max.

357.858704 * 100000.0 = 35785872.0 ???

Could someone please demystify this for me !
Thanks a lot!

mzed's icon

I'm sorry I don't have a good link, but google "floating point precision."

Basically, every data type, including floats, have a fixed number of bits that are used to hold values. Floats are stored in scientific notation -- like 1.2345 x 10^-2 -- and they can really only handle about six digits in the decimal part. Technically, the floats in max have a 24-bit mantissa. So, floats are great for a really broad range of values, but they do not offer infinite precision.

Also Max tries to display floats attractively, so some times it's not showing you the whole picture. Type 0.999999 into a float box, and then play with the width. You'll see it displays as 1. when it's narrow.

Integers are very precise, but not as flexible. That's why we have both types.

Pieter Volger's icon

Thank you!

Cphas's icon

Message based maths (as in not using MSP) is done at the bit depth of the version of max you are using 32/64 respectively. MSP signals are always computed at 64bit depth :)