@@ -214,6 +214,17 @@ approximately equal component-wise.
214
214
The binary operator `≈` is equivalent to `isapprox` with the default arguments, and `x ≉ y`
215
215
is equivalent to `!isapprox(x,y)`.
216
216
217
+ Note that `x ≈ 0` (i.e., comparing to zero with the default tolerances) is
218
+ equivalent to `x == 0` since the default `atol` is `0`. In such cases, you should either
219
+ supply an appropriate `atol` (or use `norm(x) ≤ atol`) or rearrange your code (e.g.
220
+ use `x ≈ y` rather than `x - y ≈ 0`). It is not possible to pick a nonzero `atol`
221
+ automatically because it depends on the overall scaling (the "units") of your problem:
222
+ for example, in `x - y ≈ 0`, `atol=1e-9` is an absurdly small tolerance if `x` is the
223
+ [radius of the Earth](https://en.wikipedia.org/wiki/Earth_radius) in meters,
224
+ but an absurdly large tolerance if `x` is the
225
+ [radius of a Hydrogen atom](https://en.wikipedia.org/wiki/Bohr_radius) in meters.
226
+
227
+
217
228
# Examples
218
229
```jldoctest
219
230
julia> 0.1 ≈ (0.1 - 1e-10)
@@ -224,6 +235,12 @@ true
224
235
225
236
julia> isapprox([10.0^9, 1.0], [10.0^9, 2.0])
226
237
true
238
+
239
+ julia> 1e-10 ≈ 0
240
+ false
241
+
242
+ julia> isapprox(1e-10, 0, atol=1e-8)
243
+ true
227
244
```
228
245
"""
229
246
function isapprox (x:: Number , y:: Number ; atol:: Real = 0 , rtol:: Real = rtoldefault (x,y,atol), nans:: Bool = false )
0 commit comments