Add real_iszero to real.*
authorAldy Hernandez <aldyh@redhat.com>
Fri, 26 Aug 2022 14:57:09 +0000 (16:57 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 26 Aug 2022 18:45:30 +0000 (20:45 +0200)
We have real_isnegzero but no real_iszero.  We could memcmp with 0,
but that's just ugly.

gcc/ChangeLog:

* real.cc (real_iszero): New.
* real.h (real_iszero): New.

gcc/real.cc
gcc/real.h

index dcf41b7..96f05ec 100644 (file)
@@ -1272,6 +1272,22 @@ real_isneg (const REAL_VALUE_TYPE *r)
   return r->sign;
 }
 
+/* Determine whether a floating-point value X is plus or minus zero.  */
+
+bool
+real_iszero (const REAL_VALUE_TYPE *r)
+{
+  return r->cl == rvc_zero;
+}
+
+/* Determine whether a floating-point value X is zero with SIGN.  */
+
+bool
+real_iszero (const REAL_VALUE_TYPE *r, bool sign)
+{
+  return real_iszero (r) && r->sign == sign;
+}
+
 /* Determine whether a floating-point value X is minus zero.  */
 
 bool
index e01f9ed..ec78e8a 100644 (file)
@@ -295,6 +295,12 @@ extern bool real_isneg (const REAL_VALUE_TYPE *);
 /* Determine whether a floating-point value X is minus zero.  */
 extern bool real_isnegzero (const REAL_VALUE_TYPE *);
 
+/* Determine whether a floating-point value X is plus or minus zero.  */
+extern bool real_iszero (const REAL_VALUE_TYPE *);
+
+/* Determine whether a floating-point value X is zero with SIGN.  */
+extern bool real_iszero (const REAL_VALUE_TYPE *, bool sign);
+
 /* Test relationships between reals.  */
 extern bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
 extern bool real_equal (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);