From 073e4aabc5b1a6a9b4cefa5e8fe3f182b7778c61 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Fri, 30 Aug 2024 05:37:34 +0200 Subject: [PATCH] prevent unnecessary conversion --- base/intfuncs.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index b84c54fb8cb3b4..c82f7f5a9368ef 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -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, ".",