Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: finite scaling of complex infinity gives complex NaN #38757
What version of Go are you using (
This is working as intended. The issue is the untyped constant 42 is converted to a complex number with zero imaginary part and the multiplication between Inf and 0.0 is NaN.
cmplx.Inf()*42 == complex(math.Inf(1), math.Inf(1)) * (42 + 0i) ... == (math.Inf(1)*42-math.Inf(1)*0) + (math.Inf(1)*0+math.Inf(1)*42) i ... == (math.Inf(1) - math.NaN()) + (math.NaN() + math.Inf()) i ... == math.Nan() +math.NaN() i
To scale by a real number rather than multiply by a complex number with zero imaginary part you need to write this as:
x := cmplx.Inf() x = complex(42 * real(x), 42 * imag(x))
See #38780 for further discussion.