Nothing Special   »   [go: up one dir, main page]

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 guidance of [float_cmp] and [float_cmp_const] to not incorrectly recommend f__::EPSILON as the error margin. #13079

Merged
merged 3 commits into from
Jul 10, 2024

Conversation

sandersaares
Copy link
Contributor

Using f32::EPSILON or f64::EPSILON as the floating-point equality comparison error margin is incorrect, yet float_cmp has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a sample implementation for using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equality comparison for cases where absolute error margins cannot be identified.

changelog: [float_cmp] Fix guidance to not incorrectly recommend f__::EPSILON as the error margin.
changelog: [float_cmp_const] Fix guidance to not incorrectly recommend f__::EPSILON as the error margin.

Fixes #6816

Using `f32::EPSILON` or `f64::EPSILON` as the floating-point equality comparison error margin is incorrect, yet `float_cmp` has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a reference implementation of using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equaltiy comparison for when absolute error margin cannot be used.

changelog: Fix guidance of [`float_cmp`] and [`float_cmp_const`] to not incorrectly recommend `f64::EPSILON` as the error margin.

Fixes rust-lang#6816
@rustbot
Copy link
Collaborator
rustbot commented Jul 9, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @y21 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 9, 2024
Copy link
Member
@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice improvement, looks good to me. Just one question.


FWIW, there's an existing PR that also addresses the issue by removing the note about f__::EPSILON, but it also changes the lint's logic a fair bit in other ways (including removing the _const lint) so it seems good to land this "smaller" change on its own 👍

clippy_lints/src/operators/mod.rs Outdated Show resolved Hide resolved
@y21
Copy link
Member
y21 commented Jul 10, 2024

LGTM, thanks!

@bors r+

@bors
Copy link
Collaborator
bors commented Jul 10, 2024

📌 Commit e42a380 has been approved by y21

It is now in the queue for this repository.

@bors
Copy link
Collaborator
bors commented Jul 10, 2024

⌛ Testing commit e42a380 with merge ab7c910...

@bors
Copy link
Collaborator
bors commented Jul 10, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: y21
Pushing ab7c910 to master...

@bors bors merged commit ab7c910 into rust-lang:master Jul 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EPSILON is a bad error margin and should not be recommended [float_cmp]
5 participants