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 many gcc warnings mostly shown by -Werror=float-equal #520

Closed
wants to merge 1 commit into from

Conversation

Jaaaky
Copy link

@Jaaaky Jaaaky commented Jul 2, 2023

Implement nlopt_isequal() and nlopt_iszero() functions for help
Partially fixes #519

@Jaaaky Jaaaky force-pushed the pr-fix-Werror=float-equal branch 2 times, most recently from 4d61c88 to aaaeb95 Compare July 2, 2023 07:59
@Jaaaky Jaaaky force-pushed the pr-fix-Werror=float-equal branch from aaaeb95 to d0e37cd Compare July 2, 2023 09:06
@stevengj
Copy link
Owner

stevengj commented Jul 2, 2023

This is wrong.

The idea that it is never meaningful to compare floating-point numbers for exact equality is a myth. And replacing x == y with |x - y| < ε is even worse, because it is confusing floating-point arithmetic with fixed-point arithmetic (it is assuming your numbers have a scale of unity).

If there is an individual place in the code where it can be argued that the exact equality check is an error, then we can discuss what would be a more appropriate check on a case-by-case basis. But a blanket search-and-replace like this will introduce more bugs than it fixes.

@stevengj stevengj closed this Jul 2, 2023
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.

Enabling some compiler warnings produce many that could be fixed
2 participants