File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change 999
999
@constprop :aggressive function ^ (x:: Float64 , y:: Float64 )
1000
1000
yint = unsafe_trunc (Int, y) # Note, this is actually safe since julia freezes the result
1001
1001
y == yint && return x^ yint
1002
+ # numbers greater than 2*inv(eps(T)) must be even, and the pow will overflow
1003
+ y >= 2 * inv (eps ()) && return x^ (typemax (Int64)- 1 )
1002
1004
x< 0 && y > - 4e18 && throw_exp_domainerror (x) # |y| is small enough that y isn't an integer
1003
1005
x == 1 && return 1.0
1004
1006
return pow_body (x, y)
@@ -1017,6 +1019,8 @@ end
1017
1019
@constprop :aggressive function ^ (x:: T , y:: T ) where T <: Union{Float16, Float32}
1018
1020
yint = unsafe_trunc (Int64, y) # Note, this is actually safe since julia freezes the result
1019
1021
y == yint && return x^ yint
1022
+ # numbers greater than 2*inv(eps(T)) must be even, and the pow will overflow
1023
+ y >= 2 * inv (eps (T)) && return x^ (typemax (Int64)- 1 )
1020
1024
x < 0 && y > - 4e18 && throw_exp_domainerror (x) # |y| is small enough that y isn't an integer
1021
1025
return pow_body (x, y)
1022
1026
end
Original file line number Diff line number Diff line change 155
155
@test x^ y === T (big (x)^ big (y))
156
156
@test x^ 1 === x
157
157
@test x^ yi === T (big (x)^ yi)
158
+ # test (-x)^y for y larger than typemax(Int)
159
+ @test T (- 1 )^ floatmax (T) === T (1 )
160
+ @test prevfloat (T (- 1 ))^ floatmax (T) === T (Inf )
161
+ @test nextfloat (T (- 1 ))^ floatmax (T) === T (0.0 )
158
162
# test for large negative exponent where error compensation matters
159
163
@test 0.9999999955206014 ^- 1.0e8 == 1.565084574870928
160
164
@test (- x)^ yi == x^ yi
You can’t perform that action at this time.
0 commit comments