2006/04/14(Fri)
○ strtold(3)
NetBSDのstrtold(3)ってちょっと動作が変。
#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)
うげげ。src/lib/libc/arch/i386/gen/infinityl.cを見る限り
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:
こうじゃないのかな...
それにコンパイラとgdtoaで丸め誤差が微妙に違う。
long double x, y;
x = 0.1;
y = strtold("0.1", NULL);
assert(x == y);
これは許容されうるものなのかね?
ちなみにRedhat9/glibc-2.3.3だとstrtold(3)が
完全に壊れてるwwwwので確認できず。