Skip to content

Commit fffd2e1

Browse files
committed
Fixes for 0.7 and update function types
1 parent d0cc8de commit fffd2e1

File tree

9 files changed

+56
-51
lines changed

9 files changed

+56
-51
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.6-pre
1+
julia 0.6

src/SLEEF.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ for func in (:atan2, :hypot)
108108
$func(a::Float16, b::Float16) = Float16($func(Float32(a), Float32(b)))
109109
end
110110
end
111+
ldexp(x::Float16, q::Int) = Float16(ldexpk(Float32(x), q))
111112

112113
end

src/exp.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# exported exponential functions
22

33
"""
4-
ldexp(a, n::Int) -> IEEEFloat
4+
ldexp(a, n)
55
66
Computes `a × 2^n`
77
"""
8-
ldexp(x::IEEEFloat, q::Int) = ldexpk(x, q)
8+
ldexp(x::Union{Float32,Float64}, q::Int) = ldexpk(x, q)
99

1010

1111
const max_exp2(::Type{Float64}) = 1024
@@ -16,7 +16,7 @@ const max_exp2(::Type{Float32}) = 128f0
1616
1717
Compute the base-`2` exponential of `x`, that is `2ˣ`.
1818
"""
19-
function exp2(x::T) where {T<:IEEEFloat}
19+
function exp2(x::T) where {T<:Union{Float32,Float64}}
2020
u = expk(dmul(MDLN2(T), x))
2121
x > max_exp2(T) && (u = T(Inf))
2222
isninf(x) && (u = T(0.0))
@@ -32,7 +32,7 @@ const max_exp10(::Type{Float32}) = 38.531839419103626f0 # log 2^127 *(2-2^-23)
3232
3333
Compute the base-`10` exponential of `x`, that is `10ˣ`.
3434
"""
35-
function exp10(x::T) where {T<:IEEEFloat}
35+
function exp10(x::T) where {T<:Union{Float32,Float64}}
3636
u = expk(dmul(MDLN10(T), x))
3737
x > max_exp10(T) && (u = T(Inf))
3838
isninf(x) && (u = T(0.0))
@@ -51,7 +51,7 @@ const min_expm1(::Type{Float32}) = -17.3286790847778338076068394f0
5151
5252
Compute `eˣ- 1` accurately for small values of `x`.
5353
"""
54-
function expm1(x::T) where {T<:IEEEFloat}
54+
function expm1(x::T) where {T<:Union{Float32,Float64}}
5555
u = T(dadd2(expk2(Double(x)), -T(1.0)))
5656
x > max_expm1(T) && (u = T(Inf))
5757
x < min_expm1(T) && (u = -T(1.0))
@@ -97,7 +97,7 @@ const c1f = 0.5f0
9797
global @inline exp_kernel(x::Float64) = @horner x c1d c2d c3d c4d c5d c6d c7d c8d c9d c10d c11d
9898
global @inline exp_kernel(x::Float32) = @horner x c1f c2f c3f c4f c5f c6f
9999

100-
function exp(d::T) where {T<:IEEEFloat}
100+
function exp(d::T) where {T<:Union{Float32,Float64}}
101101
q = unsafe_trunc(Int, round(T(MLN2E) * d))
102102
s = muladd(q, -L2U(T), d)
103103
s = muladd(q, -L2L(T), s)

src/hyp.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ over_sch(::Type{Float32}) = 89f0
88
99
Compute hyperbolic sine of `x`.
1010
"""
11-
function sinh(x::T) where {T<:IEEEFloat}
11+
function sinh(x::T) where {T<:Union{Float32,Float64}}
1212
u = abs(x)
1313
d = expk2(Double(u))
1414
d = dsub(d, drec(d))
@@ -27,7 +27,7 @@ end
2727
2828
Compute hyperbolic cosine of `x`.
2929
"""
30-
function cosh(x::T) where {T<:IEEEFloat}
30+
function cosh(x::T) where {T<:Union{Float32,Float64}}
3131
u = abs(x)
3232
d = expk2(Double(u))
3333
d = dadd(d, drec(d))
@@ -48,7 +48,7 @@ over_th(::Type{Float32}) = 18.714973875f0
4848
4949
Compute hyperbolic tangent of `x`.
5050
"""
51-
function tanh(x::T) where {T<:IEEEFloat}
51+
function tanh(x::T) where {T<:Union{Float32,Float64}}
5252
u = abs(x)
5353
d = expk2(Double(u))
5454
e = drec(d)
@@ -68,7 +68,7 @@ end
6868
6969
Compute the inverse hyperbolic sine of `x`.
7070
"""
71-
function asinh(x::T) where {T<:IEEEFloat}
71+
function asinh(x::T) where {T<:Union{Float32,Float64}}
7272
y = abs(x)
7373

7474
d = y > 1 ? drec(x) : Double(y, T(0.0))
@@ -92,7 +92,7 @@ end
9292
9393
Compute the inverse hyperbolic cosine of `x`.
9494
"""
95-
function acosh(x::T) where {T<:IEEEFloat}
95+
function acosh(x::T) where {T<:Union{Float32,Float64}}
9696
d = logk2(dadd2(dmul(dsqrt(dadd2(x, T(1.0))), dsqrt(dsub2(x, T(1.0)))), x))
9797
y = T(d)
9898

