Skip to content

Commit

Permalink
Optimize evaluating JSON number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Dec 27, 2023
1 parent 3ead88d commit 3a8c14c
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/util/json_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,18 @@ static double __evaluate_json_number(const char *integer,
}
}

num = mant;
if (exp != 0 && figures != 0)
{
if (exp > 309 - figures)
num = INFINITY;
else if (exp > 0)
num *= __power_of_10[exp];
else if (exp > -309)
num /= __power_of_10[-exp];
else if (exp > -324 - figures)
{
num /= __power_of_10[-exp - 308];
num /= __power_of_10[308];
}
else
num = 0.0;
}
if (exp == 0 || figures == 0)
num = mant;
else if (exp > 291)
num = INFINITY;
else if (exp > 0)
num = mant * __power_of_10[exp];
else if (exp > -309)
num = mant / __power_of_10[-exp];
else if (exp > -324 - figures)
num = mant / __power_of_10[-exp - 308] / __power_of_10[308];
else
num = 0.0;

return sign ? -num : num;
}
Expand Down

0 comments on commit 3a8c14c

Please sign in to comment.