Skip to content

fix: round negative fractions toward zero - #490

Open
SashaMIT wants to merge 1 commit into
Masterminds:masterfrom
SashaMIT:fix/round-negative-fraction
Open

SashaMIT wants to merge 1 commit into
Masterminds:masterfrom
SashaMIT:fix/round-negative-fraction

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Sep 30, 2026 •

Copy link
Copy Markdown

round(-1.25, 0) returned -2. math.Modf keeps the sign of the fractional part, so a negative fraction is never >= 0.5 and every negative value took math.Floor.

-1.25 is -1. -1.5 stays -2. -1.75 stays -2. The positive cases are unchanged. A custom threshold follows the same rule: -123.2329999 rounded to 2 digits with threshold 0.3 is -123.23, and -123.233 stays -123.24.

#488 changes the product to float64 so fused multiply-add does not move a positive fraction under the threshold. This patch leaves that line alone.

Red on Go 1.24.4: expected -1, actual -2. Green: TZ=UTC go test .

math.Modf keeps the sign of the fractional part, so every negative value took math.Floor. round(-1.25, 0) returned -2.

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