File tree 3 files changed +8
-2
lines changed
3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,8 @@ function power_by_squaring(x_, p::Integer)
165
165
elseif p == 2
166
166
return x* x
167
167
elseif p < 0
168
+ x == 1 && return copy (x)
169
+ x == - 1 && return iseven (p) ? one (x) : copy (x)
168
170
throw (DomainError ())
169
171
end
170
172
t = trailing_zeros (p) + 1
@@ -185,7 +187,7 @@ function power_by_squaring(x_, p::Integer)
185
187
end
186
188
power_by_squaring (x:: Bool , p:: Unsigned ) = ((p== 0 ) | x)
187
189
function power_by_squaring (x:: Bool , p:: Integer )
188
- p < 0 && throw (DomainError ())
190
+ p < 0 && ! x && throw (DomainError ())
189
191
return (p== 0 ) | x
190
192
end
191
193
Original file line number Diff line number Diff line change 827
827
@test_throws DomainError 2 ^ - 2
828
828
@test_throws DomainError (- 2 )^ (2.2 )
829
829
@test_throws DomainError (- 2.0 )^ (2.2 )
830
+ @test_throws DomainError false ^ - 2
831
+ @test 1 ^ - 2 === (- 1 ) ^ - 2 === 1
832
+ @test (- 1 ) ^ - 3 === - 1
833
+ @test true ^ - 2 === true
830
834
831
835
# issue #13748
832
836
let A = [1 2 ; 3 4 ]; B = [5 6 ; 7 8 ]; C = [9 10 ; 11 12 ]
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ immutable TypeWithIntParam{T <: Integer} end
257
257
let undefvar
258
258
err_str = @except_strbt sqrt (- 1 ) DomainError
259
259
@test contains (err_str, " Try sqrt(complex(x))." )
260
- err_str = @except_strbt 1 ^ (- 1 ) DomainError
260
+ err_str = @except_strbt 2 ^ (- 1 ) DomainError
261
261
@test contains (err_str, " Cannot raise an integer x to a negative power -n" )
262
262
err_str = @except_strbt (- 1 )^ 0.25 DomainError
263
263
@test contains (err_str, " Exponentiation yielding a complex result requires a complex argument" )
You can’t perform that action at this time.
0 commit comments