You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working with negative exponents has some very odd behaviors, to say the least. Running the internals of the ^ function gives different results than ^ itself, evaluation success changes based on whether a variable is replaced with its value, and @code_* forms are convinced that the result should always be of type Int64. Tested on v1.0.0 and v1.1.0-DEV.
julia>2^-50.03125
julia> Base.power_by_squaring(2, -5)
ERROR: DomainError with -5:
Cannot raise an integer x to a negative power -5.
Make x a float by adding a zero decimal (e.g., 2.0^-5 instead of 2^-5), or write 1/x^5, float(x)^-5, or (x//1)^-5
Stacktrace:
[1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
[2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
[3] top-level scope at none:0
julia>@edit2^-5# ^(x::T, p::T) where {T<:Integer} = power_by_squaring(x,p)
julia> x =-2;
julia> x ^ x
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.
Make x a float by adding a zero decimal (e.g., 2.0^-2 instead of 2^-2), or write 1/x^2, float(x)^-2, or (x//1)^-2
Stacktrace:
[1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
[2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
[3] ^(::Int64, ::Int64) at ./intfuncs.jl:220
[4] top-level scope at none:0
julia> x ^ (-2)
0.25
julia> (-2) ^ x
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.
Make x a float by adding a zero decimal (e.g., 2.0^-2 instead of 2^-2), or write 1/x^2, float(x)^-2, or (x//1)^-2
Stacktrace:
[1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
[2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
[3] ^(::Int64, ::Int64) at ./intfuncs.jl:220
[4] top-level scope at none:0
julia> (-2) ^ (-2)
0.25
julia>@code_warntype x ^ x
Body::Int642201 ─ %1= invoke Base.power_by_squaring(_2::Int64, _3::Int64)::Int64 │
└── return%1 │
The text was updated successfully, but these errors were encountered:
Working with negative exponents has some very odd behaviors, to say the least. Running the internals of the
^
function gives different results than^
itself, evaluation success changes based on whether a variable is replaced with its value, and@code_*
forms are convinced that the result should always be of typeInt64
. Tested on v1.0.0 and v1.1.0-DEV.The text was updated successfully, but these errors were encountered: