223
223
224
224
# isapprox: approximate equality of numbers
225
225
"""
226
- isapprox(x, y; rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function)
226
+ isapprox(x, y; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps, nans::Bool=false[ , norm::Function] )
227
227
228
228
Inexact equality comparison: `true` if `norm(x-y) <= max(atol, rtol*max(norm(x), norm(y)))`. The
229
229
default `atol` is zero and the default `rtol` depends on the types of `x` and `y`. The keyword
@@ -234,10 +234,9 @@ the square root of [`eps`](@ref) of the type of `x` or `y`, whichever is bigger
234
234
This corresponds to requiring equality of about half of the significand digits. Otherwise,
235
235
e.g. for integer arguments or if an `atol > 0` is supplied, `rtol` defaults to zero.
236
236
237
- `x` and `y` may also be arrays of numbers, in which case `norm` defaults to the usual
238
- `norm` function in LinearAlgebra, but
239
- may be changed by passing a `norm::Function` keyword argument. (For numbers, `norm` is the
240
- same thing as `abs`.) When `x` and `y` are arrays, if `norm(x-y)` is not finite (i.e. `±Inf`
237
+ The `norm` keyword defaults to `abs` for numeric `(x,y)` and to `LinearAlgebra.norm` for
238
+ arrays (where an alternative `norm` choice is sometimes useful).
239
+ When `x` and `y` are arrays, if `norm(x-y)` is not finite (i.e. `±Inf`
241
240
or `NaN`), the comparison falls back to checking whether all elements of `x` and `y` are
242
241
approximately equal component-wise.
243
242
@@ -273,8 +272,10 @@ julia> isapprox(1e-10, 0, atol=1e-8)
273
272
true
274
273
```
275
274
"""
276
- function isapprox (x:: Number , y:: Number ; atol:: Real = 0 , rtol:: Real = rtoldefault (x,y,atol), nans:: Bool = false )
277
- x == y || (isfinite (x) && isfinite (y) && abs (x- y) <= max (atol, rtol* max (abs (x), abs (y)))) || (nans && isnan (x) && isnan (y))
275
+ function isapprox (x:: Number , y:: Number ;
276
+ atol:: Real = 0 , rtol:: Real = rtoldefault (x,y,atol),
277
+ nans:: Bool = false , norm:: Function = abs)
278
+ x == y || (isfinite (x) && isfinite (y) && norm (x- y) <= max (atol, rtol* max (norm (x), norm (y)))) || (nans && isnan (x) && isnan (y))
278
279
end
279
280
280
281
"""
0 commit comments