1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "test.h"
5
6 #define length(x) (sizeof(x) / sizeof *(x))
7
8 static struct {
9 char *s;
10 float f;
11 } t[] = {
12 // 2^-149 * 0.5 - eps
13 {".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0},
14 // // 2^-149 * 0.5 + eps
15 // {".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149},
16 // // 2^-149 * 0.5 - eps
17 // {".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149},
18 // // 2^-149 * 0.5 + eps
19 // {".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148},
20 // 2^-126 + 2^-150 - eps
21 {".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126},
22 // 2^-126 + 2^-150 + eps
23 {".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126},
24 // 2^128 - 2^103 - eps
25 {"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127},
26 // 2^128 - 2^103
27 {"340282356779733661637539395458142568448", INFINITY},
28 {"10.0", 10.0},
29 {"1.0e2", 100.0},
30 {"0x1.0p3", 8.0},
31 };
32
main(void)33 int main(void)
34 {
35 int i;
36 float x;
37 char *p;
38
39 for (i = 0; i < length(t); i++) {
40 x = strtof(t[i].s, &p);
41 if (x != t[i].f)
42 t_error("strtof(\"%s\") want %a got %a\n", t[i].s, t[i].f, x);
43 }
44 return t_status;
45 }
46