Skip to content

Keep large integers exact in FormatInteger - #167

Open
x0Lazarus wants to merge 1 commit into
dustin:masterfrom
x0Lazarus:fix/preserve-integer-format-digits
Open

x0Lazarus wants to merge 1 commit into
dustin:masterfrom
x0Lazarus:fix/preserve-integer-format-digits

Conversation

@x0Lazarus

Copy link
Copy Markdown

On 64-bit platforms, FormatInteger("#.", 9007199254740993) returns 9007199254740992. Converting an integer to float64 loses digits for large values, and the float rounding step can also change an exact integer when no decimal places are requested.

This change formats the integer's decimal digits directly and shares the existing format parsing with FormatFloat. Grouping, signs and decimal zero padding stay the same, including the default two decimal places. Negative values are handled without negating the integer, so the minimum int remains valid. The float rounding and special-value handling are unchanged.

The regression tests cover 32-bit and 64-bit boundaries, large positive and negative values, explicit signs, Unicode separators, zero padding and invalid formats. Full tests, build and go vet ./... pass on Windows with Go 1.21.13 and 1.27.1. The 32-bit Windows suite also passes, skipping the seven values that require a 64-bit int. A separate comparison of 154 float-formatting cases on each Go version matches the unchanged code. Linux CI and race tests were not run locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant