Subject: lib/33262: isinf(strtold("INF", NULL)) returns false
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <tnozaki@netbsd.org>
List: netbsd-bugs
Date: 04/15/2006 15:20:00
>Number:         33262
>Category:       lib
>Synopsis:       isinf(strtold("INF", NULL)) returns false
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 15 15:20:00 +0000 2006
>Originator:     Takehiko NOZAKI
>Release:        NetBSD i386 3.99.17
>Organization:
>Environment:
NetBSD krafty.example.jp 3.99.17 NetBSD 3.99.17 (KRAFTY) #0: Sun Apr  9 04:03:45 JST 2006  tnozaki@krafty.example.jp:/usr/obj/sys/arch/i386/compile/KRAFTY i386

libc.so.12.139
>Description:
strtold("INF", NULL) should return HUGE_VALL, 
and isinf(strtold("INF", NULL)) should return true.
but NetBSD/i386's implementation(= gdtoa) is not.
(i don't know whether other architecture has same problems too)
 
it seems that HUGE_VALL definition are different
between
src/lib/libc/gdtoa/strtopx.c
(snip)
 	  case STRTOG_Infinite:
 		L[_0] = 0x7fff;
		L[_1] = L[_2] = L[_3] = L[_4] = 0;

and src/lib/libc/arch/i386/gen/infinityl.c.
(snip)
const union __long_double_u __infinityl =
	{ { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f, 0, 0 } };

>How-To-Repeat:
#include <assert.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
    assert(isinf(strtold("INF", NULL)));
}

----------------------------------------
assertion "isinf(strtold("INF", NULL))" failed file "strtold_test.c", line 5, function "main"
Abort (core dumped)
>Fix:
for only i386 architecture, apply this patch.
(i'm not sure this is correct way...)

Index: strtopx.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gdtoa/strtopx.c,v
retrieving revision 1.3
diff -u -B -w -r1.3 strtopx.c
--- strtopx.c	15 Mar 2006 17:35:18 -0000	1.3
+++ strtopx.c	14 Apr 2006 13:08:44 -0000
@@ -89,7 +89,8 @@
 
 	  case STRTOG_Infinite:
 		L[_0] = 0x7fff;
-		L[_1] = L[_2] = L[_3] = L[_4] = 0;
+		L[_1] = 0x8000;
+		L[_2] = L[_3] = L[_4] = 0;
 		break;
 
 	  case STRTOG_NaN: