Here's a fun little problem. Suppose you've got a system that makes use of the following struct:
struct User {
unsigned int user_id;
unsigned short access_level;
float account_balance; // stored as US dollars
}Your system is ridiculously well-tested, all the tests pass, everything works totally fine. I'll be so bold as to say it's (kinda)
(
Read more... )
It almost gives it away, but the reason you should never, ever store data that requires precision - like financial info - is because, well, ISO floating-point (i.e. the float or double types in C, C++, Java, Python, or pretty much any language) is imprecise by design. It's not possible to have arbitrary-precision numbers in POD like floats or doubles, because to have arbitrary precision you need an arbitrary number of bytes. Floating-point fudges this by storing a floating-point number encoded in fractional powers of two, which means that only numbers that are sums of integer powers of two (and fit within a certain range) are stored precisely, and such numbers are still limited by the number of available bytes. This also means that addition and multiplication aren't commutative, for obvious reasons.
Hence you could have an Office Space type problem, where adding $1 to someone's ( ... )
Reply
Reply
Reply
Reply
Reply
Leave a comment