diff mbox

Go patch committed: Fix negative float zero constant

Message ID mcrlilmyxzl.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor April 23, 2012, 8:49 p.m. UTC
This patch to the Go frontend corrects the handling of negative zero
when using untyped constants.  Go's untyped constants are ideal floating
point numbers, and don't have negative zero or infinity or NaN.  The Go
frontend was incorrectly representing the negative of zero as a negative
zero, since it just uses the MPFR library.  This was detectable via the
standard function math.Float64bits.  This patch corrects the problem.  I
added a test case to the master Go testsuite, which will be copied into
the gccgo testsuite in due course.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.7 branch.

Ian
diff mbox

Patch

diff -r afcf18f60884 go/expressions.cc
--- a/go/expressions.cc	Mon Apr 23 09:59:25 2012 -0700
+++ b/go/expressions.cc	Mon Apr 23 13:42:46 2012 -0700
@@ -13620,7 +13620,13 @@ 
   this->clear();
   this->classification_ = NC_FLOAT;
   this->type_ = type;
-  mpfr_init_set(this->u_.float_val, val, GMP_RNDN);
+  // Numeric constants do not have negative zero values, so remove
+  // them here.  They also don't have infinity or NaN values, but we
+  // should never see them here.
+  if (mpfr_zero_p(val))
+    mpfr_init_set_ui(this->u_.float_val, 0, GMP_RNDN);
+  else
+    mpfr_init_set(this->u_.float_val, val, GMP_RNDN);
 }
 
 // Set to a complex value.