10.05 - 10.00 > 0.05 (in Python, but interestingly not in Mathematica)
2.000006 - 2.000005 > 0.000001 (in Python AND Mathematica)
I recently fell prey to this basic gotcha. The solution is to add an "epsilon" which determines a threshold level, e.g.
def myGreater(a, b, eps=1e-6):
return a > b + eps
In Mathematica, such problems can be completely avoided by using arbitrary-precision arithmetic, e.g.
2.000006`20 - 2.000005`20 > 0.000001`20
but at the cost of slower performance.
This article has what appears to be a good discussion of the ins and outs of fpa (one for a *very* rainy day...):
No comments:
Post a Comment