Skip to content

Commit

Permalink
Style updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Dec 26, 2018
1 parent 99ec7ec commit e57ed3c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 55 deletions.
12 changes: 8 additions & 4 deletions src/SLEEF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ const IntegerType64 = Union{Int64,Vec{<:Any,Int64}}
const IntegerType32 = Union{Int32,Vec{<:Any,Int32}}
const IntegerType = Union{IntegerType64,IntegerType32}

EquivalentInteger(::Type{Float64}) = Int == Int32 ? Int32 : Int64
EquivalentInteger(::Type{Float32}) = Int32
EquivalentInteger(::Type{Vec{N,Float64}}) where N = Int == Int32 ? Vec{N,Int32} : Vec{N,Int64}
EquivalentInteger(::Type{Vec{N,Float32}}) where N = Vec{N,Int32}
fpinttype(::Type{Float64}) = Int == Int32 ? Int32 : Int64
fpinttype(::Type{Float32}) = Int32
function fpinttype(::Type{Vec{N,Float64}}) where {N}
Int == Int32 ? Vec{N,Int32} : Vec{N,Int64}
end
function fpinttype(::Type{Vec{N,Float32}}) where {N}
Vec{N,Int32}
end

@generated function Base.unsafe_trunc(::Type{I}, x::Vec{N,T}) where {N,T,I}
quote
Expand Down
4 changes: 2 additions & 2 deletions src/double.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Double(x::T) where {T<:vIEEEFloat} = Double(x, zero(T))
@inline trunclo(x::Float64) = reinterpret(Float64, reinterpret(UInt64, x) & 0xffff_ffff_f800_0000) # clear lower 27 bits (leave upper 26 bits)
@inline trunclo(x::Float32) = reinterpret(Float32, reinterpret(UInt32, x) & 0xffff_f000) # clear lowest 12 bits (leave upper 12 bits)

@inline function trunclo(x::Vec{N,Float64}) where N
@inline function trunclo(x::Vec{N,Float64}) where {N}
reinterpret(Vec{N,Float64}, reinterpret(Vec{N,UInt64}, x) & 0xffff_ffff_f800_0000) # clear lower 27 bits (leave upper 26 bits)
end
@inline function trunclo(x::Vec{N,Float32}) where N
@inline function trunclo(x::Vec{N,Float32}) where {N}
reinterpret(Vec{N,Float32}, reinterpret(Vec{N,UInt32}, x) & 0xffff_f000) # clear lowest 12 bits (leave upper 12 bits)
end

Expand Down
25 changes: 13 additions & 12 deletions src/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const min_exp2(::Type{Float32}) = -150f0
c3 = 0.5550410866482046596e-1
c2 = 0.2402265069591012214
c1 = 0.6931471805599452862
@horner x c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
return @horner x c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
end

@inline function exp2_kernel(x::FloatType32)
Expand All @@ -36,18 +36,18 @@ end
c3 = 0.5550347269f-1
c2 = 0.2402264476f0
c1 = 0.6931471825f0
@horner x c1 c2 c3 c4 c5 c6
return @horner x c1 c2 c3 c4 c5 c6
end

"""
exp2(x)
Compute the base-`2` exponential of `x`, that is `2ˣ`.
"""
function exp2(d::V) where V <: FloatType
function exp2(d::V) where {V <: FloatType}
T = eltype(d)
q = round(d)
qi = unsafe_trunc(EquivalentInteger(T), q)
qi = unsafe_trunc(fpinttype(T), q)

s = d - q

Expand All @@ -58,7 +58,8 @@ function exp2(d::V) where V <: FloatType

u = vifelse(d > max_exp2(T), T(Inf), u)
u = vifelse(d < min_exp2(T), T(0.0), u)
u

return u
end


Expand Down Expand Up @@ -98,10 +99,10 @@ end
Compute the base-`10` exponential of `x`, that is `10ˣ`.
"""
function exp10(d::V) where V <: FloatType
function exp10(d::V) where {V <: FloatType}
T = eltype(d)
q = round(T(MLOG10_2) * d)
qi = unsafe_trunc(EquivalentInteger(T), q)
qi = unsafe_trunc(fpinttype(T), q)

s = muladd(q, -L10U(T), d)
s = muladd(q, -L10L(T), s)
Expand All @@ -114,7 +115,7 @@ function exp10(d::V) where V <: FloatType
u = vifelse(d > max_exp10(T), T(Inf), u)
u = vifelse(d < min_exp10(T), T(0.0), u)

u
return u
end


Expand Down Expand Up @@ -157,7 +158,7 @@ const min_exp(::Type{<:FloatType32}) = -103.97208f0 # ≈ log 2^-1
c3 = 0.0416666666666665047591422
c2 = 0.166666666666666851703837
c1 = 0.50
@horner x c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
return @horner x c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
end

@inline function exp_kernel(x::FloatType32)
Expand All @@ -167,7 +168,7 @@ end
c3 = 0.0416664853692054748535156f0
c2 = 0.166666671633720397949219f0
c1 = 0.5f0
@horner x c1 c2 c3 c4 c5 c6
return @horner x c1 c2 c3 c4 c5 c6
end

"""
Expand All @@ -178,7 +179,7 @@ Compute the base-`e` exponential of `x`, that is `eˣ`.
function exp(d::FloatType)
T = eltype(d)
q = round(T(MLN2E) * d)
qi = unsafe_trunc(EquivalentInteger(T), q)
qi = unsafe_trunc(fpinttype(T), q)

s = muladd(q, -L2U(T), d)
s = muladd(q, -L2L(T), s)
Expand All @@ -190,5 +191,5 @@ function exp(d::FloatType)
u = vifelse(d > max_exp(T), T(Inf), u)
u = vifelse(d < min_exp(T), T(0), u)

