gason doesn't handle JS Number.MIN_VALUE or MAX_VALUE #19
Open
Description
In JavaScript (NodeJS) Number.MIN_VALUE is 5e-324 and MAX_VALUE 1.7976931348623157e+308.
These numbers are parsed by gason as 0 and infinity respectively. C++ will handle these as literals quite happily so string2double
must be causing an underflow and overflow.
I replicated this case with simple mods to test-suite.cpp on master:
void parse(const char *csource, bool ok) {
char *source = strdup(csource);
char *endptr;
JsonValue value;
JsonAllocator allocator;
int result = jsonParse(source, &endptr, &value, allocator);
printf("result is %d, value is: %g\n", result, value.fval);
++parsed;
free(source);
}
int main() {
pass(u8R"json(5e-324)json");
pass(u8R"json(1.7976931348623157e+308)json");
return 0;
}
The output is:
result is: 0, value is: 0
result is: 0, value is: inf
Working case example:
int main()
{
double min = 5e-324;
double max = 1.7976931348623157e+308;
printf("Min: %g, Max: %g\n", min, max);
}
This program prints 'Min: 4.94066e-324, Max: 1.79769e+308'.
I see this problem on an Intel i7 under Debian 8. I guess on some other CPU architectures this test may not fail in this manner.
Metadata
Assignees
Labels
No labels