8 ms·
Can we trust floating-point numbers? (2006) [pdf]
- symmetricsaurus 12y agoIs there any separate write-up of this? Trying to read the slides to a presentation is just frustrating. (And if you can actually read the slides by themselves the presentation is probably not very good).
- personZ 12y agoInteresting, though Excel most certainly does use floating point numbers for storage and calculations (both at the time of its writing and now), and has some infamous calculation errors as a result. Maybe I misunderstood the slide. EDIT: I don't normally care much about a "downvote", but when it must be backed by ignorance I have to comment. Excel has always, and to this day, uses doubles. There is not a whit of decimal math to be found in the product. I kind of know this given that my industry is finance, and the calculation quirks of Excel (which is simply a quirk of floating point math) are something that the industry is aware of and works around. Now it by default rounds the number for presentation, but surely no one on HN would be so confused that they fail to understand the difference.
- acqq 12y agoYou are right, Excel uses doubles internally, taking care to format them as good as it can. BLAS also uses floating point numbers: singles, doubles, complex (note the S, D, Z prefixes): http://www.netlib.org/blas/ http://www.netlib.org/blas/
- andreasvc 12y agoDon't worry about downvoters, they know not what they do. Also, it's easy to accidentally press the wrong arrow and it cannot be undone. On topic: do you happen to know why Excel doesn't use decimal math? I'd imagine for most spreadsheets the performance difference shouldn't be noticeable.
- stephencanon 12y agoSpeculation: The performance impact would have been significant in the mid-1980s. They can’t change the arithmetic now because users would complain if their spreadsheets started producing different results (how many billions of dollars of contracts were negotiated based on the results of an Excel spreadsheet?)
- stephencanon 12y agoMy understanding is that Excel mostly uses double, but with a bunch of hacks bolted on to make some results “seem” right. If anything this makes the situation worse. IIRC, for example, it’s possible to construct numbers such that any desired subset of the following three properties do or do not hold: 1. a and b have the same default displayed representation 2. a and b compare equal 3. (a - b) is zero It’s been ~10 years since I really poked around at Excel numerics, so my recollection may not be perfect, but there were definitely a number of hacks beyond straightforward double-precision arithmetic when I looked at it.
- michaelochurch 12y agoBLAS doesn't use floating-point numbers? So what does it use? My impression was that BLAS was a library of fast linear algebra. Decimals are not fast, as far as I'm aware.
- Aardwolf 12y agoI think it does use them? What does "real" here mean? http://www.netlib.org/lapack/explore-html/d8/daf/saxpy_8f.html http://www.netlib.org/lapack/explore-html/d8/daf/saxpy_8f.ht... Seems to mean floating point according to this...: http://www-classes.usc.edu/engr/ce/108/text/fbk01.htm http://www-classes.usc.edu/engr/ce/108/text/fbk01.htm Please correct me if I'm wrong, I'm not that familiar with Fortran.
- sharpneli 12y agoIt does use floats. Floats are not that much of a problem as people might think. They come as a surprise for those that don't know how they work. Small course in numerical analysis would do people good. Switching to fixed point would not cure anything, just change the ways they can break. Floats actually have way superior error propagation properties compared to fixed point if your range varies widely, as it often does in physics. In a massively simplified way one can say that multiplication is error free in floats whereas in fixed point multiplication is horrible.
- dragonwriter 12y agoSwitching to arbitrary position decimal/rational would cure most easily curable problems (which are the ones that deal with simple arithmetic not working as expected.) Dealing with the bigger problems (like combining arithmetic with transcendental functions and then getting bitten by approximation issues) require using a symbolic math engine and only reducing to numeric approximations when needed (e.g., for presentation) rather than for intermediate values. "Throw floats at the problem and hope that it works okay" is a great approach for performance, but not really the best approach for correctness. Which is fine, if its a conscious decision, but its so pervasive and encouraged by most programming environments that its easy for people to forget the tradeoff that they are making.
- earlz 12y agoI code-review altcoins[1] as a hobby and stuff like this is why I give a ding to coins using floating point operations in, say, reward code, especially when it's something relatively complicated like multiplication or division. I'm just waiting for different processors to differ in the last decimal place to cause a fork on the coin's network. [1]: https://github.com/Earlz/coinreviews https://github.com/Earlz/coinreviews
- acqq 12y agoAs far as I know, all the modern processors follow the IEEE 754 standard, which is a serious and reliable standard, so if anything like that happens, it shouldn't be a processor issue. The implementations of the languages are something else, however. I suggest the fine article by Bruce Dawson: https://randomascii.wordpress.com/2013/07/16/floating-point-determinism/ https://randomascii.wordpress.com/2013/07/16/floating-point-...
- ColinDabritz 12y agoMuch of the problem with floating point is that we intuitively expect it to follow the math rules we're familiar with, but they seem to, but often don't. Most programmers realize they are 'approximate' but they don't notice consequences, such as checking for exactly equal to zero, when you need to check for "close enough" depending on your context. More subtly, but perhaps more damaging, they break properties like associative and commutative. Different orders change values, you can add tiny values repeatedly to a large value, and it won't change, breaking testing of the value... The presentation goes over many of these, but the fundamental problem, to me, is that we're falsely presenting an interface suggesting "this acts like a number" when it doesn't in many key ways. We should perhaps call them approximate pseudo numbers or something. Don't allow operators, require functions like SortOfMaybeAdd, AcculumateList... Perhaps such measures will communicate better. A fascinating world we program in...
- lmm 12y agoI've long wanted a language that defaults to a decimal type (or perhaps forces the user to specify a precision), and provides hardware floating point only as an option where requested. Something like the way Python handles integers. Most of what C-family languages do has the wrong semantics. Any program which is happy to accept round-to-even and arbitrary increases in precision would probably accept the rearrangement of arithmetic under the assumption that it was commutative, but in e.g. Java there's no way to change rounding mode, and also no way to just request an approximate answer. The defaults are a compromise that satisfies no-one.
- dragonwriter 12y ago> I've long wanted a language that defaults to a decimal type (or perhaps forces the user to specify a precision), and provides hardware floating point only as an option where requested. Scheme (via its numeric tower) and some other language default to exact types (decimal or in some cases rational if they don't have a separate exact decimal type) and only use approximate floating point types if explicitly requested (including using by using a function which inherently produces an approximate output.) Haskell can be configured by way of the default specifier to do something analogous to this in its handling of ambiguous numeric types (which includes literals, which start out with a generic type of Num a => a) , though the default default uses double precision floating point for types that can't be constrained to arbitrary precision integers -- default (Integer, Double) -- so to do this you need something like default (Integer, Rational, Double.)
- anovikov 12y agoWhy we need floating point at all now? IEEE-754 64-bit decimal appears to cover everything that's needed.
- wolfgke 12y agoThey have the same kind of rounding problems - except in base 10 instead of 2.
- dragonwriter 12y ago> They have the same kind of rounding problems - except in base 10 instead of 2 Sure, but if you aren't dealing with transcendental functions but just typical input from people and arithmetic, you don't usually introduce as many errors by rounding to a base-10 representation, so decimal floating point solves a lot of the problems (at the cost of performance if you have a system that implements it over hardware that doesn't.) You still have the big + small problem, though.
- acqq 12y agoIt is proven that the binary FP accumulates errors slower than any other bigger base when the longer scientific calculations are involved. But when you want to represent something like money, there's by definition an error as soon as you want to store 0.01 as the binary FP, and the same error doesn't happen in decimal FP.
- wolfgke 12y agoOn the other hand: If your smallest unit of money is cents (or perhaps tenth of cents), you better use large integers to store the amount of money instead of base 10 floating point numbers.
- acqq 12y ago> Why we need floating point at all now? IEEE-754 64-bit decimal appears to cover everything that's needed. IEEE-754 64-bit decimal is also a floating point representation: http://en.wikipedia.org/wiki/IEEE_754-2008 http://en.wikipedia.org/wiki/IEEE_754-2008
- stephencanon 12y agoClarification: The opening few slides (titled “who is NOT using floating point numbers”) contain a list of prominent software that uses floating-point. The author is not an idiot. Presumably this was more clear with the verbal portion of the talk intact, but it would appear to be rhetorical device: “who uses floating point? It would be easier to list who doesn’t; lots of prominent software uses floating-point…” If you don’t know who Paul Zimmermann is, you may safely assume that he knows more about floating-point than you do (actually that he knows more about computer arithmetic than you do). While there may well be errors or typos in the slides, it’s far more likely that you are misinterpreting something without the context of the talk that went along with them.