This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] PowerPC: Fix for strtold overflow handling (bz14551)
On 09/11/2012 02:02 PM, Joseph S. Myers wrote:
> On Tue, 11 Sep 2012, Adhemerval Zanella wrote:
>
>> I messed up the threads in my last email and the message ended up being
>> too confusing. This patch is intended to fix the bz14551
>> http://sourceware.org/bugzilla/show_bug.cgi?id=14551 and it fixes
>> the errors that 'tst-strtod-overflow' triggers with IBM long double.
> Sorry, you still haven't explained how a long double change could possibly
> be relevant to tst-strtod-overflow, which doesn't use strtold at all.
My mistake here, I meant the 'tst-strtod-round' testcase, not the 'tst-strtod-overflow'.
>
>> - if (exponent2 > 0)
>> + if (exponent2 > 0 && u.ieee.exponent < 0x7FF)
>> u.ieee.exponent2 = exponent2;
>> else
>> lo >>= 1 - exponent2;
> I don't think this can be correct; this may avoid setting the exponent of
> the low part, but it could still have an incorrect nonzero mantissa in
> these overflow cases.
>
> You also need to add a testcase to the testsuite covering the various
> overflow possibilities, and the overflow case should set errno to ERANGE
> (and that should be tested).
>
I focused on the test available on 'tst-strtod-overflow' and 'master' is not failing,
but printing this errors:
strtold (179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.999) returned 0x1.fffffffffffff8p+1023 not inf
ignoring this inexact long double result
strtold (179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792) returned 0x1.fffffffffffff8p+1023 not inf
ignoring this inexact long double result
strtold (179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792.001) returned 0x1.fffffffffffff8p+1023 not inf
ignoring this inexact long double result
strtold (-179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.999) returned -0x1.fffffffffffff8p+1023 not -inf
ignoring this inexact long double result
strtold (-179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792) returned -0x1.fffffffffffff8p+1023 not -inf
ignoring this inexact long double result
strtold (-179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792.001) returned -0x1.fffffffffffff8p+1023 not -inf
ignoring this inexact long double result
The patch fixes it, making strtold correct returning infinity number for these cases.
I adjusted the testcase to check on error for IBM long double as well.
2012-09-12 Adhemerval Zanella <azanella@linux.vnet.ibm.com>
[BZ #14551]
sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c: (__mpn_construct_long_double):
Fix the overflow long double generation.
stdlib/tst-strtod-round.c: (struct test): Report error in infinity
transformation for IBM long double.
diff --git a/stdlib/tst-strtod-round.c b/stdlib/tst-strtod-round.c
index c6ad126..bdd4ed8 100644
--- a/stdlib/tst-strtod-round.c
+++ b/stdlib/tst-strtod-round.c
@@ -61,7 +61,7 @@ struct test {
ld64md, ld64mn, ld64mz, ld64mu, \
ld106exact, ld106d, ld106n, ld106z, ld106u, \
ld113d, ld113n, ld113z, ld113u) \
- { s, fn, dn, ld106exact, ld106n }
+ { s, fn, dn, true, ld106n }
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
# define TEST(s, fd, fn, fz, fu, dd, dn, dz, du, ld53d, ld53n, ld53z, ld53u, \
ld64id, ld64in, ld64iz, ld64iu, \
diff --git a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
index b49ad96..53528d1 100644
--- a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
@@ -134,7 +134,7 @@ __mpn_construct_long_double (mp_srcptr frac_ptr, int expt, int sign)
lo = lo << lzcount;
exponent2 = exponent2 - lzcount;
}
- if (exponent2 > 0)
+ if (exponent2 > 0 && u.ieee.exponent < 0x7FF)
u.ieee.exponent2 = exponent2;
else
lo >>= 1 - exponent2;
--
Adhemerval Zanella Netto
Software Engineer
Linux Technology Center Brazil
Toolchain / GLIBC on Power Architecture
azanella@linux.vnet.ibm.com / azanella@br.ibm.com
+55 61 8642-9890