Skip to content

web: goFixed is toFixed plus Go's tie rule - #3

Merged
midagedev merged 1 commit into
mainfrom
gofixed
Oct 14, 2026
Merged

midagedev merged 1 commit into
mainfrom
gofixed

Conversation

@midagedev

Copy link
Copy Markdown
Owner

goFixed in web/src/run.js (from #2) walked the float's bits in BigInt, about 40 lines, to match Go's strconv.FormatFloat. toFixed already rounds the exact binary value. It differs from Go only on an exact tie: away from zero against to even. A tie is a multiple of 2^-(digits+1), which is an exact test. So the function is now toFixed plus that one rule.

Evidence:

  • The old and new functions agree on 16,000,036 inputs (random values, quarter and fortieth ties, digits 0 and 1).
  • New web/test/gofixed.test.mjs pins the ties (0.25, 0.75, 2.5, 3.5, -0.25) and near-ties (0.15, 1.45). With plain toFixed the tie test fails.
  • ./scripts/check.sh OK, npm test 51/51.

The change was written by the bloomery AI assistant.

🤖 Generated with Claude Code

The page's Go-matching rounding was a 40-line walk over the float's bits.
toFixed already rounds the exact binary value; it differs from
strconv.FormatFloat only on an exact tie (away from zero against to
even), and a tie is a multiple of 2^-(digits+1), an exact test. Same
output on 16 million values, ties included; the new test pins the ties
and fails on plain toFixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@midagedev
midagedev merged commit 0fad7ce into main Oct 14, 2026
3 checks passed
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