@b0rk ... which explains the word "float" and (mostly) the even stranger term "double".
I'm told that, when storing amounts of money (e.g., in banking), you're supposed to use fixed-point numbers (integer numbers of pennies) to avoid surprising rounding errors.
@peterdrake @b0rk That's what it is made for. But it ismore than that:
Floats – by design – makes it difficult to you to foresee whether an addition has at least some effect. It is possible to add to floats without changing it.
+ Floats have exponents to binary mantissa so some numbers, that can be represented with two decimal digits, do not have a float representation.
Floats are for sciencists. Fixed are for banks.
@b0rk although there’s some nuance when working with them, for example: multiplication would be (a*b+500)/1000
(edited to add rounding, thanks @peturdainn)
@b0rk Yes! I always explain it as "Thinking in pennies or pence, but writing it in dollars or pounds."
Sometimes even a complicated old-fashioned system like LSD currency (12 pennies to the shilling, 20 shillings to the pound) can just be done in pence and divided by 240 to get pounds, and then the remainder by 12 to get shillings with the second remainder in pence.
Take that, Charlemagne!
https://en.wikipedia.org/wiki/%C2%A3sd
@b0rk In my experience, an integer divided by a power of two. I did a lot of scaled fixed point calculations in 8-bit single precision. If you multiply two 8-bit numbers, you get a 16 bit result. You have to take into account the scaling of the multiplicand and multiplier to determine which 8 bits to store as the new multiplicand.
Fun stuff when working in assembly language for embedded 8-bit processors.
@b0rk an interesting nuance, which you can see in these replies, is that the choice of base largely depends on which of the two typical uses for fixed point that you're discussing.
For financial calculations, you'd typically use a power of 10, because accounting regulations about rounding are written using that language.
When you're trying to wring decent real-number performance out of lower-power hardware, it's more typical to use a power of 2, so you can use shift to divide.