Fix failed build with compile flag: -Werror=float-equal (#741) #770
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 formn != n
allows us to determine whether a numbern
is a NaN when there is no way to useisnan()
. 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 numericalepsilon
corresponds to the precision of the representation of floating point numbers, which is determined by the data type (float
ordouble
).The presence of the problem was verified as follows:
examples/example_1/makefile
I added the lineCFLAGS += -Werror=float-equal
;examples/example_1/
;-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.