diff --git a/base/intfuncs.jl b/base/intfuncs.jl index ec57f7f80d809..0cc033f2c801f 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -295,8 +295,14 @@ function power_by_squaring(x::Bool, p::Integer) return (p==0) | x end -^(x::T, p::T) where {T<:Integer} = power_by_squaring(x,p) -^(x::Number, p::Integer) = power_by_squaring(x,p) +@inline function ^(x::T, p::Integer) where T <: BitInteger #check for overflow + ans = power_by_squaring(x,p) + low_bound = ((sizeof(x)<<3)-leading_zeros(x)-1)*p + trailing_ones(typemax(T)) < low_bound || ans < (one(T)<