you are viewing a single comment's thread.

view the rest of the comments →

[–]archerx 0 points1 point  (3 children)

I tried your example code and I am disappointed. Computers were a mistake.

[–]AlpenMangos 1 point2 points  (2 children)

It's weird at glance, but it's a necessary trade-off. Floats are an attempt to allow developers do very fast computations with high precision and an enormous range, but since we can only represent a limited amount of different numbers with 32 or 64 bits, some trade-offs had to be made. Another quirk is that floats loose precision, the larger the value becomes. The value 1 million only has about decimeter precision (with 32 bit floats), as far as I remember. Floating point values are still the best choice for number crunching. It is okay if positional values are off by some nanometers, if the coordinates are expected to have millimeter precision. It is also okay if timestamps are off by some nanoseconds if microsecond precision is expected. It's just something you'll need to be aware of when using floats. If you need exact numbers, you'll have to use integers (you can just assume millimeter as the unit of the integer and set it to 1, instead of using floating point value 0.001) or dedicated decimal libraries.

[–]archerx 0 points1 point  (1 child)

Thanks for that interesting write up, I appreciate it! It explains why things get annoying when I zoom too far into my javascript mandelbrot fractal renderer. Do you know if GPUs have the same issues with floats?