Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add generic fallback to all scalar functions" #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/NaNMath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
x === xf && throw(MethodError($f, (x,)))
($f)(xf)
end
if $f !== :lgamma
($f)(x) = (Base.$f)(x)
end
end
end

Expand Down Expand Up @@ -51,14 +48,6 @@
x < T(-1) ? T(NaN) : Base.log1p(x)
end

for f in (:sqrt,)
@eval ($f)(x) = (Base.$f)(x)
end

for f in (:max, :min)
@eval ($f)(x, y) = (Base.$f)(x, y)
end

sqrt(x::T) where {T<:Union{Float16, Float32, Float64}} = x < T(0) ? T(NaN) : Base.Intrinsics.sqrt_llvm(x)
sqrt(x::T) where {T<:AbstractFloat} = x < T(0) ? T(NaN) : Base.sqrt(x)
sqrt(x::Real) = sqrt(float(x))
Expand All @@ -68,13 +57,11 @@
Base.@assume_effects :total pow(x::Float32, y::Float32) = ccall((:powf,libm), Float32, (Float32,Float32), x, y)
# We `promote` first before converting to floating pointing numbers to ensure that
# e.g. `pow(::Float32, ::Int)` ends up calling `pow(::Float32, ::Float32)`
pow(x::Real, y::Real) = pow(promote(x, y)...)
pow(x::T, y::T) where {T<:Real} = pow(float(x), float(y))
pow(x, y) = ^(x, y)
pow(x::Number, y::Number) = pow(promote(x, y)...)
pow(x::T, y::T) where {T<:Number} = pow(float(x), float(y))

Check warning on line 61 in src/NaNMath.jl

View check run for this annotation

Codecov / codecov/patch

src/NaNMath.jl#L61

Added line #L61 was not covered by tests

# The following combinations are safe, so we can fall back to ^
pow(x::Number, y::Integer) = x^y
pow(x::Real, y::Integer) = x^y
pow(x::Complex, y::Complex) = x^y

"""
Expand Down
15 changes: 0 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,3 @@ end
@test NaNMath.argmin(exp,x) === -1.0
@test NaNMath.argmax(exp,x) === 3.0
end

# Test forwarding
x = 1 + 2im
for f in (:sin, :cos, :tan, :asin, :acos, :acosh, :atanh, :log, :log2, :log10,
:log1p, :sqrt)
@test @eval (NaNMath.$f)(x) == $f(x)
end

struct A end
Base.isless(::A, ::A) = false
y = A()
for f in (:max, :min)
@test @eval (NaNMath.$f)(y, y) == $f(y, y)
end
@test NaNMath.pow(x, x) == ^(x, x)
Loading