@@ -111,7 +111,7 @@ end
111111
112112
Compute the inverse hyperbolic tangent of `x`.
113113
"""
114-
function atanh(x::T) where {T<:IEEEFloat}
114+
function atanh(x::T) where {T<:Union{Float32,Float64}}
115115
u = abs(x)
116116
d = logk2(ddiv(dadd2(T(1.0), u), dsub2(T(1.0), u)))
117117
u = u > T(1.0) ? T(NaN) : (u == T(1.0) ? T(Inf) : T(d) * T(0.5))

src/log.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ where `significand ∈ [1, 2)`.
1919
* `x = ±Inf` returns `INT_MAX`
2020
* `x = NaN` returns `FP_ILOGBNAN`
2121
"""
22-
function ilogb(x::T) where {T<:IEEEFloat}
22+
function ilogb(x::T) where {T<:Union{Float32,Float64}}
2323
e = ilogbk(abs(x))
2424
x == 0 && (e = FP_ILOGB0)
2525
isnan(x) && (e = FP_ILOGBNAN)
@@ -33,7 +33,7 @@ end
3333
3434
Returns the base `10` logarithm of `x`.
3535
"""
36-
function log10(a::T) where {T<:IEEEFloat}
36+
function log10(a::T) where {T<:Union{Float32,Float64}}
3737
x = T(dmul(logk(a), MDLN10E(T)))
3838

3939
isinf(a) && (x = T(Inf))
@@ -49,7 +49,7 @@ end
4949
5050
Returns the base `2` logarithm of `x`.
5151
"""
52-
function log2(a::T) where {T<:IEEEFloat}
52+
function log2(a::T) where {T<:Union{Float32,Float64}}
5353
u = T(dmul(logk(a), MDLN2E(T)))
5454

5555
isinf(a) && (u = T(Inf))
@@ -68,7 +68,7 @@ const over_log1p(::Type{Float32}) = 1f38
6868
6969
Accurately compute the natural logarithm of 1+x.
7070
"""
71-
function log1p(a::T) where {T<:IEEEFloat}
71+
function log1p(a::T) where {T<:Union{Float32,Float64}}
7272
x = T(logk2(dadd2(a, T(1.0))))
7373

7474
a > over_log1p(T) && (x = T(Inf))
@@ -86,7 +86,7 @@ end
8686
Compute the natural logarithm of `x`. The inverse of the natural logarithm is
8787
the natural expoenential function `exp(x)`
8888
"""
89-
function log(d::T) where {T<:IEEEFloat}
89+
function log(d::T) where {T<:Union{Float32,Float64}}
9090
x = T(logk(d))
9191

9292
isinf(d) && (x = T(Inf))
@@ -140,7 +140,7 @@ const c1f = 2f0
140140
global @inline log_fast_kernel(x::Float64) = @horner x c1d c2d c3d c4d c5d c6d c7d c8d
141141
global @inline log_fast_kernel(x::Float32) = @horner x c1f c2f c3f c4f c5f
142142

143-
function log_fast(d::T) where {T<:IEEEFloat}
143+
function log_fast(d::T) where {T<:Union{Float32,Float64}}
144144
o = d < realmin(T)
145145
o && (d *= T(Int64(1) << 32) * T(Int64(1) << 32))
146146

