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.
This commit is contained in:
parent
a7e56e6b85
commit
e1116104ff
@ -0,0 +1,100 @@
|
||||
From bf671bfc8d86630e84892219196bf2dd5173306a Mon Sep 17 00:00:00 2001
|
||||
From: Branden Archer <b.m.archer4@gmail.com>
|
||||
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
|
||||
|
||||
@ -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 <fandehui@xfusion.com> - 0.12.0-5
|
||||
- Add warning on floating point eq and ne assertions
|
||||
|
||||
* Mon Dec 9 2019 mengxian <mengxian@huawei.com> - 0.12.0-4
|
||||
- Package init
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user