5 ms·
Maybe I'm just getting incurably academic, but I think "I found a bug!" is not nearly as interesting as "I found a bug!" and one of: 1) It affects millions of
by swolchok 17y ago
Maybe I'm just getting incurably academic, but I think "I found a bug!" is not nearly as interesting as "I found a bug!" and one of:
1) It affects millions of people!
2) It affects large amounts of money!
3) It is a great example of a new or rare class of bug. Here's how you can avoid introducing similar bugs into your code! Here's how we can detect these things automatically! etc.
Here, the only thing that springs to mind is IEEE floating point being used internally by Google Calculator for some reason, which I find hard to believe. Where's the insight?
- kevindication 17y agoI guess it's just a reminder not to trust a search engine with your fiduciary responsibilities?
- jacquesm 17y agohttp://www.brillig.com/debt_clock/ http://www.brillig.com/debt_clock/ I think you still have a few orders of magnitude to go before that becomes a real problem.
- joshu 17y agoI remember a programmer once griping that you still need to be careful with floats, and that double-precision still did not have neough significant digits to store the dollar to turkish lira conversion rate..
- jacquesm 17y agoIf you need floats you don't understand your problem ;)
- calcnerd256 17y agounless you're doing realtime graphics
- jacquesm 17y agoNo, you can do realtime graphics just fine with fixed point arithmetic. You can do nice matrix and vector math entirely in 16.16 fixed point. It's not as fast as having a co-processor, but there was a time that those were not standard items.
- blasdel 17y agoThe problem is not with precision, but in using floats to represent money. Why in the fuck would you try to do financial math with anything but fixed-point or rational numbers?
- bdr 17y agoWhat about: 4) It's not obvious how this bug could happen! Let's think about it!
- swolchok 17y agoWell, apparently, it was obvious. AFAICT, no one has come up with a better explanation than using IEEE floating point where bignums should be used, which I pointed out in my original comment.
- dreish 17y agoExcept that neither double nor single precision IEEE floats behave the same way as whatever numbers Google is using.
- swolchok 17y agoThe algorithm probably first decides how to do the math and then does the math. EDIT: single-precision does behave this way: -bash-3.2$ cat precision.c #include <stdio.h> int main() { float f1 = 999999999999999; float f2 = 999999999999997; printf("%f\n", f1 - f2); return 0; } -bash-3.2$ gcc precision.c -bash-3.2$ ./a.out 0.000000 I am saying that if it's not consistent with single-precision across multiple inputs, there's probably code that looks at the numbers involved and decides what kind of numeric type to use to do the calculations. In this case, single-precision floating-point happens to be a bad choice. Second edit: replacing the 7 with a 6 still prints 0. The parent is right: something else is going on here. I like the theory espoused elsewhere in this discussion that it's a result of some truncation to avoid returning nonzero when the result should be zero.
- gjm11 17y agoWhat exactly do you mean, and how does it make "using floating point arithmetic with insufficient precision" a viable explanation for this, given that none of the usual floating-point formats behave in this way?
- 17y ago
- unalone 17y agoI was curious as to what caused this. Posting to HN seemed like the fastest way to get an answer.
- jacquesm 17y agoClearly someone wasn't using 'bignum' when they should have. Pretty sloppy to not even detect overflow on the input. another one: http://www.google.com/#q=999999999999999999+-+900000000000000000&hl=en&safe=off&sa=2&fp=7b823cb19394de08 http://www.google.com/#q=999999999999999999+-+90000000000000...
- tripa 17y agoIt's not really overflow. It's more like insufficient precision.
- jacquesm 17y agoInsufficient precision implies too little bits to store the number in. These are unsigned integers, they could have been represented as integers in a 64 bit unsigned value, if the number of bits in the variable destined to hold the input is not enough and you keep on working as though there are that's overflow al right. It should have simply thrown an error: operand too large. I have a dark brown feeling that it won't be long before it does though :)
- ars 17y agoThis bug has been there for years. So I don't think they'll fix it all that fast. They use floats for everything, not ints.
- jacquesm 17y agoThat would explain it quite nicely, the decimal64 implementation of the ieee floating point data tops out at 16 digits. edit: actually, it doesn't, the input above is 15 digits long.
- mustpax 17y agoThis is clearly a floating point precision problem. It happens when are no bits small enough on the mantissa to express the difference between the two values. Check out: http://www.google.com/search?q=999999999999999+*+1 http://www.google.com/search?q=999999999999999+*+1 this overflows into the next integer as well.
- deleted 17y ago[deleted]
- deleted 17y ago[deleted]
- mid 17y agoBTW, bing does it right: http://www.bing.com/search?q=999999999999999+-+999999999999997 http://www.bing.com/search?q=999999999999999+-+9999999999999...
- nostrademons 17y agoBing gets it wrong if you add enough digits: http://www.bing.com/search?q=999999999999999999999999999+-+999999999999999999999999997 http://www.bing.com/search?q=999999999999999999999999999+-+9...
- frossie 17y agoAs does the google calculator widget: http://www.google.com/ig/directory?hl=en&url=www.google.com/ig/modules/calculator.xml http://www.google.com/ig/directory?hl=en&url=www.google....
- DanielStraight 17y agoI agree. My first thought was "who cares?" After reading all the comments, my thought was "who cares?" Now, my thought is "who cares?"
- jey 17y agoSpoken like a true "business guy". It's technically interesting behavior.
- adrianwaj 17y agoIn the early 90's the Pentium floating point error could fit your criteria: http://www.cs.niu.edu/other/pentium.html http://www.cs.niu.edu/other/pentium.html I remember taking the chip into Digital at the time. They replaced it for me.