Skip to content

Commit

Permalink
Verbalize definition of isapprox in docstring (JuliaLang#39765)
Browse files Browse the repository at this point in the history
* Verbalize definition of isapprox

* More examples for isapprox
  • Loading branch information
mschauer committed Apr 3, 2021
1 parent 8d1f052 commit aaf2b9f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ end
"""
isapprox(x, y; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps, nans::Bool=false[, norm::Function])
Inexact equality comparison: `true` if `norm(x-y) <= max(atol, rtol*max(norm(x), norm(y)))`. The
default `atol` is zero and the default `rtol` depends on the types of `x` and `y`. The keyword
argument `nans` determines whether or not NaN values are considered equal (defaults to false).
Inexact equality comparison. Two numbers compare equal if their relative distance *or* their
absolute distance is within tolerance bounds: `isapprox` returns `true` if
`norm(x-y) <= max(atol, rtol*max(norm(x), norm(y)))`. The default `atol` is zero and the
default `rtol` depends on the types of `x` and `y`. The keyword argument `nans` determines
whether or not NaN values are considered equal (defaults to false).
For real or complex floating-point values, if an `atol > 0` is not specified, `rtol` defaults to
the square root of [`eps`](@ref) of the type of `x` or `y`, whichever is bigger (least precise).
Expand Down Expand Up @@ -259,20 +261,26 @@ but an absurdly large tolerance if `x` is the
# Examples
```jldoctest
julia> 0.1 ≈ (0.1 - 1e-10)
julia> isapprox(0.1, 0.15; atol=0.05)
true
julia> isapprox(10, 11; atol = 2)
julia> isapprox(0.1, 0.15; rtol=0.34)
true
julia> isapprox([10.0^9, 1.0], [10.0^9, 2.0])
julia> isapprox(0.1, 0.15; rtol=0.33)
false
julia> 0.1 + 1e-10 ≈ 0.1
true
julia> 1e-10 ≈ 0
false
julia> isapprox(1e-10, 0, atol=1e-8)
true
julia> isapprox([10.0^9, 1.0], [10.0^9, 2.0]) # using `norm`
true
```
"""
function isapprox(x::Number, y::Number;
Expand Down

0 comments on commit aaf2b9f

Please sign in to comment.