Roots.jl icon indicating copy to clipboard operation
Roots.jl copied to clipboard

In a42 the almost_equal test is probably wrong

Open ikirill opened this issue 8 years ago • 1 comments

I mean this test:

https://github.com/JuliaMath/Roots.jl/pull/98/commits/cc03ba6e5d9a43ca8cd4d4f786eda956bbc7084b#diff-9471aab4b037f803f311ca8d2d35fe8fR558

It potentially uses the wrong type (Float64, which is not necessarily the type it's working with), and also it seems to use realmin in place of eps, where eps is the appropriate value.

I want to change it to

abs(x - y) < 32 * max(eps(x), eps(y))

which is probably what was intended anyway.

ikirill avatar Jan 02 '18 01:01 ikirill

Okay, I now found it in the original paper, the condition there is specified as x-y == 0. The test abs(x-y) <= 32 * 1e-308 essentially accomplishes the same thing, because either x-y will be on the order of max(abs(x),abs(y))*eps(), or exactly zero, so I think this is identical, slightly roundabout way of checking x-y==0.

See http://www.netlib.org/toms-2014-06-10/748 at the lines starting with PROF=(FA-FB)...

Perhaps the reason for writing it this way was the infamous maxim "don't test floating point numbers for equality", so it was a way of "fixing" x==y?

ikirill avatar Jan 04 '18 18:01 ikirill