Repository navigation
fix(runtime): return max/2 and min/2 arguments unchanged - #8
Merged
Merged
Conversation
erlang:max/2 and min/2 now return one of their two arguments as it was, the first when the two compare equal, as on BEAM: max(2, 1.5) is 2 and max(1, 1.0) is 1. The mixed integer and float arms rounded the integer to a float and returned a new float, which also lost precision above 2^53. Every pair now goes through the term order, which compares integers and floats exactly. The max_min_numbers fixture runs natively and on BEAM.
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
Natively, erlang:max/2 and min/2 turned the integer of a mixed integer and float pair into a new float, so max(2, 1.5) returned 2.0 and max(1, 1.0) returned 1.0, where BEAM returns 2 and 1.
Rounding the integer first also made integers above 2^53 compare equal to smaller floats.
What changed
Before and after
Before: Natively, max(2, 1.5) was 2.0, min(1, 1.0) was 1.0, and max(9007199254740993, 9007199254740992.0) was a float.
After: Natively, max(2, 1.5) is 2, min(1, 1.0) is 1, and max(9007199254740993, 9007199254740992.0) is the integer, as on OTP 29.
The change is in runtime results that a program prints or matches, not in anything drawn on screen.
Checked
How it was checked
cargo build --release --locked -p nera-runtime, then -p nera, then the whole workspace: passed
cargo clippy --workspace --all-targets --locked -- -D warnings: passed
cargo test --workspace --locked --no-fail-fast: 2,139 passed, 0 failed, 1 ignored
python3 scripts/test-allocator-config.py: passed
nera test -j 1 --timeout 30: 467 passed, 0 failed, 2 skipped (external OneCached modules), max_min_numbers included
cargo test -p nera-runtime --lib bif::tests::bif_m ten times: 10 of 10, five tests each
nera test max_min_numbers ten times: 10 of 10; the same fixture under erl on OTP 29.1.2 ten times: 10 of 10
Checked on macOS arm64 only
Risk
Risk: low in every dimension.
Full risk assessment