Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: constant arithmetic with typed complex numbers is too precise #33285
When computing constant arithmetic of typed floating-point numbers, we truncate the results based on the floating-point type. That is, if
This is currently handled in const.go:setconst:
However, there's no corresponding logic for truncating typed complex constants. E.g., see this sample program that demonstrates "catastrophic cancellation" for arithmetic on const floats, non-const floats, and non-const complexes, but (non-spec-compliantly) computes the precise result for the const complex arithmetic: https://play.golang.org/p/UpXhGv8pLjQ
gccgo correctly computes 0 for all results. go/types looks like it probably handles this correctly too, but cmd/gotype doesn't easily expose constant values, and I haven't tried writing a test case.
Tagging "help wanted" since this is probably an easy CL if someone wants to grab it. There's already trunccmplxlit, just need to call it.