Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in abs_diff #736

Merged
merged 1 commit into from
Dec 22, 2024
Merged

Fix a bug in abs_diff #736

merged 1 commit into from
Dec 22, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Dec 22, 2024

These implementations of abs_diff were added in c2ff1b3 ("Completely overhaul fuzz testing"), but the signed implementation is wrong when |x| + |y| exceeds the integer's limits (e.g. (-128).abs_diff(1) should be 129 but currently these return 127.

Resolve this by just using std's implementation since that is stable now. This isn't used anywhere critical, we probably just weren't hitting the edge case.

These implementations of `abs_diff` were added in c2ff1b3
("Completely overhaul fuzz testing"), but the signed implementation is
wrong when |x| + |y| exceeds the integer's limits (e.g.
`(-128).abs_diff(1)` should be 128 but currently these return 127.

Resolve this by just using `std`'s implementation since that is stable
now. This isn't used anywhere critical, we probably just weren't hitting
the edge case.
@tgross35 tgross35 enabled auto-merge December 22, 2024 22:25
@tgross35 tgross35 merged commit 3e0fe12 into rust-lang:master Dec 22, 2024
26 checks passed
@tgross35 tgross35 deleted the fix-abs-diff branch December 22, 2024 22:26
tgross35 added a commit to tgross35/rust-libm that referenced this pull request Dec 22, 2024
These were taken from `compiler-builtins` but the implementation has a
bug near the integer limits. Fixed in `compiler-builtins` by using
`core`'s implementation at [1], this is the corresponding fix for
`libm`.

[1]: rust-lang/compiler-builtins#736
@RalfJung
Copy link
Member

(-128).abs_diff(1) should be 128

It should be 129, right?

@tgross35
Copy link
Contributor Author

Ah yeah that's a typo, how did you stumble across this and find that :). Updated the description.

tgross35 added a commit to tgross35/rust that referenced this pull request Dec 27, 2024
tgross35 added a commit to tgross35/rust that referenced this pull request Dec 27, 2024
@RalfJung
Copy link
Member

RalfJung commented Dec 27, 2024 via email

Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2024
Rollup merge of rust-lang#134832 - tgross35:update-builtins, r=tgross35

Update `compiler-builtins` to 0.1.140

Nothing significant here, just syncing the following small changes:

- rust-lang/compiler-builtins#727
- rust-lang/compiler-builtins#730
- rust-lang/compiler-builtins#736
- rust-lang/compiler-builtins#737
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
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.

2 participants