src/misc.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Exponentiation operator, returns `x` raised to the power `y`.
66
"""
7-
function pow(x::T, y::T) where {T<:IEEEFloat}
7+
function pow(x::T, y::T) where {T<:Union{Float32,Float64}}
88
yi = unsafe_trunc(Int, y)
99
yisint = yi == y
1010
yisodd = isodd(yi) && yisint
@@ -51,7 +51,7 @@ global @inline cbrt_kernel(x::Float32) = @horner x c1f c2f c3f c4f c5f c6f
5151
5252
Return `x^{1/3}`.
5353
"""
54-
function cbrt_fast(d::T) where {T<:IEEEFloat}
54+
function cbrt_fast(d::T) where {T<:Union{Float32,Float64}}
5555
e = ilogbk(abs(d)) + 1
5656
d = ldexpk(d, -e)
5757
r = (e + 6144) % 3
@@ -74,7 +74,7 @@ end
7474
7575
Return `x^{1/3}`. The prefix operator `∛` is equivalent to `cbrt`.
7676
"""
77-
function cbrt(d::T) where {T<:IEEEFloat}
77+
function cbrt(d::T) where {T<:Union{Float32,Float64}}
7878
e = ilogbk(abs(d)) + 1
7979
d = ldexpk(d, -e)
8080
r = (e + 6144) % 3
@@ -108,7 +108,7 @@ end
108108
"""
109109
hypot(x,y)
110110
111-
Compute the hypotenuse `\sqrt{x^2+y^2}` avoiding overflow and underflow.
111+
Compute the hypotenuse `\\sqrt{x^2+y^2}` avoiding overflow and underflow.
112112
"""
113113
function hypot(x::T, y::T) where {T<:IEEEFloat}
114114
x = abs(x)
@@ -117,5 +117,5 @@ function hypot(x::T, y::T) where {T<:IEEEFloat}
117117
x, y = y, x
118118
end
119119
r = (x == 0) ? y : y / x
120-
x * sqrt(T(1) + r * r)
120+
x * sqrt(T(1.0) + r * r)
121121
end

src/priv.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ end
2727
@inline split_exponent(::Type{Float32}, q::Int) = _split_exponent(q, UInt(6), UInt(31), UInt(2))
2828

2929
"""
30-
ldexpk(a::IEEEFloat, n::Int) -> IEEEFloat
30+
ldexpk(a, n)
3131
3232
Computes `a × 2^n`.
3333
"""
34-
@inline function ldexpk(x::T, q::Int) where {T<:IEEEFloat}
34+
@inline function ldexpk(x::T, q::Int) where {T<:Union{Float32,Float64}}
3535
bias = exponent_bias(T)
3636
emax = exponent_raw_max(T)
3737
m, q = split_exponent(T, q)
@@ -45,11 +45,11 @@ Computes `a × 2^n`.
4545
x * u
4646
end
4747

48-
@inline function ldexp2k(x::T, e::Int) where {T<:IEEEFloat}
48+
@inline function ldexp2k(x::T, e::Int) where {T<:Union{Float32,Float64}}
4949
x * pow2i(T, e >> 1) * pow2i(T, e - (e >> 1))
5050
end
5151

52-
@inline function ldexp3k(x::T, e::Int) where {T<:IEEEFloat}
52+
@inline function ldexp3k(x::T, e::Int) where {T<:Union{Float32,Float64}}
5353
reinterpret(T, reinterpret(Unsigned, x) + (Int64(e) << significand_bits(T)) % fpinttype(T))
5454
end
5555

@@ -58,7 +58,7 @@ const threshold_exponent(::Type{Float64}) = 300
5858
const threshold_exponent(::Type{Float32}) = 64
5959

6060
"""
61-
ilogbk(x::IEEEFloat) -> Int
61+
ilogbk(x) -> Int
6262
6363
Returns the integral part of the logarithm of `|x|`, using 2 as base for the logarithm; in other
6464
words this returns the binary exponent of `x` so that
@@ -67,14 +67,14 @@ words this returns the binary exponent of `x` so that
6767
6868
where `significand ∈ [1, 2)`.
6969
"""
70-
@inline function ilogbk(d::T) where {T<:IEEEFloat}
70+
@inline function ilogbk(d::T) where {T<:Union{Float32,Float64}}
7171
m = d < T(2)^-threshold_exponent(T)
7272
d = ifelse(m, d * T(2)^threshold_exponent(T), d)
7373
q = float2integer(d) & exponent_raw_max(T)
7474
q = ifelse(m, q - (threshold_exponent(T) + exponent_bias(T)), q - exponent_bias(T))
7575
end
7676

77-
@inline function ilogb2k(d::T) where {T<:IEEEFloat}
77+
@inline function ilogb2k(d::T) where {T<:Union{Float32,Float64}}
7878
(float2integer(d) & exponent_raw_max(T)) - exponent_bias(T)
7979
end
8080

@@ -117,7 +117,7 @@ const c1f = -0.333332866430282592773438f0
117117
global @inline atan2k_fast_kernel(x::Float64) = @horner x c1d c2d c3d c4d c5d c6d c7d c8d c9d c10d c11d c12d c13d c14d c15d c16d c17d c18d c19d c20d
118118
global @inline atan2k_fast_kernel(x::Float32) = @horner x c1f c2f c3f c4f c5f c6f c7f c8f c9f
119119

120-
@inline function atan2k_fast(y::T, x::T) where {T<:IEEEFloat}
120+
@inline function atan2k_fast(y::T, x::T) where {T<:Union{Float32,Float64}}
121121
q = 0
122122
if x < 0
123123
x = -x
@@ -139,7 +139,7 @@ end
139139
global @inline atan2k_kernel(x::Double{Float64}) = @horner x.hi c1d c2d c3d c4d c5d c6d c7d c8d c9d c10d c11d c12d c13d c14d c15d c16d c17d c18d c19d c20d
140140
global @inline atan2k_kernel(x::Double{Float32}) = dadd(c1f, x.hi * (@horner x.hi c2f c3f c4f c5f c6f c7f c8f c9f))
141141

142-
@inline function atan2k(y::Double{T}, x::Double{T}) where {T<:IEEEFloat}
142+
@inline function atan2k(y::Double{T}, x::Double{T}) where {T<:Union{Float32,Float64}}
143143
q = 0
144144
if x < 0
145145
x = -x
@@ -193,7 +193,7 @@ global @inline expk_kernel(x::Float32) = @horner x c1f c2f c3f c4f c5f
193193
global under_expk(::Type{Float64}) = -1000.0
194194
global under_expk(::Type{Float32}) = -104f0
195195

196-
@inline function expk(d::Double{T}) where {T<:IEEEFloat}
196+
@inline function expk(d::Double{T}) where {T<:Union{Float32,Float64}}
197197
q = round(T(d) * T(MLN2E))
198198

199199
s = dadd(d, q * -L2U(T))
@@ -215,7 +215,7 @@ global under_expk(::Type{Float32}) = -104f0
215215
end
216216

217217

218-
@inline function expk2(d::Double{T}) where {T<:IEEEFloat}
218+
@inline function expk2(d::Double{T}) where {T<:Union{Float32,Float64}}
219219
q = round(T(d) * T(MLN2E))
220220

221221
s = dadd(d, -q * L2U(T))
@@ -251,7 +251,7 @@ const c1f = 0.666666686534881591796875f0
251251
global @inline logk2_kernel(x::Float64) = @horner x c1d c2d c3d c4d c5d c6d c7d c8d
252252
global @inline logk2_kernel(x::Float32) = @horner x c1f c2f c3f c4f
253253

254-
@inline function logk2(d::Double{T}) where {T<:IEEEFloat}
254+
@inline function logk2(d::Double{T}) where {T<:Union{Float32,Float64}}
255255
e = ilogbk(d.hi * T(1.0/0.75))
256256
m = scale(d, pow2i(T, -e))
257257

@@ -285,7 +285,7 @@ const c1fd = Double(0.66666662693023681640625f0, 3.69183861259614332084311f-9)
285285
global @inline logk_kernel(x::Double{Float64}) = dadd2(c1dd, dmul(x, @horner x.hi c2d c3d c4d c5d c6d c7d c8d c9d c10d))
286286
global @inline logk_kernel(x::Double{Float32}) = dadd2(c1fd, dmul(x, @horner x.hi c2f c3f c4f))
287287

288-
@inline function logk(d::T) where {T<:IEEEFloat}
288+
@inline function logk(d::T) where {T<:Union{Float32,Float64}}
289289
o = d < realmin(T)
290290
o && (d *= T(Int64(1) << 32) * T(Int64(1) << 32))
291291

src/trig.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ end
701701
702702
Compute the inverse tangent of `x`, where the output is in radians.
703703
"""
704-
function atan(x::T) where {T<:IEEEFloat}
704+
function atan(x::T) where {T<:Union{Float32,Float64}}
705705
u = T(atan2k(Double(abs(x)), Double(T(1))))
706706
isinf(x) && (u = T(PI_2))
707707
flipsign(u, x)
@@ -749,7 +749,7 @@ const c1f = -0.333331018686294555664062f0
749749
global @inline _atan_fast(x::Float64) = @horner x c1d c2d c3d c4d c5d c6d c7d c8d c9d c10d c11d c12d c13d c14d c15d c16d c17d c18d c19d
750750
global @inline _atan_fast(x::Float32) = @horner x c1f c2f c3f c4f c5f c6f c7f c8f
751751

