3 ms·
> 60 bits of numerator and denominator. The trouble is this isn't enough, even for ordinary usage. The numerator and denominator grow in proportion to the tota
by justinpombrio 4y ago
> 60 bits of numerator and denominator.
The trouble is this isn't enough, even for ordinary usage. The numerator and denominator grow in proportion to the total number of operations you have performed. For example, if you start with `1` and then multiply by `80/81` a thousand times, you get a number that's around 1e-6, but when expressed as a rational the numerator and denominator have hundreds of digits:
https://www.wolframalpha.com/input?i=%2880%2F81%29%5E1000 https://www.wolframalpha.com/input?i=%2880%2F81%29%5E1000
- kortex 4y agoBut how often are people using decimal types to do that? Most of the uses I could see this type being used for - currency, percent scaling, datetimes, audio/video codec frame rates - all are basically fixed point operations. Anything involving powers of 80/81 would probably need bigint based rationals anyways. Actually if you had an int64 type which was scaled by flicks, that'd give you quite a lot of latitude for most day to day stuff. https://en.m.wikipedia.org/wiki/Flick_(time) https://en.m.wikipedia.org/wiki/Flick_(time)
- justinpombrio 4y agoYeah, fixed point is different from rational, and all those examples you gave sound to me like fixed point. And that can be implemented efficiently without dedicated hardware support: the denominator is fixed, and you store the numerator as an integer. A 1/3 off discount on a $10 item is $6.67 (or $6.66 if rounding in the customer's favor), not $10/3. (Except datetime, did you mean timestamp? A timestamp is an instant in time, and it often makes sense to store it in high precision because you're saying exactly when something happened. A datetime is for communicating between humans who are using some particular calendar; it rarely makes sense to have more than minute precision.)