public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/3673] New: strtod exponent limit calculations broken
@ 2006-12-07  4:52 jsm28 at gcc dot gnu dot org
  2006-12-10  1:12 ` [Bug libc/3673] " drepper at redhat dot com
  2007-01-12 18:07 ` cvs-commit at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2006-12-07  4:52 UTC (permalink / raw)
  To: glibc-bugs

The strtod exponent limit calculations

          /* Get the exponent limit. */
          if (base == 16)
            exp_limit = (exp_negative ?
                         -MIN_EXP + MANT_DIG + 4 * int_no :
                         MAX_EXP - 4 * int_no + lead_zero);
          else
            exp_limit = (exp_negative ?
                         -MIN_10_EXP + MANT_DIG + int_no :
                         MAX_10_EXP - int_no + lead_zero);

have a few bugs:

* The max exponent calculation for decimals has an off-by-one error.

* The max exponent calculation for hex numbers has an off-by-three error.

* The hex calculation should use 4 * lead_zero not plain lead_zero.

(I haven't checked in detail whether the calculations for minimum exponent are
correct or not.)

This test illustrates the three problems above.  Each line of output should show
two equal numbers, but instead it says

1e+308 inf
8.98847e+307 inf
1.12356e+307 inf

because of wrong detection of overflow that wasn't there.

#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
  printf("%g %g\n", atof("1e308"), atof("100000000e300"));
  printf("%g %g\n", atof("0x1p1023"), atof("0x1000p1011"));
  printf("%g %g\n", atof("0x1p1020"), atof("0x0.00001p1040"));
  return 0;
}

-- 
           Summary: strtod exponent limit calculations broken
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: jsm28 at gcc dot gnu dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=3673

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libc/3673] strtod exponent limit calculations broken
  2006-12-07  4:52 [Bug libc/3673] New: strtod exponent limit calculations broken jsm28 at gcc dot gnu dot org
@ 2006-12-10  1:12 ` drepper at redhat dot com
  2007-01-12 18:07 ` cvs-commit at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: drepper at redhat dot com @ 2006-12-10  1:12 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2006-12-10 01:11 -------
Fixed in cvs.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=3673

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libc/3673] strtod exponent limit calculations broken
  2006-12-07  4:52 [Bug libc/3673] New: strtod exponent limit calculations broken jsm28 at gcc dot gnu dot org
  2006-12-10  1:12 ` [Bug libc/3673] " drepper at redhat dot com
@ 2007-01-12 18:07 ` cvs-commit at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2007-01-12 18:07 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2007-01-12 18:07 -------
Subject: Bug 3673

CVSROOT:	/cvs/glibc
Module name:	libc
Branch: 	glibc-2_5-branch
Changes by:	jakub@sourceware.org	2007-01-12 18:07:19

Modified files:
	.              : ChangeLog 
	stdlib         : Makefile strtod_l.c 
Added files:
	stdlib         : tst-atof1.c tst-atof2.c tst-strtod2.c 
	                 tst-strtod3.c 

Log message:
	* stdlib/Makefile (tst-strtod3-ENV): Define.
	
	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Parse thousand
	separators also if no non-zero digits found.
	* stdlib/Makefile (tests): Add tst-strtod3.
	
	[BZ #3664]
	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Fix test to recognize
	empty parsed strings.
	* stdlib/Makefile (tests): Add tst-strtod2.
	* stdlib/tst-strtod2.c: New file.
	
	[BZ #3673]
	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Fix exp_limit
	computation.
	* stdlib/Makefile (tests): Add tst-atof2.
	* stdlib/tst-atof2.c: New file.
	
	[BZ #3674]
	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Adjust exponent value
	correctly if removing trailing zero of hex-float.
	* stdlib/Makefile (tests): Add tst-atof1.
	* stdlib/tst-atof1.c: New file.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/ChangeLog.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.10362.2.28&r2=1.10362.2.29
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/tst-atof1.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.1.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/tst-atof2.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.1.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/tst-strtod2.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.3.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/tst-strtod3.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.1.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/Makefile.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.109.2.2&r2=1.109.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/strtod_l.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.14&r2=1.14.2.1



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=3673

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-01-12 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-07  4:52 [Bug libc/3673] New: strtod exponent limit calculations broken jsm28 at gcc dot gnu dot org
2006-12-10  1:12 ` [Bug libc/3673] " drepper at redhat dot com
2007-01-12 18:07 ` cvs-commit at gcc dot gnu dot org

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).