@@ -51,60 +51,19 @@ const EXP2FT = (Float32(0x1.6a09e667f3bcdp-1),
51
51
Float32 (0x1 .3 dea64c123422p+ 0 ),
52
52
Float32 (0x1 .4 bfdad5362a27p+ 0 ),
53
53
Float32 (0x1 .5 ab07dd485429p+ 0 ))
54
- @inline function _exp2 (x:: Float32 )
55
- TBLBITS = UInt32 (4 )
56
- TBLSIZE = UInt32 (1 << TBLBITS)
57
54
58
- redux = Float32 (0x1 .8 p23) / TBLSIZE
59
- P1 = Float32 (0x1 .62e430 p- 1 )
60
- P2 = Float32 (0x1 . ebfbe0p- 3 )
61
- P3 = Float32 (0x1 . c6b348p- 5 )
62
- P4 = Float32 (0x1 .3 b2c9cp- 7 )
63
-
64
- # Reduce x, computing z, i0, and k.
65
- t:: Float32 = x + redux
66
- i0 = reinterpret (UInt32, t)
67
- i0 += TBLSIZE ÷ UInt32 (2 )
68
- k:: UInt32 = unsafe_trunc (UInt32, (i0 >> TBLBITS) << 20 )
69
- i0 &= TBLSIZE - UInt32 (1 )
70
- t -= redux
71
- z = x - t
72
- twopk = Float32 (reinterpret (Float64, UInt64 (0x3ff00000 + k) << 32 ))
73
-
74
- # Compute r = exp2(y) = exp2ft[i0] * p(z).
75
- tv = EXP2FT[i0 + UInt32 (1 )]
76
- u = tv * z
77
- tv = tv + u * (P1 + z * P2) + u * (z * z) * (P3 + z * P4)
78
-
79
- # Scale by 2**(k>>20)
80
- return tv * twopk
81
- end
82
-
83
- if VERSION < v " 1.7.0"
84
- """
85
- fastpow(x::Real, y::Real) -> Float32
86
- """
87
- @inline function fastpow (x:: Real , y:: Real )
88
- if iszero (x)
89
- return 0.0f0
90
- elseif isinf (x) && isinf (y)
91
- return Float32 (Inf )
92
- else
93
- return _exp2 (convert (Float32, y) * fastlog2 (convert (Float32, x)))
94
- end
95
- end
96
- else
97
- """
98
- fastpow(x::Real, y::Real) -> Float32
99
- """
100
- @inline function fastpow (x:: Real , y:: Real )
101
- if iszero (x)
102
- return 0.0f0
103
- elseif isinf (x) && isinf (y)
104
- return Float32 (Inf )
105
- else
106
- return @fastmath exp2 (convert (Float32, y) * fastlog2 (convert (Float32, x)))
107
- end
55
+ """
56
+ fastpow(x::T, y::T) where {T} -> T
57
+ Trips through Float32 for performance.
58
+ """
59
+ @inline function fastpow (x:: T , y:: T ) where {T}
60
+ if iszero (x)
61
+ return zero (T)
62
+ elseif isinf (x) && isinf (y)
63
+ return convert (T,Inf )
64
+ else
65
+ return convert (T,@fastmath exp2 (convert (Float32, y) * fastlog2 (convert (Float32, x))))
108
66
end
109
67
end
68
+
110
69
@inline fastpow (x, y) = x^ y
0 commit comments