{{ message }}
Repository navigation
Conversation
Since 8c26b85 (ThrowTheSwitch#770), UnityPrintFloat() prints 0 for every value whose magnitude is below UNITY_FLOAT_PRECISION, or below UNITY_DOUBLE_PRECISION when doubles are enabled. Those macros are the relative tolerance of the equality asserts, not a print threshold, so a failing TEST_ASSERT_EQUAL_FLOAT(1e-6f, 3e-6f) in a default build reports "Expected 0 Was 0". Test for an exact zero with two ordered comparisons instead. They are false for NaN and keep -Wfloat-equal quiet, which was the reason for the epsilon in the first place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

🍍
Since 2.7.0,
UnityPrintFloat()prints0for every value whose magnitude is belowUNITY_FLOAT_PRECISION(1e-5 by default), or belowUNITY_DOUBLE_PRECISION(1e-12) whenUNITY_INCLUDE_DOUBLEis defined. In a default build,fails with
Expected 0 Was 0, where 2.6.1 printedExpected 1e-06 Was 3e-06.8c26b85 (#770) changed the zero check to
UNITY_ABS(number) < epsilonto avoid==on floating point values, and took the epsilon from the precision macros. Those macros are the tolerance of the equality asserts, not a print threshold. The check is now(number >= 0.0f) && (number <= 0.0f), which is true only for zero, false for NaN, and does not trigger-Wfloat-equalwith gcc or clang.testDoublePrintinggains values below the old threshold. The float-only printing tests already expect4.99e-07and5e-07, but CI does not build that configuration. Built that way,testFloatPrintingstill fails on its-0line, which has been stale since 60b23dc changed only the double test.