math/big: incorrect Float formatting for negative/auto prec #71245
Labels
BugReport
Issues describing a possible bug in the Go implementation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go version go1.23.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/DtKUPDsBMNg
What did you see happen?
What did you expect to see?
I expected to big.Float's string formatter to do what it says on the tin: "A negative precision selects the smallest number of decimal digits necessary to identify the value x uniquely using x.Prec() mantissa bits".
I also expected the formatter to correctly apply round-to-nearest-half-to-even rounding, which is what I believe
decimal
implementation (inmath/big
) is intended to perform.Seems like a pretty clear bug - I tested these values with python3 and node REPLs, and they all align with
strconv.FormatFloat
andencoding/json
.Not super relevant, but my original intent was to use the
big.Float.Append
method to canonicalize JSON numbers (which this issue prevents).The text was updated successfully, but these errors were encountered: