Hacker News new | past | comments | ask | show | jobs | submit login

For Floats in particular, binary implementation details leak all the time due to rounding. A number like 0.0625 can be represented in binary exactly with only 4 bits, but a number like 0.1 can only be represented approximately even when using 64 bits.

This could be solved with a rational-style data type, but I consider the fact that real-style data types don't capture that to also be the implementation leaking.




> For Floats in particular, binary implementation details leak all the time due to rounding.

No, they don't. Floats are meant to represent real numbers reasonably accurately.

Real numbers aren't fractions, and the idea of 'rounding' doesn't even apply to reals.

What you want are rational numbers, they solve your use case perfectly.

Floats don't represent rational numbers properly, and they are not meant to.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: