Blame src/general/strtof.c
|
nsz |
462b4f |
#include <stdio.h>
|
|
nsz |
462b4f |
#include <stdlib.h>
|
|
nsz |
462b4f |
#include <math.h>
|
|
nsz |
462b4f |
#include "test.h"
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
#define length(x) (sizeof(x) / sizeof *(x))
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
static struct {
|
|
nsz |
462b4f |
char *s;
|
|
nsz |
462b4f |
float f;
|
|
nsz |
462b4f |
} t[] = {
|
|
nsz |
462b4f |
// 2^-149 * 0.5 - eps
|
|
nsz |
462b4f |
{".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0},
|
|
nsz |
462b4f |
// 2^-149 * 0.5 + eps
|
|
nsz |
462b4f |
{".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149},
|
|
nsz |
462b4f |
// 2^-149 * 0.5 - eps
|
|
nsz |
462b4f |
{".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149},
|
|
nsz |
462b4f |
// 2^-149 * 0.5 + eps
|
|
nsz |
462b4f |
{".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148},
|
|
nsz |
462b4f |
// 2^-126 + 2^-150 - eps
|
|
nsz |
462b4f |
{".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126},
|
|
nsz |
462b4f |
// 2^-126 + 2^-150 + eps
|
|
nsz |
462b4f |
{".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126},
|
|
nsz |
462b4f |
// 2^128 - 2^103 - eps
|
|
nsz |
462b4f |
{"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127},
|
|
nsz |
462b4f |
// 2^128 - 2^103
|
|
nsz |
462b4f |
{"340282356779733661637539395458142568448", INFINITY},
|
|
nsz |
462b4f |
};
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
int main(void)
|
|
nsz |
462b4f |
{
|
|
nsz |
462b4f |
int i;
|
|
nsz |
462b4f |
float x;
|
|
nsz |
462b4f |
char *p;
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
for (i = 0; i < length(t); i++) {
|
|
nsz |
462b4f |
x = strtof(t[i].s, &p);
|
|
nsz |
462b4f |
if (x != t[i].f)
|
|
nsz |
462b4f |
error("strtof(\"%s\") want %a got %a\n", t[i].s, t[i].f, x);
|
|
nsz |
462b4f |
}
|
|
nsz |
462b4f |
return test_status;
|
|
nsz |
462b4f |
}
|