Skip to content

Commit 056a69d

Browse files
authored
Avoid promotion in muladd involving unitful Furlong (#56886)
1 parent 71bfbb3 commit 056a69d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/complex.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ end
342342
*(x::Real, z::Complex) = Complex(x * real(z), x * imag(z))
343343
*(z::Complex, x::Real) = Complex(x * real(z), x * imag(z))
344344

345-
muladd(x::Real, z::Complex, y::Number) = muladd(z, x, y)
345+
muladd(x::Real, z::Complex, y::Union{Real,Complex}) = muladd(z, x, y)
346346
muladd(z::Complex, x::Real, y::Real) = Complex(muladd(real(z),x,y), imag(z)*x)
347347
muladd(z::Complex, x::Real, w::Complex) =
348348
Complex(muladd(real(z),x,real(w)), muladd(imag(z),x,imag(w)))

test/testhelpers/Furlongs.jl

+6
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,11 @@ for op in (:rem, :mod)
100100
end
101101
Base.sqrt(x::Furlong) = _div(sqrt(x.val), x, Val(2))
102102
Base.muladd(x::Furlong, y::Furlong, z::Furlong) = x*y + z
103+
Base.muladd(x::Furlong, y::Number, z::Number) = x*y + z
104+
Base.muladd(x::Furlong, y::Furlong, z::Number) = x*y + z
105+
Base.muladd(x::Number, y::Furlong, z::Number) = x*y + z
106+
Base.muladd(x::Number, y::Number, z::Furlong) = x*y + z
107+
Base.muladd(x::Number, y::Furlong, z::Furlong) = x*y + z
108+
Base.muladd(x::Furlong, y::Number, z::Furlong) = x*y + z
103109

104110
end

0 commit comments

Comments
 (0)