Skip to content

Commit

Permalink
add doctests for frexp, expm1, exponent (JuliaLang#36352)
Browse files Browse the repository at this point in the history
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
  • Loading branch information
2 people authored and ElOceanografo committed May 4, 2021
1 parent 1f3c9eb commit a0b23fc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,16 @@ asinh(x::Number)
"""
expm1(x)
Accurately compute ``e^x-1``.
Accurately compute ``e^x-1``. It avoids the loss of precision involved in the direct
evaluation of exp(x)-1 for small values of x.
# Examples
```jldoctest
julia> expm1(1e-16)
1.0e-16
julia> exp(1e-16) - 1
0.0
```
"""
expm1(x)
expm1(x::Float64) = ccall((:expm1,libm), Float64, (Float64,), x)
Expand Down Expand Up @@ -791,6 +800,15 @@ ldexp(x::Float16, q::Integer) = Float16(ldexp(Float32(x), q))
Get the exponent of a normalized floating-point number.
Returns the largest integer `y` such that `2^y ≤ abs(x)`.
# Examples
```jldoctest
julia> exponent(6.5)
2
julia> exponent(16.0)
4
```
"""
function exponent(x::T) where T<:IEEEFloat
@noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf."))
Expand Down Expand Up @@ -841,6 +859,11 @@ end
Return `(x,exp)` such that `x` has a magnitude in the interval ``[1/2, 1)`` or 0,
and `val` is equal to ``x \\times 2^{exp}``.
# Examples
```jldoctest
julia> frexp(12.8)
(0.8, 4)
```
"""
function frexp(x::T) where T<:IEEEFloat
xu = reinterpret(Unsigned, x)
Expand Down

0 comments on commit a0b23fc

Please sign in to comment.