public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libgo patch committed: Fix math.Ldexp for large powers
@ 2017-08-09 17:15 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2017-08-09 17:15 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 545 bytes --]

The libgo implementation of math.Ldexp declared the libc "ldexp" as
taking an 'int' exponent argument, which is not quite right for 64-bit
platforms (exp arg is always int32); this could yield incorrect
results for exponent values outside the range of Minint32/Maxint32.
This patch by Than McIntosh fixes this by upating the type for the
libc version of ldexp, and adding guards to screen for out-of-range
exponents.  This fixes https://golang.org/issue/21323.  Bootstrapped
and ran Go tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 966 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 250873)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-db685a1a9aa8b3b916dd6d1284895e01d73158e1
+5fd112e5c2968e94761c41519c451d789e23a92b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/math/ldexp.go
===================================================================
--- libgo/go/math/ldexp.go	(revision 250873)
+++ libgo/go/math/ldexp.go	(working copy)
@@ -13,10 +13,15 @@ package math
 //	Ldexp(NaN, exp) = NaN
 
 //extern ldexp
-func libc_ldexp(float64, int) float64
+func libc_ldexp(float64, int32) float64
 
 func Ldexp(frac float64, exp int) float64 {
-	r := libc_ldexp(frac, exp)
+	if exp > MaxInt32 {
+		exp = MaxInt32
+	} else if exp < MinInt32 {
+		exp = MinInt32
+	}
+	r := libc_ldexp(frac, int32(exp))
 	return r
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-09 17:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-09 17:15 libgo patch committed: Fix math.Ldexp for large powers Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).