This is the mail archive of the
mailing list for the GCC project.
Go patch committed: Fix negative float zero constant
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Mon, 23 Apr 2012 13:49:50 -0700
- Subject: Go patch committed: Fix negative float zero constant
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.
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->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);
+ mpfr_init_set(this->u_.float_val, val, GMP_RNDN);
// Set to a complex value.