From 2bd22ec1319f34f6f0482fcb3252f220a87f46be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= <765740+giordano@users.noreply.github.com> Date: Sat, 5 Oct 2024 01:20:23 +0100 Subject: [PATCH] Update base/math.jl Co-authored-by: Alex Arslan --- base/math.jl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/base/math.jl b/base/math.jl index 77919f0b1531f..16a8a547e8de1 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1276,13 +1276,11 @@ end return ifelse(isfinite(x) & isfinite(err), muladd(x, y, err), x*y) end -for (T, WT) in ((Float16, Float32), (Float32, Float64)) - @eval function ^(x::$T, n::Integer) - n == -2 && return (i=inv(x); i*i) - n == 3 && return x*x*x #keep compatibility with literal_pow - n < 0 && return $T(Base.power_by_squaring(inv($WT(x)),-n)) - $T(Base.power_by_squaring($WT(x),n)) - end +function ^(x::Union{Float16,Float32}, n::Integer) + n == -2 && return (i=inv(x); i*i) + n == 3 && return x*x*x #keep compatibility with literal_pow + n < 0 && return oftype(x, Base.power_by_squaring(inv(widen(x)),-n)) + oftype(x, Base.power_by_squaring(widen(x),n)) end ## rem2pi-related calculations ##