4 ms·
As the author of Fixed, I'd like to make a few comments: 1. If you are above 100 billion, you are probably dropping the the 'fractions' and dealing with whole
by robaho 8y ago
As the author of Fixed, I'd like to make a few comments:
1. If you are above 100 billion, you are probably dropping the the 'fractions' and dealing with whole numbers. Most databases don't have their columns configured as Decimal(64,64) for 128 digits. It's not practical. So I would store the amounts above 100 billion in another value - the billions unit. And if you are 100s of billion, I am pretty certain you're not concerned with .0000001 dollars. Most 'terminals/receipts' couldn't show/print a number that high without truncating or the UI/representation would be all messed up.
2. I don't believe the crypto-currency space needs more than 7 places on an exchange. The CME only supports 8 decimal places in their protocol. Most of these issues are handled by reinterpreting the scale & quantity. "The satoshi is currently the smallest unit of the bitcoin currency recorded on the block chain. It is a one hundred millionth of a single bitcoin (0.00000001 BTC)." and since there can only be 21 million BTC, it easily fits - although I would probably change the code to use 8 decimal places for ease of use.
3. I might add more rounding modes. They are trivial, but there are some pretty exotic ones - so implementing them all internally, rather than externally can be problematic.
4. For the gamers that say they need float32 - there are more digits of precision in Fixed that float32 - just change the number of places in the code... if you need less significand and more decimals.
5. I've added integer Mul. It is about 2x faster than using floating point. If you avoid limiting overflow, which it doesn't, it is closer to 10x.
- andreygrehov 8y agoAny ideas on handling Ethereum gas, which is uint256?
- miohtama 8y agoGas is limited by having per block gas usage limit. One block cannot consume more than 8M gas. Uint256 comes from the fact that it is native word size for EVM and that is because of crypto operations.
- robaho 8y agonot really, except that all of them are going to zero, so fixed.Fixed should be sufficient :)
- robaho 8y agoAlso, at least in Go, it is fairly trivial to do: type Billions fixed.Fixed and then add operators to allow Fixed to be added, String() would add a B at the end etc. So 0.1 is 100 million, etc. Like I said, if you are summing into the billions, you are probably not concerned about .00001 pennies
- slededit 8y ago> if you are 100s of billion, I am pretty certain you're not concerned with .0000001 dollars Be careful with that logic. Salami fraud takes advantage of low precision. You need to maintain enough precision to make it not worthwhile for your transaction volume.