@@ -46,6 +46,8 @@ function generate_overdubs(mod, Ctx)
46
46
@inline Cassette. overdub (:: $Ctx , :: typeof (- ), a:: T , b:: T ) where T<: Union{Float32, Float64} = sub_float_contract (a, b)
47
47
@inline Cassette. overdub (:: $Ctx , :: typeof (* ), a:: T , b:: T ) where T<: Union{Float32, Float64} = mul_float_contract (a, b)
48
48
49
+ @inline Cassette. overdub (:: $Ctx , :: typeof (Base. literal_pow), f:: F , x, p) where F = Base. literal_pow (f, x, p)
50
+
49
51
function Cassette. overdub (:: $Ctx , :: typeof (:), start:: T , step:: T , stop:: T ) where T<: Union{Float16,Float32,Float64}
50
52
lf = (stop- start)/ step
51
53
if lf < 0
@@ -61,15 +63,42 @@ function generate_overdubs(mod, Ctx)
61
63
Base. steprangelen_hp (T, start, step, 0 , len, 1 )
62
64
end
63
65
64
- @inline Cassette. overdub (:: $Ctx , :: typeof (Base. literal_pow), f:: F , x, p) where F = Base. literal_pow (f, x, p)
65
-
66
66
if VERSION >= v " 1.5"
67
67
@inline function Cassette. overdub (:: $Ctx , :: typeof (Base. Checked. throw_overflowerr_binaryop), op, x, y)
68
68
throw (OverflowError (" checked arithmetic: cannot compute" ))
69
69
end
70
+
70
71
@inline function Cassette. overdub (:: $Ctx , :: typeof (Base. Checked. throw_overflowerr_negation), x)
71
72
throw (OverflowError (" checked arithmetic: cannot compute -x" ))
72
73
end
74
+
75
+ @inline function Cassette. overdub (:: $Ctx , :: typeof (exponent), x:: Union{Float32, Float64} )
76
+ T = typeof (x)
77
+ xs = reinterpret (Unsigned, x) & ~ Base. sign_mask (T)
78
+ if xs >= Base. exponent_mask (T)
79
+ throw (DomainError (x, " Cannot be Nan of Inf." ))
80
+ end
81
+ k = Int (xs >> Base. significand_bits (T))
82
+ if k == 0 # x is subnormal
83
+ if xs == 0
84
+ throw (DomainError (x, " Cannot be subnormal converted to 0." ))
85
+ end
86
+ m = Base. leading_zeros (xs) - Base. exponent_bits (T)
87
+ k = 1 - m
88
+ end
89
+ return k - Base. exponent_bias (T)
90
+ end
91
+ end
92
+
93
+ if VERSION >= v " 1.6"
94
+ @inline function Cassette. overdub (:: $Ctx , :: typeof (Base. _unsafe_getindex),
95
+ :: IndexStyle , A:: AbstractArray , I:: Vararg{Union{Real, AbstractArray}, N} ) where N
96
+ shape = index_shape (I... )
97
+ dest = similar (A, shape)
98
+ map (unsafe_length, axes (dest)) == map (unsafe_length, shape) || throw (DimensionMismatch (" output array is the wrong size" ))
99
+ _unsafe_getindex! (dest, A, I... )
100
+ return dest
101
+ end
73
102
end
74
103
end
75
104
end
0 commit comments