4 ms·
Exactly! Very far from a floating point expert here, but what I do is to scale-down by a few odd prime-power factors as appropriate: Scaling down by powers of
by delhanty 8y ago
Exactly!
Very far from a floating point expert here, but what I do is to scale-down by a few odd prime-power factors as appropriate:
Scaling down by powers of 5 is obviously appropriate for decimals, currency etc.
Scaling down by powers of 3 is good for angles measured in the degrees, minutes, seconds system.
If one scales down a lot there is an increased risk of overflow, so one can compensate by scaling up some powers of 2.
The way I think of this is as using my own manual exponent bias [0].
>the exponent is stored in the range 1 .. 254 (0 and 255 have special meanings), and is interpreted by subtracting the bias for an 8-bit exponent (127) to get an exponent value in the range −126 .. +127.
So, for example, even single-precision number are always exact multiples of 1/(2^126), and I'm just changing the denominator to contain powers of 3, 5, 7, ... etc.
[0] https://en.wikipedia.org/wiki/Exponent_bias https://en.wikipedia.org/wiki/Exponent_bias
- microcolonel 8y agoIntegers are a lot less trouble for many currency problems, but I think some people are afraid of multiplying integer fractions. In financial calculations I've seen, figures are given in standard magnitudes (per cent, per mille, basis points, integer cents, etc.) which, if you're lucky with your language, can be encoded as types which can be promoted to higher precision (somewhat) transparently.