2 ms·
isn't this just a problem with numerical instability? Yes, but many developers aren't aware of numeric instability. Or, maybe they've heard the term, but not
by martincmartin 7y ago
isn't this just a problem with numerical instability?
Yes, but many developers aren't aware of numeric instability. Or, maybe they've heard the term, but not how it applies in practice.
People seem to go through stages when learning about floating point:
1. "When you need fractions, use floating point." At this stage, they expect "x / 3 * 3 == x" to always be true, and are surprised when things like that fail.
2. "Floating point is just approximate. So always use double, which is accurate to 15 decimal places." So this explains why you don't get exact answers, but of course doesn't explain the numerical instability in the OP's post.
3. "Cancellation can cause results to be arbitrarily far off! We need to analyze the error propagation of every expression!" This is impractical, and developers in stage 2 look at you like you're over engineering the system.
4. "In practice, using doubles 'just works' in almost all situations." If you're lucky, you can recognize when it might not work, and do error analysis only in those cases. If not, you just don't sleep well at night, wondering whether or where your code will break down. Probably some of both.
- coldcode 7y agoI learned about this back in the early 80's writing a transcendental runtime library (to be used on the F-16 fighter with Jovial). I was always afraid to read a story about some pilot in a dog fight launching a missile and having it go nuts and they were shot down because the code had issues.