diff mbox

Fix comparison of decimal float zeroes (PR80692)

Message ID 5f6c38def032322cffa98349b553855247b49041.1495042128.git.segher@kernel.crashing.org
State New
Headers show

Commit Message

Segher Boessenkool May 17, 2017, 6:36 p.m. UTC
Decimal float negative zero should compare equal to positive zero.
Decimal float zeroes are encoded as value class "normal" (in real.c);
they need to be handled specially, but in this one case that does not
yet happen.  This fixes it.

Bootstrapped and tested on powerpc64-linux {-m32,-m64}; also tested
the testcase separately (it fails before the test, except at -O0; it
passes after it).

Is this okay for trunk?


Segher


2017-05-17  Segher Boessenkool  <segher@kernel.crashing.org>

	PR middle-end/80692
	* real.c (do_compare): Give decimal_do_compare preference over
	comparing just the signs.

gcc/testsuite/
	PR middle-end/80692
	* gcc.c-torture/execute/pr80692.c: New testcase.

---
 gcc/real.c                                    |  6 +++---
 gcc/testsuite/gcc.c-torture/execute/pr80692.c | 13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr80692.c

Comments

Ben Elliston May 17, 2017, 8:56 p.m. UTC | #1
On Wed, May 17, 2017 at 06:36:38PM +0000, Segher Boessenkool wrote:

> 2017-05-17  Segher Boessenkool  <segher@kernel.crashing.org>
> 
> 	PR middle-end/80692
> 	* real.c (do_compare): Give decimal_do_compare preference over
> 	comparing just the signs.
> 
> gcc/testsuite/
> 	PR middle-end/80692
> 	* gcc.c-torture/execute/pr80692.c: New testcase.

OK, thanks.

Cheers,
Ben
diff mbox

Patch

diff --git a/gcc/real.c b/gcc/real.c
index 97452a9..a5671b2 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -960,12 +960,12 @@  do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b,
       gcc_unreachable ();
     }
 
-  if (a->sign != b->sign)
-    return -a->sign - -b->sign;
-
   if (a->decimal || b->decimal)
     return decimal_do_compare (a, b, nan_result);
 
+  if (a->sign != b->sign)
+    return -a->sign - -b->sign;
+
   if (REAL_EXP (a) > REAL_EXP (b))
     ret = 1;
   else if (REAL_EXP (a) < REAL_EXP (b))
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80692.c b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
new file mode 100644
index 0000000..e653c71
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
@@ -0,0 +1,13 @@ 
+/* { dg-require-effective-target dfp } */
+
+int main () {
+	_Decimal64 d64 = -0.DD;
+
+	if (d64 != 0.DD)
+		__builtin_abort ();
+
+	if (d64 != -0.DD)
+		__builtin_abort ();
+
+	return 0;
+}