I am new to Max MSP and just bought Max 5 a month ago – working pretty intensely on it at the moment. Best program ever in my opinion, but then I just stumbled upon a problem when trying to multiply 441 by 0.1 in Max: the result I get is 44.100002. So I tried to divide it by 10 instead but I got 44.099998. This is just an example but it annoys me quite a lot, as certain numbers show no problem and some, even as simple as these ones, do.

Damn, how come simple multiplications/divisions give wrong results?? Can anyone tell me if there is any way this kind of things won’t make all my patches lack of precision in the end?

Thanks to you all for contributing to this great forum, and hope I will be of some use in a near future too!

Yann

]]>The short answer is: the results are not wrong at all. They are exactly what you you should expect with digital arithmetic. 44.100002 and 44.099998 are as close as you can get to 44.1, which cannot be represented with finite precision on your computer. This is the math that your computer is using every nanosecond of every day for every program you have ever used.

The complete answer is: read “What Every Computer Scientist Should Know About Floating-Point Arithmetic,” < http://docs.sun.com/source/806-3568/ncg_goldberg.html> is one link. Don’t matter if you don’t think you’re a computer scientist, you’re programming a computer with Max and you need to know this stuff. Period.

The intermediate answer: take a piece of paper and a pencil. Divide 10 by 3, to six digits accuracy. You get 3.33333. Multiply that by 3. You get 9.99999. That’s what your computer is doing.

–

Corrected typo: ‘finite’ instead of ‘infinite’. Apols for the confusion.

On the other hand the Float Display Correction in the preferences doesn’t seem to visually correct this, which is of course not really important but would look better on the patch: it was already checked.

Anyway once again, thanks!

Yann

Apropos fixed point (@Steve): you still have the fundamental issue that arithmetic is binary. As soon as you divide by a number that isn’t a power of 2, the result can only be an approximation of the real answer. (If you dislike puns, please ignore this one). Fixed point avoids some problems of floating point, but it has it’s own issues.

Re: Float Display Correction, to be honest, I never understood exactly what it did. It’s probably documented somewhere I still haven’t read. But most options that have been introduced over the years seemed immediately obvious to me, whereas this one remains a bit mysterious…

]]>Apropos fixed point (@Steve): you still have the fundamental issue that arithmetic is binary. As soon as you divide by a number that isn’t a power of 2, the result can only be an approximation of the real answer. (If you dislike puns, please ignore this one). Fixed point avoids some problems of floating point, but it has it’s own issues.

As I suspected…it’s just that I’ve always come across posts (here and elsewhere) decrying the ‘problems with floating-point accuracy’ without mentioning fixed-point…implying that somehow fixed-point is more accurate, if not just superior in general. Having spent quite a few years with FORTH/HMSL I just got used to doing everything in fixed-point, but sure appreciate the programming convenience of floating-point.

]]>just wonders why numbers sometimes show up rounded

and sometimes not, as if the “correct number display”

option was turned on while it isnt.

sometimes i see that too and usually closing and reopening

the patcher fixes it.