I don't think I understood before this week that a "fixed point number" is literally just an integer (which represents that integer divided by 1000 or something)
@b0rk the Analog Devices Blackfin DSP chip is fixed point!

@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 Can confirm. In the business software we write all currency is stored as integer + the currency in a separate field, we have a list which currencies have 0, 1, 3 or 4 decimals (everything else has 2), and when displaying to users / entering from the UI we convert (multiply/divide).

@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

£sd - Wikipedia

@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.

@b0rk agree that it took me a long time to grok as well ; maybe we should call it "fixed denominator" or "only numerators" ;-)
@b0rk which is a shame that it's not implemented in more languages by default.
@b0rk Usually divided by a power of two, so you can have N.M bits: N integer bits and M fractional bits. This also makes multiplications and additions more convenient.
@b0rk engineers don't make the best documentation writers do they? I remember fixed point as 8.8 -- 16bit register using low 8 bits for fractions(?)
@b0rk usually a power of 2 when it's binary