3 ms·
I was recently thinking about writing something about fixed point vs floating point. The numbers that you can represent with floating point are exponentially d
by rustybolt 6y ago
I was recently thinking about writing something about fixed point vs floating point.
The numbers that you can represent with floating point are exponentially distributed. Floating point is well-behaved when you multiply things, and it maintains a good relative error. Addition works best when you add similar numbers. Overflow is almost impossible, but it's easy to get loss of significance.
The numbers that you can represent with fixed point are uniformly distributed. Fixed point is well-behaved when you add things, and it maintains a good absolute error. Loss of significance doesn't happen, but it's easy to get an overflow.
In both systems it's possible to accumulate error, but under normal circumstances the approximation error should average out. Fixed point makes it easier to reason about the error, floating point is a bit harder, but usually works well in practice (with some exceptions -- for example, if you add a huge array of small values you will run into trouble due to the loss of significance).
- bjackman 6y agoFixed point also has the advantage that you can do it quickly without needing a floating point unit in your CPU. That means you can do it on microcontrollers, and you can do it in the kernel without needing to save extra user context on kernel entry (this is only relevant on architectures that have separate floating point registers).
- nestorD 6y agoI have meet a surprisingly large number of people who think that fixed point arithmetic is the solution to all of their problems (probably because its use is not widespread). The big problem with fixed-point, making them a bad choice for most scientific computation (which is where the design decision for the current dominating system came from) is their lack of resolution. You can represent only a comparatively small interval of numbers and a few division|multiplication will quickly lead to large errors in the output (even if you do not hit underflows/overflows).
- mamcx 6y ago> I have meet a surprisingly large number of people who think that fixed point arithmetic is the solution to all of their problems >a bad choice for most scientific computation Is weird this. Scientific computation is at most a niche. Financial and real-world decimal calculations is the norm. That is why a lot of people could be server better by the use of decimals or fixed point.
- nestorD 6y agoIt might be me, I work with people doing simulation and ML, not game or web dev. People doing financial computations are using fixed-point for very good reasons but, other than them, the scientific people are the only one that I know of who care deeply for the results of their numerical computations.
- NovemberWhiskey 6y ago>Financial and real-world decimal calculations is the norm. A significant amount of financial calculation is not in the nature of 'sum this column of numbers'. Most computation in e.g. derivative pricing has a lot more to do with scientific computing than it does with accountancy.
- edflsafoiewq 6y agoThe big problem with fixed point is reciprocals are really bad. If you have a fixed point format that goes from 0 to 1000, then 0.0125% of the numbers are below 1/8, whereas 99.2% of the numbers are above 8. Obviously for the reciprocal to be accurate, there needs to be the same amount of numbers above 1 as below 1, like there is for floats.
- rustybolt 6y agoGood point, indeed. Fixed point works best for multiplication with numbers that are approximately 1 in magnitude.
- munchbunny 6y agoI'm not sure that fixed point actually makes it easier to reason about the error, it's just that fixed point isn't the default these days, so you have to choose to use fixed point. That means, when you do use it, it likely suits the problem you need to solve.