Skip to content

fix(runtime): match BEAM exponent text in float_to_binary - #105

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/4a70df34
Dec 2, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/4a70df34

Conversation

@mremond

@mremond mremond commented Dec 2, 2026

Copy link
Copy Markdown
Member

Why

Programs compiled by Nera turned a number into text with `float_to_binary` using a different exponent than standard Erlang (BEAM): `e15`, `e-3` and `e0` instead of `e+15`, `e-03` and `e+00`.

What changed

  • People running compiled programs will notice: `float_to_binary/1` now writes the exponent with its sign and at least two digits, exactly as standard Erlang does.
  • `float_to_binary/2` does the same when given no options or `{scientific, N}`.
  • A new test program checks the same text when compiled by Nera and when run on standard Erlang.

Before and after

Before: On the base version, 414 of 456 test calls returned an exponent unlike Erlang/OTP 29, such as `9.00719925474099200000e15`.

After: Now 435 of those 456 calls return exactly what Erlang/OTP 29 returns, such as `9.00719925474099200000e+15`; the other 21 are texts over 255 bytes that Erlang rejects and Nera still returns, as before.

Only the text a compiled program returns changes, so there is no screen to picture; terminal transcripts are the evidence.

Checked

  • The new test on a build of the base version's code: Fails at its first comparison: `e15` where `e+15` is expected
  • The new test, ten runs compiled by Nera and ten on Erlang/OTP 29, no retries: 20 of 20 passed
  • The project's full local checks: release builds, lint, all Rust tests, all end-to-end tests: All passed: 2,303 Rust tests with 1 ignored, 556 end-to-end tests with 2 skipped for absent external modules
  • Independent review of the final change against Erlang/OTP 29: No code problem found; 487,298 scientific conversions identical to Erlang/OTP
How it was checked

cargo build --release --locked -p nera-runtime, then -p nera, then the whole workspace

cargo clippy --workspace --all-targets --locked -- -D warnings

cargo test --workspace --locked --no-fail-fast

python3 scripts/test-allocator-config.py

./target/release/nera test -j 1 --timeout 30

python3 scripts/test-stacktrace-order.py

./target/release/nera test float_to_binary_text -j 1 --timeout 30, ten times

erlc tests/float_to_binary_text.erl, then erl -noshell -eval 'float_to_binary_text:test(), halt().', ten times

A test program calling float_to_binary on 19 values with 30 option lists, directly and through apply and fun calls, compiled natively on macOS arm64 and compared with Erlang/OTP 29 output

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low Three formatting calls in one pair of runtime conversion functions
Behavior low Corrects exponent text to Erlang/OTP's; code parsing the old text sees the new one
Undo low Reverting restores the old text; no data or settings move
Evidence low Compiled programs compared with Erlang/OTP 29 output, plus the full local checks
Sensitivity low No saved data, settings, sign-ins or release steps touched
Novelty low Reuses the formatter float_to_list already uses
Dependencies low No dependency change
Not done

`float_to_binary/2` still reads its options and rounds fixed decimals differently from standard Erlang, and returns scientific text longer than 255 bytes that Erlang rejects; this change leaves all of that as it was.

People running compiled programs will notice: `float_to_binary/1` now writes the exponent with its sign and at least two digits, exactly as standard Erlang does.

`float_to_binary/2` does the same when given no options or `{scientific, N}`.

A new test program checks the same text when compiled by Nera and when run on standard Erlang.
@mremond
mremond merged commit 8b2d306 into main Dec 2, 2026
21 checks passed
@mremond
mremond deleted the infinitary-batch/4a70df34 branch December 2, 2026 23:29
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