752-
function atan_fast(x::T) where {T<:IEEEFloat}
752+
function atan_fast(x::T) where {T<:Union{Float32,Float64}}
753753
q = 0
754754
if signbit(x)
755755
x = -x
@@ -777,7 +777,7 @@ const under_atan2(::Type{Float32}) = 2.9387372783541830947f-39
777777
778778
Compute the inverse tangent of `x/y`, using the signs of both `x` and `y` to determine the quadrant of the return value.
779779
"""
780-
function atan2(x::T, y::T) where {T<:IEEEFloat}
780+
function atan2(x::T, y::T) where {T<:Union{Float32,Float64}}
781781
abs(y) < under_atan2(T) && (x *= T(Int64(1) << 53); y *= T(Int64(1) << 53))
782782
r = T(atan2k(Double(abs(x)), Double(y)))
783783

@@ -800,7 +800,7 @@ end
800800
801801
Compute the inverse tangent of `x/y`, using the signs of both `x` and `y` to determine the quadrant of the return value.
802802
"""
803-
function atan2_fast(x::T, y::T) where {T<:IEEEFloat}
803+
function atan2_fast(x::T, y::T) where {T<:Union{Float32,Float64}}
804804
r = atan2k_fast(abs(x), y)
805805
r = flipsign(r, y)
806806
if isinf(y) || y == 0
@@ -822,7 +822,7 @@ end
822822
823823
Compute the inverse sine of `x`, where the output is in radians.
824824
"""
825-
function asin(x::T) where {T<:IEEEFloat}
825+
function asin(x::T) where {T<:Union{Float32,Float64}}
826826
d = atan2k(Double(abs(x)), dsqrt(dmul(dadd(T(1), x), dsub(T(1), x))))
827827
u = T(d)
828828
abs(x) == 1 && (u = T(PI_2))
@@ -835,7 +835,7 @@ end
835835
836836
Compute the inverse sine of `x`, where the output is in radians.
837837
"""
838-
function asin_fast(x::T) where {T<:IEEEFloat}
838+
function asin_fast(x::T) where {T<:Union{Float32,Float64}}
839839
flipsign(atan2k_fast(abs(x), _sqrt((1 + x) * (1 - x))), x)
840840
end
841841

@@ -846,7 +846,7 @@ end
846846
847847
Compute the inverse cosine of `x`, where the output is in radians.
848848
"""
849-
function acos(x::T) where {T<:IEEEFloat}
849+
function acos(x::T) where {T<:Union{Float32,Float64}}
850850
d = atan2k(dsqrt(dmul(dadd(T(1), x), dsub(T(1), x))), Double(abs(x)))
851851
d = flipsign(d, x)
852852
abs(x) == 1 && (d = Double(T(0)))
@@ -860,6 +860,6 @@ end
860860
861861
Compute the inverse cosine of `x`, where the output is in radians.
862862
"""
863-
function acos_fast(x::T) where {T<:IEEEFloat}
863+
function acos_fast(x::T) where {T<:Union{Float32,Float64}}
864864
flipsign(atan2k_fast(_sqrt((1 + x) * (1 - x)), abs(x)), x) + (signbit(x) ? T(M_PI) : T(0))
865865
end

0 commit comments

Comments
 (0)