3 ms·
I don't want to sound dismissive, but isn't this just a problem with numerical instability? How is this different from trying to solve the following system?
by xondono 7y ago
I don't want to sound dismissive, but isn't this just a problem with numerical instability? How is this different from trying to solve the following system?
x^2+(2+y)*x+1=2
x^2+(2 -y)*x+1=3
And playing with the value of y.
I know that this example involves a sign change while the OP doesn't, but it's the same kind problem essentially, isn't it?
If I have learnt anything building PID loops on microcontrollers is that floating point can be a PITA if you are near this kind of situations.
- deleted 7y ago[deleted]
- martincmartin 7y agoisn'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.