4 ms·
I like to tell IEEE754 as an improvised story, because it's so rich in history as far as data types go. They were first introduced in 1941 on the German made Z
by bdg 13y ago
I like to tell IEEE754 as an improvised story, because it's so rich in history as far as data types go.
They were first introduced in 1941 on the German made Z3 compuer. Whic means, yup, we can blame nazis for 0.1+0.2 == 0.30000000000000004
In all seriousness, more programmers need to understand this. I've seen more than a few beginners go rant about how awesome their language X is when contrast against language Y because language Y has bugs like 0.1+0.2 ... then they're blown away when the see their language too has the same "bug".
- nraynaud 13y agofrankly I don't really understand it. I mean we do real geeky numerical computations only once in a while for a week, and then we spend a few months on CSS IE compatibility. I never remember what kind of computations break my numbers in what ways and how I know if I can safely use == or not in my case (and if I can't, how big the epsilon should be).
- mynegation 13y agoOh, with == it is pretty simple: do not _ever_ use it on floating point data.
- nraynaud 13y agogo read the paper.
- dragonwriter 13y agoScheme programmers don't have that problem, because Scheme is one of the few languages that does math in a sane manner. The whole inexact-by-default behavior of most languages with literals expressed as decimals is somewhat nutty. For all the flexibility provided by Scheme's structure (shared with other lisps), the thing I wish more languages would borrow from scheme is the numerical tower, which doesn't need Lispish syntax or any of the other features of Scheme that most people object to.
- nraynaud 13y agoI think it's a bit naïve, because transcendental number have no exact finite representation in any integral base. Having arbitrary precision helps only in some cases.
- dragonwriter 13y agoHaving arbitrary precision helps in all the cases where you start with something given as an exact decimal, and perform only operations which produce exact decimal outputs from exact decimal inputs, which isn't a particularly small set of use cases. Scheme's approach of using exact representations unless either an inexact one is explicitly requested or an operation is used which produces a result which has no exact representation is correct in the broadest number of cases at the expense if requiring a tiny bit of extra effort to exchange accuracy for efficiency where that is desired. This is, IMO, clearly the best approach for a general purpose language, and far superior to the large number of languages which lack even a convenient syntax for exact decimal literals.
- thetwiceler 13y agoI totally agree. Unless we decide to leave the field of rational numbers (with exponents, trigonometrics or nth roots), there's little reason not to keep the exact rational number around. Fortunately Haskell does this too with Data.Ratio!