]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add iszero.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 23 Sep 2016 21:54:21 +0000 (21:54 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Fri, 23 Sep 2016 21:54:21 +0000 (21:54 +0000)
TS 18661-1 adds an iszero classification macro to <math.h>.  This
patch implements it for glibc.  There are no new underlying functions
in libm because the implementation uses fpclassify when sNaN support
is required and a direct comparison otherwise; any optimizations for
this macro should be done through adding __builtin_iszero in GCC and
using it in the header for suitable GCC versions, not through adding
other optimized inline or out-of-line versions to glibc.

Tested for x86_64 and x86.

* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (iszero): New
macro.
* math/libm-test.inc (iszero_test_data): New array.
(iszero_test): New function.
(main): Call iszero_test.
* manual/arith.texi (Floating Point Classes): Document iszero.
* manual/libm-err-tab.pl: Update comment on interfaces without
ulps tabulated.

ChangeLog
NEWS
manual/arith.texi
manual/libm-err-tab.pl
math/libm-test.inc
math/math.h

index fa6d945ed12c6266758108aed0d481e11b9f6815..6cbe4303d72469d44aa35249590b8ab58b4e4558 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2016-09-23  Joseph Myers  <joseph@codesourcery.com>
+
+       * math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (iszero): New
+       macro.
+       * math/libm-test.inc (iszero_test_data): New array.
+       (iszero_test): New function.
+       (main): Call iszero_test.
+       * manual/arith.texi (Floating Point Classes): Document iszero.
+       * manual/libm-err-tab.pl: Update comment on interfaces without
+       ulps tabulated.
+
 2016-09-23  Zack Weinberg  <zackw@panix.com>
 
        * scripts/check-installed-headers.sh: New script.
diff --git a/NEWS b/NEWS
index 23ca5abdbeb1afc154228af19ad772ce21e14110..e29527413e93c13309e8ea20b37ad1bb72640698 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,7 +51,7 @@ Version 2.25
 
 * New <math.h> features are added from TS 18661-1:2014:
 
-  - Classification macros: issubnormal.
+  - Classification macros: issubnormal, iszero.
 
 * The <sys/quota.h> header now includes the <linux/quota.h> header.  Support
   for the Linux quota interface which predates kernel version 2.4.22 has
index bfa236a50ef73fbbc9165da3112dd35d32c5df1f..58f35781bb01c2b753ab311d01ce9e36e3d176ea 100644 (file)
@@ -414,6 +414,14 @@ This macro returns a nonzero value if @var{x} is subnormal.  It is
 from TS 18661-1:2014.
 @end deftypefn
 
+@comment math.h
+@comment ISO
+@deftypefn {Macro} int iszero (@emph{float-type} @var{x})
+@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
+This macro returns a nonzero value if @var{x} is zero.  It is from TS
+18661-1:2014.
+@end deftypefn
+
 Another set of floating-point classification functions was provided by
 BSD.  @Theglibc{} also supports these functions; however, we
 recommend that you use the ISO C99 macros in new code.  Those are standard
index adeadb8f55fec779c06e2afcf61ea1fa5e4b66b9..2386772b8599f4b078e5fa93cc25a04f2051872d 100755 (executable)
@@ -78,7 +78,7 @@ use vars qw (%results @all_floats %suffices @all_functions);
     "scalbn", "sin", "sincos", "sinh", "sqrt", "tan", "tanh", "tgamma",
     "trunc", "y0", "y1", "yn" );
 # fpclassify, isnormal, isfinite, isinf, isnan, issignaling,
-# issubnormal, signbit, isgreater, isgreaterequal, isless,
+# issubnormal, iszero, signbit, isgreater, isgreaterequal, isless,
 # islessequal, islessgreater, isunordered are not tabulated.
 
 if ($#ARGV == 0) {
index 385ec5c0535428ce9ec6e56df571e746997d9888..872bafd9c73ff223a174ec23055cb0f0edf5698c 100644 (file)
@@ -46,7 +46,7 @@
    cbrt, ceil, copysign, cos, cosh, drem, erf, erfc, exp, exp10, exp2, expm1,
    fabs, fdim, finite, floor, fma, fmax, fmin, fmod, fpclassify,
    frexp, gamma, hypot,
-   ilogb, isfinite, isinf, isnan, isnormal, issignaling, issubnormal,
+   ilogb, isfinite, isinf, isnan, isnormal, issignaling, issubnormal, iszero,
    isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered,
    j0, j1, jn,
    ldexp, lgamma, log, log10, log1p, log2, logb,
@@ -8671,6 +8671,31 @@ isunordered_test (void)
   ALL_RM_TEST (isunordered, 1, isunordered_test_data, RUN_TEST_LOOP_ff_i_tg, END);
 }
 
+static const struct test_f_i_data iszero_test_data[] =
+  {
+    TEST_f_b (iszero, 0, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, minus_zero, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, 10, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, min_subnorm_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, -min_subnorm_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, min_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, -min_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, max_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, -max_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, plus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+    TEST_f_b (iszero, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+  };
+
+static void
+iszero_test (void)
+{
+  ALL_RM_TEST (iszero, 1, iszero_test_data, RUN_TEST_LOOP_f_b_tg, END);
+}
+
 static const struct test_f_f_data j0_test_data[] =
   {
     /* j0 is the Bessel function of the first kind of order 0 */
@@ -12694,6 +12719,7 @@ main (int argc, char **argv)
   isnormal_test ();
   issignaling_test ();
   issubnormal_test ();
+  iszero_test ();
   signbit_test ();
 
   /* Trigonometric functions:  */
index 064cc56e1b566e0519d0d57e0a221b78ccc66cec..0a099596f18ad1a3977482201c58657e9affee58 100644 (file)
@@ -331,6 +331,13 @@ enum
 
 /* Return nonzero value if X is subnormal.  */
 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
+
+/* Return nonzero value if X is zero.  */
+# ifdef __SUPPORT_SNAN__
+#  define iszero(x) (fpclassify (x) == FP_ZERO)
+# else
+#  define iszero(x) ((x) == 0)
+# endif
 #endif /* Use IEC_60559_BFP_EXT.  */
 
 #ifdef __USE_MISC