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 failed build with compile flag: -Werror=float-equal (#741) #770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

artem-sharipov
Copy link

This is the fix for issue #741.

Briefly, compilation with the -Werror=float-equal flag failed.

The cause of the errors was the direct comparison of a floating-point number to another number in three places in the source, two of which are listed in the issue #741. The third error location is the implementation of the number check for NaN - UNITY_IS_NAN(n). In fact, a check of the form n != n allows us to determine whether a number n is a NaN when there is no way to use isnan(). In this case, a direct comparison of a floating-point number is acceptable because the number is being compared to itself, but the compiler flag does not make an exception in this case, so the implementation of the NaN check has been changed.

Elsewhere in the code, the value epsilon was introduced to solve the problem. epsilon is the error by which one number can be equal to another number. This error occurs because of the finite precision of the computer system's representation of real numbers. For this reason, floating point numbers cannot be directly compared using the == and != operators. The numerical epsilon corresponds to the precision of the representation of floating point numbers, which is determined by the data type (float or double).

The presence of the problem was verified as follows:

  1. in the examples/example_1/makefile I added the line CFLAGS += -Werror=float-equal;
  2. ran make in the directory examples/example_1/;
  3. saw that the build failed with the errors described in the issue Some codes failed -Werror=float-equal compiler flag, please fix it. #741.

After making the changes to the code, I repeated step 2 and checked that there were no more build errors.

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.

1 participant