# History of \`isapprox\` in languages

**URL:** https://discourse.julialang.org/t/history-of-isapprox-in-languages/119347
**Category:** Numerics
**Tags:** question, numerics, approx
**Created:** [September 12, 2024, 6:51pm UTC](https://discourse.julialang.org/t/history-of-isapprox-in-languages/119347 "2024-09-12T18:51:09Z")
**Posts on this page:** 1
**Showing post:** 45

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 19, 2024, 3:57pm UTC](https://discourse.julialang.org/t/history-of-isapprox-in-languages/119347/45 "2024-09-19T15:57:37Z")

</div>

> [@Richard\_Fateman](#):
>
> In brief, anyone reading/ perhaps modifying/ your code will have to know (or ignore) the meaning of isapprox.

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.

> [@Richard\_Fateman](#):
>
> Testing for abs(a-b)\<test is really pretty clear at least for a,b, floating-point values,

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](https://discourse.julialang.org/t/how-to-add-a-tolerance-to-isapprox/118711/7) 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.)

---

_[View the full topic](https://discourse.julialang.org/t/history-of-isapprox-in-languages/119347)._
