stevengj / nlopt

library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization
Other
1.89k stars 588 forks source link

Fix many gcc warnings mostly shown by -Werror=float-equal #520

Closed Jaaaky closed 1 year ago

Jaaaky commented 1 year ago

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

stevengj commented 1 year ago

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.