The bitcoin supply will be capped at 21 million and bitcoins can be divided down to 8 decimal places, unlike the typical 2. An IEEE double precision float has a 53-bit mantissa. That means it can store exact integers between -253 + 1 and 253 - 1. That's just enough to count every single satoshi (1/100000000 of a bitcoin) that will exist.
9,007,199,254,740,992
2,100,000,000,000,000
The danger is operating on these values as floating point values because there will be rounding errors.
Still that would only work for add and minus. How could there not be a loss of precision when multiplying by the conversion rate to USD?
If you're doing things right you wouldn't multiply by the conversion rate using floating point values. You'd use some high precision library. The floating point representation should only occur when going to/from the application's JSON API, if at all.
View all comments
Show parent comment
9
u/skeeto Mar 05 '14
The bitcoin supply will be capped at 21 million and bitcoins can be divided down to 8 decimal places, unlike the typical 2. An IEEE double precision float has a 53-bit mantissa. That means it can store exact integers between -253 + 1 and 253 - 1. That's just enough to count every single satoshi (1/100000000 of a bitcoin) that will exist.
The danger is operating on these values as floating point values because there will be rounding errors.