Skip to content

Commit

Permalink
A faster version of exp, exp2, exp10 for Floating point numbers (Juli…
Browse files Browse the repository at this point in the history
…aLang#36761)

* A faster version of exp for Float64

This is based on the Glibc algorithm which at-chriselrod (Elrond on discourse) described the algorithm of for me. It appears to be about 2x faster than the current algorithm, and equally accurate over the range for which I have tried it. It also theoretically should be easier to vectorize as branches are only used for checking for over/underflow.
  • Loading branch information
oscardssmith authored Oct 30, 2020
1 parent 300e34c commit 0097bdd
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 268 deletions.
11 changes: 3 additions & 8 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,9 @@ asinh(x::Number)
Accurately compute ``e^x-1``.
"""
expm1(x)
for f in (:exp2, :expm1)
@eval begin
($f)(x::Float64) = ccall(($(string(f)),libm), Float64, (Float64,), x)
($f)(x::Float32) = ccall(($(string(f,"f")),libm), Float32, (Float32,), x)
($f)(x::Real) = ($f)(float(x))
end
end
expm1(x::Float64) = ccall((:expm1,libm), Float64, (Float64,), x)
expm1(x::Float32) = ccall((:expm1f,libm), Float32, (Float32,), x)
expm1(x::Real) = expm1(float(x))

"""
exp2(x)
Expand Down Expand Up @@ -1186,7 +1182,6 @@ Return positive part of the high word of `x` as a `UInt32`.
# More special functions
include("special/cbrt.jl")
include("special/exp.jl")
include("special/exp10.jl")
include("special/ldexp_exp.jl")
include("special/hyperbolic.jl")
include("special/trig.jl")
Expand Down
Loading

0 comments on commit 0097bdd

Please sign in to comment.