ciabatta/test/test.c

27 lines
693 B
C
Raw Normal View History

2022-06-05 22:02:54 +00:00
#include <stdio.h>
#include <errno.h>
2022-06-05 22:02:54 +00:00
#include <stdlib.h>
2022-06-05 22:02:54 +00:00
int main(void)
{
double v0 = strtod("0X1.BC70A3D70A3D7P+6", NULL);
// parsing with error handling
const char *p = "111.11 -2.22 Nan nan(2) inF 0X1.BC70A3D70A3D7P+6 1.18973e+4932zzz";
char *end;
for (double f = strtod(p, &end); p != end; f = strtod(p, &end))
{
2022-06-05 22:02:54 +00:00
// printf("'%.*s' -> ", (int)(end-p), p);
p = end;
2022-06-05 22:02:54 +00:00
if (errno == ERANGE){
// printf("range error, got ");
errno = 0;
}
// printf("%f\n", f);
2022-06-02 13:08:59 +00:00
}
// parsing without error handling
2022-06-05 22:02:54 +00:00
double v1 = strtod(" -0.0000000123junk", NULL);
double v2 = strtod("junk", NULL);
}