ZorbaTHut (http://mandible.net) said:
it's 80-bit ieee floats internally, but there's some specialized code
to clamp it to zero when it looks like it ought to be zero.
as far as I know it should otherwise behave exactly like 80-bit ieee
(it wouldn't surprise me if the clamping code is being a little overzealous
in this case)The first thing that springs to my mind is that Google calculator is free, and more precision isn't.
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.
http://www.bing.com/search?q=999999999999999999999999999+-+9...
Pretty sloppy to not even detect overflow on the input.
another one:
http://www.google.com/#q=999999999999999999+-+90000000000000...
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 :)
It all boils down to what type you consider the entries have, opposed to what Google considers.
They use floats for everything, not ints.
edit: actually, it doesn't, the input above is 15 digits long.
I think you still have a few orders of magnitude to go before that becomes a real problem.
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.
Why in the fuck would you try to do financial math with anything but fixed-point or rational numbers?
Check out: http://www.google.com/search?q=999999999999999+*+1 this overflows into the next integer as well.
http://www.cs.niu.edu/other/pentium.html
I remember taking the chip into Digital at the time. They replaced it for me.
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?