pw_assert: adds float near and float exact
- Renames PW_{D,}CHECK_FLOAT_* macros to
PW_{D,}CHECK_FLOAT_EXACT_* to make it really obvious that it
ignores floating point precision limits and ergo accumulated
error which may cause accidental Asserts if the developer
was not aware of this.
- Adds PW_{D,}CHECK_FLOAT_NEAR to provide an Assert that allows
the developer to take float precision limits into account.
- Updates some stale comments and TODOs.
Change-Id: Id39921775db6386bc48dc8a9fbc7afd9937addfb
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/14041
Commit-Queue: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_assert/assert_backend_compile_test_c.c b/pw_assert/assert_backend_compile_test_c.c
index fb81a94..cecc756 100644
--- a/pw_assert/assert_backend_compile_test_c.c
+++ b/pw_assert/assert_backend_compile_test_c.c
@@ -122,13 +122,14 @@
float x_float = 50.5;
float y_float = 66.5;
- PW_CHECK_FLOAT_LE(x_float, y_float);
- PW_CHECK_FLOAT_LE(x_float, y_float, "FLOAT: " FAIL_IF_DISPLAYED);
- PW_CHECK_FLOAT_LE(x_float, y_float, "FLOAT: " FAIL_IF_DISPLAYED_ARGS, z);
+ PW_CHECK_FLOAT_EXACT_LE(x_float, y_float);
+ PW_CHECK_FLOAT_EXACT_LE(x_float, y_float, "FLOAT: " FAIL_IF_DISPLAYED);
+ PW_CHECK_FLOAT_EXACT_LE(
+ x_float, y_float, "FLOAT: " FAIL_IF_DISPLAYED_ARGS, z);
- PW_CHECK_FLOAT_GE(x_float, y_float);
- PW_CHECK_FLOAT_GE(x_float, y_float, "FLOAT: " FAIL_IF_HIDDEN);
- PW_CHECK_FLOAT_GE(x_float, y_float, "FLOAT: " FAIL_IF_HIDDEN_ARGS, z);
+ PW_CHECK_FLOAT_EXACT_GE(x_float, y_float);
+ PW_CHECK_FLOAT_EXACT_GE(x_float, y_float, "FLOAT: " FAIL_IF_HIDDEN);
+ PW_CHECK_FLOAT_EXACT_GE(x_float, y_float, "FLOAT: " FAIL_IF_HIDDEN_ARGS, z);
}
// Don't exhaustively test the DCHECKs but have a sampling of them.
@@ -138,7 +139,7 @@
PW_DCHECK(5 == 10, "Message");
PW_DCHECK(5 == 10, "Message: %d", 5);
PW_DCHECK_INT_LE(5.4, 10.0);
- PW_DCHECK_FLOAT_EQ(5.4, 10.0, "Message");
+ PW_DCHECK_FLOAT_EXACT_EQ(5.4, 10.0, "Message");
}
{ // TEST(Check, ComparisonArgumentsWithCommas)