6 ms·
I'm afraid I don't understand the downside of nanoseconds since epoch. What accuracy problems and rounding errors? Are you suggesting that nanoseconds are too c
by mark-t 18y ago
I'm afraid I don't understand the downside of nanoseconds since epoch. What accuracy problems and rounding errors? Are you suggesting that nanoseconds are too coarse of a measurement? You could use picoseconds. No matter what, if you're storing arbitrary real numbers in a fixed number of bits, you're going to have some rounding error. Choose enough bits to make your representation "good enough" or, say, "better than your instruments, anyway". Then use integers. They're simpler and much more efficient than floats/doubles.
- richardw 18y agoI'm guessing that he's saying binary doesn't represent all numbers properly so if you need it to be absolutely accurate, you need to have a custom data type. Making it picoseconds doesn't help. Same problem with money - it's a very bad idea to use floats etc for money.
- mark-t 18y agoI covered that. There is no "absolutely accurate" in a finite number of bits, no matter what data type you use. In N bits, you can't store more than 2^N distinct numbers, and there happen to be a lot more than 2^N distinct numbers, even between 0 and 1. You have to choose your margin for error and be prepared to live with it (or use a variable width format).
- pistoriusp 18y agoIs a solution for money to convert everything to cents?
- richardw 18y agoThat can work, for some tasks. Lookit this article for more info: http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact Many languages have built-in formats for decimal data, so unless you have a really good reason (space/speed), just use those.