From e1116104ff5dbeeb060aadfbd65c819418a0ab66 Mon Sep 17 00:00:00 2001 From: linker99 Date: Tue, 31 Oct 2023 04:46:20 +0800 Subject: [PATCH] Add warning on floating point eq and ne assertions The usefulness of the float/double/ldouble eq and ne macros is very limited. Comparing the results of a floating point computation should be done with some tolerance, instead of expecting an exact answer. There may be differences on different platforms, etc. To this end, some warnings are added to the eq and ne functions, instead directing users to use the _tol functions instead. --- ...-floating-point-eq-and-ne-assertions.patch | 100 ++++++++++++++++++ check.spec | 6 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 check-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch diff --git a/check-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch b/check-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch new file mode 100644 index 0000000..1c143ce --- /dev/null +++ b/check-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch @@ -0,0 +1,100 @@ +From bf671bfc8d86630e84892219196bf2dd5173306a Mon Sep 17 00:00:00 2001 +From: Branden Archer +Date: Sun, 22 Oct 2017 12:35:49 -0400 +Subject: [PATCH] Add warning on floating point eq and ne assertions + +The usefulness of the float/double/ldouble eq and ne macros is very limited. Comparing +the results of a floating point computation should be done with some tolerance, instead +of expecting an exact answer. There may be differences on different platforms, etc. + +To this end, some warnings are added to the eq and ne functions, instead directing users +to use the _tol functions instead. +--- + src/check.h.in | 36 ++++++++++++++++++++++++++++++------ + 1 file changed, 30 insertions(+), 6 deletions(-) + +diff --git a/src/check.h.in b/src/check.h.in +index 712caef..7966126 100644 +--- a/src/check.h.in ++++ b/src/check.h.in +@@ -770,7 +770,11 @@ do { \ + } while (0) + + /** +- * Check two single precision floating point numbers to determine if X == Y ++ * Check two single precision floating point numbers to determine if X == Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_float_eq_tol instead. + * + * If not X == Y, the test fails. + * +@@ -783,7 +787,11 @@ do { \ + */ + #define ck_assert_float_eq(X, Y) _ck_assert_floating(X, ==, Y, float, "") + /** +- * Check two single precision floating point numbers to determine if X != Y ++ * Check two single precision floating point numbers to determine if X != Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_float_ne_tol instead. + * + * If not X != Y, the test fails. + * +@@ -969,7 +977,11 @@ do { \ + #define ck_assert_float_nonnan(X) _ck_assert_floating_nonnan(X, float, "") + + /** +- * Check two double precision floating point numbers to determine if X == Y ++ * Check two double precision floating point numbers to determine if X == Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_double_eq_tol instead. + * + * If not X == Y, the test fails. + * +@@ -982,7 +994,11 @@ do { \ + */ + #define ck_assert_double_eq(X, Y) _ck_assert_floating(X, ==, Y, double, "") + /** +- * Check two double precision floating point numbers to determine if X != Y ++ * Check two double precision floating point numbers to determine if X != Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_double_ne_tol instead. + * + * If not X != Y, the test fails. + * +@@ -1168,7 +1184,11 @@ do { \ + #define ck_assert_double_nonnan(X) _ck_assert_floating_nonnan(X, double, "") + + /** +- * Check two double precision floating point numbers to determine if X == Y ++ * Check two double precision floating point numbers to determine if X == Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_ldouble_eq_tol instead. + * + * If not X == Y, the test fails. + * +@@ -1181,7 +1201,11 @@ do { \ + */ + #define ck_assert_ldouble_eq(X, Y) _ck_assert_floating(X, ==, Y, long double, "L") + /** +- * Check two double precision floating point numbers to determine if X != Y ++ * Check two double precision floating point numbers to determine if X != Y. ++ * ++ * Note that the usefulness of this assertion is very limited. If you ++ * want to compare two floating point numbers for equality, you probably ++ * want to use ck_assert_ldouble_ne_tol instead. + * + * If not X != Y, the test fails. + * +-- +2.27.0 + diff --git a/check.spec b/check.spec index 2ae7ed1..505108d 100644 --- a/check.spec +++ b/check.spec @@ -1,12 +1,13 @@ Name: check Version: 0.12.0 -Release: 4 +Release: 5 Summary: A unit testing framework for C Source0: https://github.com/libcheck/%{name}/archive/%{version}/%{name}-%{version}.tar.gz License: LGPLv2+ URL: http://libcheck.github.io/check/ Patch0: %{name}-0.11.0-info-in-builddir.patch Patch1: %{name}-0.11.0-fp.patch +Patch2: %{name}-0.12.0-Add-warning-on-floating-point-eq-and-ne-assertions.patch BuildRequires: gcc libtool patchutils pkgconfig BuildRequires: subunit-devel texinfo @@ -93,5 +94,8 @@ make check %{_mandir}/man1/checkmk.1* %changelog +* Thu Nov 9 2023 fandehui - 0.12.0-5 +- Add warning on floating point eq and ne assertions + * Mon Dec 9 2019 mengxian - 0.12.0-4 - Package init