cmd/compile: constant arithmetic with typed complex numbers is too precise #33285
Labels
FrozenDueToAge
help wanted
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
When computing constant arithmetic of typed floating-point numbers, we truncate the results based on the floating-point type. That is, if
x
andy
are float32 constants, thenx + y
will be truncated to fit into a float32 too, even if we could compute it more precisely:This is currently handled in const.go:setconst:
go/src/cmd/compile/internal/gc/const.go
Lines 1043 to 1046 in 9195948
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.
The text was updated successfully, but these errors were encountered: