7 ms·
I'm sad to see the x87 go. I've never been able to convince anyone of the value of 80 bits of precision. Never mind that I've seen engineers convinced their sum
by WalterBright 6y ago
I'm sad to see the x87 go. I've never been able to convince anyone of the value of 80 bits of precision. Never mind that I've seen engineers convinced their sums were correct (because the computer can't be wrong) because they used insufficient precision for adding too many numbers.
But you can thank (or blame!) me for extending its life - back when Microsoft was developing their 64 bit Windows, they were all set to not save the x87 state during a context switch, effectively killing the x87. I talked them out of it.
Microsoft's VC still doesn't support the x87, their "long double" is 64 bits. I suppose that's for compatibility with other processors it supports.
I'm proud of the Digital Mars C/C++ compiler which still sports full 80 bit long doubles, as well as the D programming language which still (despite opposition) delivers 80 bit precision for type real, even for 64 bit Windows.
- rwallace 6y ago> back when Microsoft was developing their 32 bit Windows, they were all set to not save the x87 state during a context switch, effectively killing the x87 Do you mean '64-bit Windows'? (When 32-bit Windows was being developed, killing x87 would have meant killing all hardware floating point on x86.)
- WalterBright 6y agoyes, 64-bit
- dang 6y agoI edited that now. Hope that's ok.
- WalterBright 6y agoedit: Microsoft was developing their 64 bit Windows
- dang 6y agoI've doubled the 32 in your original comment. Hope that's ok.
- WalterBright 6y agoThank you.
- titzer 6y ago> they used insufficient precision for adding too many numbers. 80-bit, 128-bit or sum of 64-bit floats, doesn't matter. Summing an arbitrarily large list of floating point numbers that maximizes precision is actually a hard problem, because the order in which you add the numbers really matters due to incremental errors. Even when this problem is recognized, it turns out the most precise algorithm escaped us for decades--it's not as simple as adding them up low to high. It's only been within the past 10 years that this optimal algorithm has been discovered. 80-bit is a non-portable abomination. It's caused us decades of us "average" programmers headaches and generally has not even given experts better numerical precision. Good riddance IMHO!
- WalterBright 6y ago> this optimal algorithm I'm curious - link please?
- titzer 6y agoThere is some good background starting from the Kahan algorithm: https://en.wikipedia.org/wiki/Kahan_summation_algorithm https://en.wikipedia.org/wiki/Kahan_summation_algorithm This paper from 1993 analyzes five algorithms: https://www.semanticscholar.org/paper/The-Accuracy-of-Floating-Point-Summation-Higham/5c179d447a27c40a54b2bf8b1b2d6819e63c1a69?p2df https://www.semanticscholar.org/paper/The-Accuracy-of-Floati... Sorry I don't a reference for the "optimal" algorithm--I had it explained to me in person by someone working in the field and they didn't give me a specific place to go track it down. The gist of it is that you need to "bin" the numbers by their approximate order of magnitude and then even in each bin you need to keep a separate running estimate of the error within each bin. It's a kind of divide-and-conquer approach. AFAIR it is "optimal" with respect to minimum error, but not optimally efficient. It's apparently a hard problem!
- WalterBright 6y agoI did find this: http://code.activestate.com/recipes/393090/ http://code.activestate.com/recipes/393090/ but according to the comments on it it isn't entirely accurate, either. It is indeed a hard problem, and just having more bits is easy :-)
- dkarl 6y agoI had to debug a nasty x87-related issue with a piece of scientific computing software. The output of each version of the software was deterministic, but different versions usually (not always) gave very, very slightly different output, even if the numerical code was unchanged. This bothered the original author, but he was a hardware engineer, and his attitude towards it was basically "software sucks, you can only depend on computers if you lay out the circuits yourself." So the mystery remained until I was brought on and was able to figure out that the default settings of gcc at the time did not use any of the SSE2 instructions supported on the workstations we were targeting, instead using x87 floating point instructions. The state of the x87 stack was affected by code interleaved with the numerical code (there was a bit more going on than just number-crunching) causing the 80-bit representations to be copied to and from 64-bit registers (and hence rounded) at slightly different points in the computation. This resulted in tiny changes in the output. I added a flag to enable SSE2 instructions, and thereafter the output only changed when the numerical code was changed.
- titzer 6y agoThis has happened to thousands of people throughout the ages. The damn --ffloat-store option! Ugh!!!
- userbinator 6y agoThe state of the x87 stack was affected by code interleaved with the numerical code (there was a bit more going on than just number-crunching) causing the 80-bit representations to be copied to and from 64-bit registers (and hence rounded) at slightly different points in the computation. The x87 can load/store 80-bit floats from/to memory, so it can definitely save intermediate results in full precision if asked to; I'd call that more of a compiler flaw than anything else.
- WalterBright 6y agoThe question, though, is which give you more accurate results? :-)
- dkarl 6y ago