accum float weirdness?

jonah's icon

why can't .3, .8, .9 floats out of accum be selected? i don't use floats often, but i was trying to make version number thingy that rolled around at .9... then playing around when it didn't work i got more confused about what's going on. :) ...it's strange to me that the message box with the 'right' value won't work being manually triggered, but if i copy and paste it back in it does...

is there a way to force more accurate(if that's the issue?) display of floats?

thanks. :)

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

either hit uzi once or t 9 times...

Peter Castine's icon

It's not a question of float display, it's an issue that floats are generally not infinitely precise and are subject to the limitations of binary representation.

In particular, values like 0.3, 0.8, and 0.9 do not exist as floats. The internal floating point representation is only an approximation (albeit one that is very close). The only floating point fractions that exist exactly are those like 0.5, 0.25, etc. (negative powers of two, or fractions that you get by adding negative powers of two).

There are numerous threads about limitations of binary representation of floating point numbers. You might want to Google the list on a combination of terms like "float" and "precision". There's also a good tutorial by Peter Elsea.

I'm not sure what you're trying to do with your patch, but in general you'll have more luck with [sel] working with integers, say 1–10, and then dividing by 10.0 when you need to do any floating point calculation.

jonah's icon

thanks. :) guess thinking decimal fractions threw me. it's not a problem for actual patch i was making when i came across this, it was just auto version numbering like 1.1...1.9 etc and writing of buffer, i used ints+ combine + sprintf instead to get it working before posting. :) just wanted to know why it seemed what was displayed wasn't matching what was happening...

reading up about floats in general...still not quite clear though...using divide object doesn't produce a float value that can be sel'd, but expr doing the dividing does. why does expr work? is there a way to force console to show what values max is actually seeing?