I\'m using the following function to approximate the derivative of a function at a point:
def prime_x(f, x, h):
if not f(x+h) == f(x) and not h == 0.0:
When you subtract two numbers that are almost the same, the result has much less precision than either of the inputs. This reduces the precision of the overall result.
Suppose you have the following two numbers, good to 15 decimal places:
1.000000000000001
- 1.000000000000000
= 0.000000000000001
See what happened? The result only has one good digit.