{
const char *cp = ds_cstr(&p->buffer);
unsigned long long int significand = 0;
+ struct json_token token;
int sig_digits = 0;
bool imprecise = false;
bool negative = false;
&& significand <= (negative
? (unsigned long long int) LLONG_MAX + 1
: LLONG_MAX)) {
- struct json_token token;
token.type = T_INTEGER;
token.u.integer = negative ? -significand : significand;
json_parser_input(p, &token);
}
}
- if (pow10 + sig_digits <= DBL_MAX_10_EXP) {
- struct json_token token;
- token.type = T_REAL;
- token.u.real = significand * pow(10.0, pow10);
- if (token.u.real <= DBL_MAX) {
- if (negative && token.u.real) {
- token.u.real = -token.u.real;
- }
- json_parser_input(p, &token);
- return;
- }
+ token.type = T_REAL;
+ if (!str_to_double(ds_cstr(&p->buffer), &token.u.real)) {
+ json_error(p, "number outside valid range");
+ return;
}
- json_error(p, "number outside valid range");
+ /* Suppress negative zero. */
+ if (token.u.real == 0) {
+ token.u.real = 0;
+ }
+ json_parser_input(p, &token);
}
static bool
[scientific notation],
[[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]],
[[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]])
+# It seems likely that the following test will fail on some system that
+# rounds slightly differently in arithmetic or in printf, but I'd like
+# to keep it this way until we run into such a system.
+JSON_CHECK_POSITIVE(
+ [+/- DBL_MAX],
+ [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
+ [[[1.79769313486232e+308,-1.79769313486232e+308]]])
+
JSON_CHECK_POSITIVE(
[negative reals],
[[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],