Repository navigation
fix(runtime): match BEAM exponent text in float_to_binary - #105
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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
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
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.