3 ms·
Can you give an example of why you think the first significant digit of "0.1+0.2" is 2? Unless you're displaying an unreasonable number of places to the right
by Gordonjcp 3y ago
Can you give an example of why you think the first significant digit of "0.1+0.2" is 2?
Unless you're displaying an unreasonable number of places to the right of the point, it's 3.
Nothing - *nothing* - needs more than about four or five significant digits.
- bazoom42 3y ago> Nothing - nothing - needs more than about four or five significant digits. So if you have a million in the bank, you would be fine with a 100$ rounding error on each transaction?
- Gordonjcp 3y agoYou don't use floats for money, because it's an integer.
- taeric 3y agoOddly, money is not an integer at large scales. At least, if you meant to calculate it in pennies, that doesn't work. Consider, what is the cost of gas?
- sweetjuly 3y agoI'm not quite sure what you mean? In most any case I can imagine, uint64 is quite enough to count money in pennies, assuming inflation doesn't get truly out of hand.
- taeric 3y agoGas is priced in sub penny values. Similarly, returns and other values are all typically calculated in sub penny values. You could store in 1/100th of a penny, I suppose? I'm not entirely sure that will work out for all calculations.
- Gordonjcp 3y agoAt present? Price at the pump is 72.9 pence per litre, which is represented internally in the software as 7290 1/100ths of a penny.
- taeric 3y agoRight, my point was just that "use pennies" won't work. You have to use fractions of a penny for different tasks. I'm not sure on the implications of using different fractions at different levels, but I'm sure the problem is more complicated than it sounds. Even before you get into the various methods of rounding that exist.
- lanstin 3y agoThere is science that uses more sig figs than tha, and for things like inverting matrices or calculating tails of distributions, you want every digit you can keep. Even just simulating dynamic systems, if you truncate, you alter your orbit. And anytime you are summing a lot of values, you want the rounding error not to go too high. I can easily imagine a million velocity data points if you are sampling say 1K/second for a twenty minute trip. Come to think of it, it would be a cool setting on game engines “8/16/32/64 bit floats”.
- nyrikki 3y agoIt effects the accumulated error when summing lots of numbers. It is a huge reason IBM mainframes are still used as they have had decimal types support for over 40 years.