u
return u
end
12 changes: 6 additions & 6 deletions src/hyp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ over_sch(::Type{Float32}) = 89f0
Compute hyperbolic sine of `x`.
"""
function sinh(x::V) where V <: FloatType
function sinh(x::V) where {V <: FloatType}
T = eltype(x)
u = abs(x)
d = expk2(Double(u))
Expand All @@ -28,7 +28,7 @@ end
Compute hyperbolic cosine of `x`.
"""
function cosh(x::V) where V <: FloatType
function cosh(x::V) where {V <: FloatType}
T = eltype(x)
u = abs(x)
d = expk2(Double(u))
Expand All @@ -50,7 +50,7 @@ over_th(::Type{Float32}) = 18.714973875f0
Compute hyperbolic tangent of `x`.
"""
function tanh(x::V) where V <: FloatType
function tanh(x::V) where {V <: FloatType}
T = eltype(x)
u = abs(x)
d = expk2(Double(u))
Expand All @@ -71,7 +71,7 @@ end
Compute the inverse hyperbolic sine of `x`.
"""
function asinh(x::V) where V <: FloatType
function asinh(x::V) where {V <: FloatType}
T = eltype(x)
y = abs(x)

Expand All @@ -97,7 +97,7 @@ end
Compute the inverse hyperbolic cosine of `x`.
"""
function acosh(x::V) where V <: FloatType
function acosh(x::V) where {V <: FloatType}
T = eltype(x)
d = logk2(dadd2(dmul(dsqrt(dadd2(x, T(1.0))), dsqrt(dsub2(x, T(1.0)))), x))
y = V(d)
Expand All @@ -117,7 +117,7 @@ end
Compute the inverse hyperbolic tangent of `x`.
"""
function atanh(x::V) where V <: FloatType
function atanh(x::V) where {V <: FloatType}
T = eltype(x)
u = abs(x)
d = logk2(ddiv(dadd2(T(1.0), u), dsub2(T(1.0), u)))
Expand Down
4 changes: 2 additions & 2 deletions src/log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
Returns the base `10` logarithm of `x`.
"""
function log10(a::V) where V <: FloatType
function log10(a::V) where {V <: FloatType}
T = eltype(a)
x = V(dmul(logk(a), MDLN10E(T)))

Expand All @@ -52,7 +52,7 @@ end
Returns the base `2` logarithm of `x`.
"""
function log2(a::V) where V <: FloatType
function log2(a::V) where {V <: FloatType}
T = eltype(a)
u = V(dmul(logk(a), MDLN2E(T)))

Expand Down
6 changes: 3 additions & 3 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Exponentiation operator, returns `x` raised to the power `y`.
"""
function pow(x::V, y::V) where {V <: FloatType}
T = eltype(x)
yi = unsafe_trunc(EquivalentInteger(T), y)
yi = unsafe_trunc(fpinttype(T), y)
yisint = yi == y
yisodd = isodd(yi) & yisint

Expand Down Expand Up @@ -53,7 +53,7 @@ end
Return `x^{1/3}`.
"""
function cbrt_fast(d::V) where V <: FloatType
function cbrt_fast(d::V) where {V <: FloatType}
T = eltype(d)
e = ilogbk(abs(d)) + 1
d = ldexp2k(d, -e)
Expand All @@ -77,7 +77,7 @@ end
Return `x^{1/3}`. The prefix operator `∛` is equivalent to `cbrt`.
"""
function cbrt(d::V) where V <: FloatType
function cbrt(d::V) where {V <: FloatType}
T = eltype(d)
e = ilogbk(abs(d)) + 1
d = ldexp2k(d, -e)
Expand Down
8 changes: 4 additions & 4 deletions src/priv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end
# similar to ilogbk, but argument has to be a normalized float value
@inline function ilogb2k(d::FloatType)
T = eltype(d)
I = EquivalentInteger(T)
I = fpinttype(T)
(float2integer(d) & I(exponent_raw_max(T))) - I(exponent_bias(T))
end

Expand Down Expand Up @@ -155,7 +155,7 @@ global @inline atan2k_kernel(x::Double{<:FloatType32}) = dadd(c1f, x.hi * (@horn
@inline function atan2k(y::Double{V}, x::Double{V}) where {T,V<:Union{T,Vec{<:Any,T}}}
xl0 = x < 0
if V <: Vec
q = vifelse(xl0, Vec{length(x.hi),EquivalentInteger(T)}(-2), 0)
q = vifelse(xl0, Vec{length(x.hi),fpinttype(T)}(-2), 0)
else
q = vifelse(xl0, -2, 0)
end
Expand Down Expand Up @@ -210,7 +210,7 @@ end

@inline function expk(d::Double{V}) where {T<:Union{Float32,Float64},V<:Union{T,Vec{<:Any,T}}}
q = round(V(d) * V(MLN2E))
qi = unsafe_trunc(EquivalentInteger(T), q)
qi = unsafe_trunc(fpinttype(T), q)

s = dadd(d, -q * L2U(T))
s = dadd(s, -q * L2L(T))
Expand Down Expand Up @@ -257,7 +257,7 @@ end

@inline function expk2(d::Double{V}) where {T<:Union{Float32,Float64},V<:Union{T,Vec{<:Any,T}}}
q = round(V(d) * T(MLN2E))
qi = unsafe_trunc(EquivalentInteger(T), q)
qi = unsafe_trunc(fpinttype(T), q)

s = dadd(d, -q * L2U(T))
s = dadd(s, -q * L2L(T))
Expand Down

0 comments on commit e57ed3c

Please sign in to comment.