From nobody@FreeBSD.org  Wed Jan 20 22:13:25 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B8BA01065692
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jan 2010 22:13:25 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A850F8FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jan 2010 22:13:25 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0KMDPpG030954
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jan 2010 22:13:25 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o0KMDPY5030953;
	Wed, 20 Jan 2010 22:13:25 GMT
	(envelope-from nobody)
Message-Id: <201001202213.o0KMDPY5030953@www.freebsd.org>
Date: Wed, 20 Jan 2010 22:13:25 GMT
From: Paul Guyot <paulguyot@ieee.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: strtod doesn't always round to the nearest
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         143037
>Category:       kern
>Synopsis:       [libc] strtod(3) doesn't always round to the nearest
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 20 22:20:06 UTC 2010
>Closed-Date:    Mon Dec 06 01:13:57 UTC 2010
>Last-Modified:  Mon Dec 06 01:13:57 UTC 2010
>Originator:     Paul Guyot
>Release:        7.1
>Organization:
>Environment:
FreeBSD papaya.local 7.1-RELEASE-p4 FreeBSD 7.1-RELEASE-p4 #0: Fri Apr 17 05:48:23 UTC 2009     root@papaya.local:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Calling strtod with "2.225073858507201e-308" yields 2^-1022 (0,16,0,0,0,0,0,0), while it should yield 2^-1022 - 2^-1074 (0,15,255,255,255,255,255,255), which is the nearest representable value.

gcc on the very same FreeBSD box rounds this to the proper value (see sample code below).
>How-To-Repeat:
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>

int main() {
if (fegetround() == FE_TONEAREST) {
printf("rounding to nearest\n");
} else {
printf("not rounding to nearest\n");
}
const char* fp_str = "2.225073858507201e-308";
printf("string  = %s\n", fp_str);
double fp_gcc = 2.225073858507201e-308;
printf("gcc     = %.20g\n", fp_gcc);
double parsed = strtod(fp_str, NULL);
printf("parsed  = %.20g\n", parsed);
double fp = 0.0;
char* fp_p = (char*) &fp;
fp_p[0] = 255;
fp_p[1] = 255;
fp_p[2] = 255;
fp_p[3] = 255;
fp_p[4] = 255;
fp_p[5] = 255;
fp_p[6] = 15;
fp_p[7] = 0;
printf("smaller = %.20g\n", fp);
if (fp == parsed) {
printf("actually rounded to nearest (and towards zero)\n");
}
fp_p[0] = 0;
fp_p[1] = 0;
fp_p[2] = 0;
fp_p[3] = 0;
fp_p[4] = 0;
fp_p[5] = 0;
fp_p[6] = 16;
fp_p[7] = 0;
printf("larger  = %.20g\n", fp);
if (fp == parsed) {
printf("actually rounded towards +infinity\n");
}

return 0;
}

>Fix:


>Release-Note:
>Audit-Trail:

From: Paul Guyot <paulguyot@ieee.org>
To: bug-followup@FreeBSD.org,
 paulguyot@ieee.org
Cc:  
Subject: Re: kern/143037: [libc] strtod(3) doesn't always round to the nearest
Date: Wed, 15 Sep 2010 12:25:27 +0200

 This bug was apparently fixed in 8.0 and 8.1, and therefore should be closed.
 

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/143037: [libc] strtod(3) doesn't always round to the nearest
Date: Wed, 15 Sep 2010 15:50:15 +0000

 running HEAD (also amd64) i get this output. is this correct? just want to
 make sure there is no regression:
 
 rounding to nearest
 string = 2.225073858507201e-308
 gcc = 2.225073858507200889e-308
 parsed = 2.225073858507200889e-308
 smaller = 2.225073858507200889e-308
 actually rounded to nearest (and towards zero)
 larger = 2.2250738585072013831e-308
 
 also could you point me to where there problem has been fixed? was it fixed by
 the gdtoa 20081205 vendor import?
 
 here's a changelog: http://www.netlib.org/fp/changes
 
 or somewhere else?
 
 cheers.
 alex
 
 -- 
 a13x
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Mon Dec 6 01:12:46 UTC 2010 
State-Changed-Why:  
Fixed several years ago in 8.x. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143037 
>Unformatted:
