diff mbox

libgo patch committed: Work around bug in Solaris 9 ldexp

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

Commit Message

Ian Lance Taylor April 27, 2012, 4:33 p.m. UTC
The Solaris 9 ldexp function has a bug: ldexp(-1, -1075) returns
positive zero when it should return negative zero.  This patch works
around this bug in the Go math package.  This fixes part of PR 52358.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu and
i386-sun-solaris2.9.  Committed to mainline and 4.7 branch.

Ian
diff mbox

Patch

diff -r c1d1d764b7a6 libgo/go/math/ldexp.go
--- a/libgo/go/math/ldexp.go	Fri Apr 27 09:26:59 2012 -0700
+++ b/libgo/go/math/ldexp.go	Fri Apr 27 09:29:05 2012 -0700
@@ -16,7 +16,18 @@ 
 func libc_ldexp(float64, int) float64
 
 func Ldexp(frac float64, exp int) float64 {
-	return libc_ldexp(frac, exp)
+     	r := libc_ldexp(frac, exp)
+
+	// Work around a bug in the implementation of ldexp on Solaris
+	// 9.  If multiplying a negative number by 2 raised to a
+	// negative exponent underflows, we want to return negative
+	// zero, but the Solaris 9 implementation returns positive
+	// zero.  This workaround can be removed when and if we no
+	// longer care about Solaris 9.
+	if r == 0 && frac < 0 && exp < 0 {
+		r = Copysign(0, frac)
+	}
+	return r
 }
 
 func ldexp(frac float64, exp int) float64 {