Skip to content

Commit

Permalink
Adding the two parameter version of log to fastmath.jl. (JuliaLang#25674
Browse files Browse the repository at this point in the history
)

@fastmath log(b,x) now works. This solves issue 25027.
  • Loading branch information
mcognetta authored and JeffBezanson committed Jan 22, 2018
1 parent 5ecba29 commit 7d0bcec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ mul_fast(x::T, y::T, zs::T...) where {T<:FloatTypes} =

@fastmath begin
cmp_fast(x::T, y::T) where {T<:FloatTypes} = ifelse(x==y, 0, ifelse(x<y, -1, +1))
log_fast(b::T, x::T) where {T<:FloatTypes} = log_fast(x)/log_fast(b)
end

eq_fast(x::T, y::T) where {T<:FloatTypes} = eq_float_fast(x, y)
Expand Down Expand Up @@ -366,6 +367,7 @@ sincos_fast(v) = (sin_fast(v), cos_fast(v))
log1p_fast(x::ComplexTypes) = log(1+x)
log2_fast(x::T) where {T<:ComplexTypes} = log(x) / log(convert(T,2))
log_fast(x::T) where {T<:ComplexTypes} = T(log(abs2(x))/2, angle(x))
log_fast(b::T, x::T) where {T<:ComplexTypes} = T(log(x)/log(b))
sin_fast(x::ComplexTypes) = -im*sinh(im*x)
sinh_fast(x::T) where {T<:ComplexTypes} = convert(T,1)/2*(exp(x) - exp(-x))
sqrt_fast(x::ComplexTypes) = sqrt(abs(x)) * cis(angle(x)/2)
Expand All @@ -385,7 +387,7 @@ for f in (:acos, :acosh, :angle, :asin, :asinh, :atan, :atanh, :cbrt,
end
end

for f in (:^, :atan2, :hypot, :max, :min, :minmax)
for f in (:^, :atan2, :hypot, :max, :min, :minmax, :log)
f_fast = fast_op[f]
@eval begin
# fall-back implementation for non-numeric types
Expand Down
6 changes: 3 additions & 3 deletions test/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ end
end
end
for f in (:+, :-, :*, :/, :%, :(==), :!=, :<, :<=, :>, :>=, :^,
:atan2, :hypot, :max, :min)
:atan2, :hypot, :max, :min, :log)
@eval begin
@test @fastmath($f($half, $third)) $f($half, $third)
@test @fastmath($f($third, $half)) $f($third, $half)
Expand Down Expand Up @@ -156,7 +156,7 @@ end
@test @fastmath($f($third)) $f($third) rtol=$rtol
end
end
for f in (:+, :-, :*, :/, :(==), :!=, :^)
for f in (:+, :-, :*, :/, :(==), :!=, :^, :log)
@eval begin
@test @fastmath($f($half, $third)) $f($half, $third) rtol=$rtol
@test @fastmath($f($third, $half)) $f($third, $half) rtol=$rtol
Expand All @@ -172,7 +172,7 @@ end
chalf = (1+1im)/CT(2)
cthird = (1-1im)/CT(3)

for f in (:+, :-, :*, :/, :(==), :!=, :^)
for f in (:+, :-, :*, :/, :(==), :!=, :^, :log)
@eval begin
@test @fastmath($f($chalf, $third)) $f($chalf, $third)
@test @fastmath($f($half, $cthird)) $f($half, $cthird)
Expand Down

0 comments on commit 7d0bcec

Please sign in to comment.