History of `isapprox` in languages

I agree, you should understand the functions you call. But the definition of isapprox is not especially complicated (if you know what relative and absolute error mean), and it is widely used for validation suites in the Julia ecosystem so it is not an obscure function. The hard part is understanding floating-point comparisons in the first place.

But most validation tests are not like this, they are relative-error tests, because for most floating-point comparisons it is more natural to set a relative tolerance than an absolute one. And those are much more cumbersome to write: norm(a - b) <= rtol * max(norm(a), norm(b)) or similar.

For one thing, this involves writing a and/or b twice, which means that you have to write a function or use temporary variables if they are expressions and you don’t want to write/eval the expressions twice. And if the arguments are arrays, many people get it wrong on their first try — they check approximate equality elementwise rather than using a norm to set the overall scale.

The Julia stdlib and packages have thousands of validation tests that check relative errors; I don’t understand why they should all have to rewrite this code, even though it is short. (Many of the existing tests could benefit from tightened tolerances, however; @test supports compact syntax such as @test x ≈ y rtol=1e-13 for this.)

1 Like