Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a test case for signbit.



details:   https://anonhg.NetBSD.org/src/rev/f9779223b01b
branches:  trunk
changeset: 456173:f9779223b01b
user:      maya <maya%NetBSD.org@localhost>
date:      Fri Apr 26 08:52:16 2019 +0000

description:
Add a test case for signbit.
(paranoia prior to a libm change)

diffstat:

 distrib/sets/lists/debug/mi |    3 +-
 distrib/sets/lists/tests/mi |    3 +-
 tests/lib/libm/Makefile     |    3 +-
 tests/lib/libm/t_bit.c      |  102 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 3 deletions(-)

diffs (157 lines):

diff -r 193a1ab2d009 -r f9779223b01b distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Fri Apr 26 08:38:25 2019 +0000
+++ b/distrib/sets/lists/debug/mi       Fri Apr 26 08:52:16 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.282 2019/04/24 11:43:20 kamil Exp $
+# $NetBSD: mi,v 1.283 2019/04/26 08:52:16 maya Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -2202,6 +2202,7 @@
 ./usr/libdata/debug/usr/tests/lib/libm/t_acos.debug                    tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_asin.debug                    tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_atan.debug                    tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libm/t_bit.debug                     tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_cabsl.debug                   tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_casinh.debug                  tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_cbrt.debug                    tests-lib-debug         debug,atf,compattestfile
diff -r 193a1ab2d009 -r f9779223b01b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Apr 26 08:38:25 2019 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Apr 26 08:52:16 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.811 2019/04/24 11:43:20 kamil Exp $
+# $NetBSD: mi,v 1.812 2019/04/26 08:52:16 maya Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3036,6 +3036,7 @@
 ./usr/tests/lib/libm/t_acos                    tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_asin                    tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_atan                    tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libm/t_bit                     tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_cabsl                   tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_casinh                  tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_cbrt                    tests-lib-tests         compattestfile,atf
diff -r 193a1ab2d009 -r f9779223b01b tests/lib/libm/Makefile
--- a/tests/lib/libm/Makefile   Fri Apr 26 08:38:25 2019 +0000
+++ b/tests/lib/libm/Makefile   Fri Apr 26 08:52:16 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.45 2018/11/07 03:56:18 riastradh Exp $
+# $NetBSD: Makefile,v 1.46 2019/04/26 08:52:16 maya Exp $
 
 .include <bsd.own.mk>
 
@@ -18,6 +18,7 @@
 TESTS_C+=      t_acos
 TESTS_C+=      t_asin
 TESTS_C+=      t_atan
+TESTS_C+=      t_bit
 TESTS_C+=      t_casinh
 TESTS_C+=      t_cbrt
 TESTS_C+=      t_ceil
diff -r 193a1ab2d009 -r f9779223b01b tests/lib/libm/t_bit.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libm/t_bit.c    Fri Apr 26 08:52:16 2019 +0000
@@ -0,0 +1,102 @@
+/* $NetBSD: t_bit.c,v 1.1 2019/04/26 08:52:16 maya Exp $ */
+
+/*
+ * Written by Maya Rashish <maya%NetBSD.org@localhost>
+ * Public domain.
+ *
+ * Testing signbit{,f,l} function correctly
+ */
+
+#include <atf-c.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+static const struct {
+       double input;
+       bool is_negative;
+} values[] = {
+       { -1,           true},
+       { -123,         true},
+       { -123E6,       true},
+#ifdef INFINITY
+       { -INFINITY,    true},
+       { INFINITY,     false},
+#endif
+       { 123E6,        false},
+       { 0,            false},
+       { -FLT_MIN,     true},
+       { FLT_MIN,      false},
+       /* 
+        * Cannot be accurately represented as float,
+        * but sign should be preserved
+        */
+       { DBL_MAX,      false},
+       { -DBL_MAX,     true},
+};
+
+#ifdef __HAVE_LONG_DOUBLE
+static const struct {
+       long double input;
+       bool is_negative;
+} ldbl_values[] = {
+       { -LDBL_MIN,    true},
+       { LDBL_MIN,     false},
+       { LDBL_MAX,     false},
+       { -LDBL_MAX,    true},
+};
+#endif
+
+ATF_TC(signbit);
+ATF_TC_HEAD(signbit, tc)
+{
+       atf_tc_set_md_var(tc, "descr","Check that signbit functions correctly");
+}
+
+ATF_TC_BODY(signbit, tc)
+{
+       double iterator_d;
+       float iterator_f;
+
+       for (unsigned int i = 0; i < __arraycount(values); i++) {
+               iterator_d = values[i].input;
+               iterator_f = (float) values[i].input;
+               if (signbit(iterator_f) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitf is wrong"
+                                       " about the sign of %f", __func__,
+                                       __LINE__, i, iterator_f);
+               if (signbit(iterator_d) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbit is wrong"
+                                       "about the sign of %f", __func__,
+                                       __LINE__,i, iterator_d);
+
+#ifdef __HAVE_LONG_DOUBLE
+               long double iterator_l = values[i].input;
+               if (signbit(iterator_l) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitl is wrong"
+                                       " about the sign of %Lf", __func__,
+                                       __LINE__, i, iterator_l);
+#endif
+       }
+
+#ifdef __HAVE_LONG_DOUBLE
+       for (unsigned int i = 0; i < __arraycount(ldbl_values); i++) {
+               if (signbit(ldbl_values[i].input) != ldbl_values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitl is"
+                                       "wrong about the sign of %Lf",
+                                       __func__, __LINE__, i,
+                                       ldbl_values[i].input);
+       }
+#endif
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, signbit);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index