Skip to content

Commit

Permalink
prevent unnecessary conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko committed Aug 30, 2024
1 parent 3974869 commit 073e4aa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ function invmod(n::T) where {T<:BitInteger}
end

# ^ for any x supporting *
to_power_type(x::Number) = first(promote(x, one(x), x*x))
function to_power_type(x::Number)
T = promote_type(typeof(x), typeof(one(x)), typeof(x*x))
convert(T, x)
end
to_power_type(x) = x
@noinline throw_domerr_powbysq(::Any, p) = throw(DomainError(p, LazyString(
"Cannot raise an integer x to a negative power ", p, ".",
Expand Down

0 comments on commit 073e4aa

Please sign in to comment.