3 ms·
If you have integers that are stored in floating point types and don't need more than [mantissa] bits of precision, you can operate on them like ints and always
by pclmulqdq 4y ago
If you have integers that are stored in floating point types and don't need more than [mantissa] bits of precision, you can operate on them like ints and always* get the right result. Nobody would expect that the formula `return new_maxhp * (old_hp / old_maxhp);` would work with ints, but they see floats as magic that allow them to drop their guard about precision and rounding of operations. Unfortunately not.
Rationals have a big problem where under multiplication and division they need to be re-normalized periodically, and that re-normalization is slow (running gcd). Under addition and subtraction, rationals are great.
*the one big difference is that division rounding is different