summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
Diffstat (limited to 'AK')
-rw-r--r--AK/JsonParser.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp
index bf27305938..46f931668b 100644
--- a/AK/JsonParser.cpp
+++ b/AK/JsonParser.cpp
@@ -8,6 +8,7 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
+#include <math.h>
namespace AK {
@@ -251,17 +252,14 @@ ErrorOr<JsonValue> JsonParser::parse_number()
}
StringView fraction_string(fraction_buffer.data(), fraction_buffer.size());
- auto fraction_string_uint = fraction_string.to_uint();
+ auto fraction_string_uint = fraction_string.to_uint<u64>();
if (!fraction_string_uint.has_value())
return Error::from_string_literal("JsonParser: Error while parsing number"sv);
- int fraction = fraction_string_uint.value();
- fraction *= (whole < 0) ? -1 : 1;
+ auto fraction = static_cast<double>(fraction_string_uint.value());
+ double sign = (whole < 0) ? -1 : 1;
- auto divider = 1;
- for (size_t i = 0; i < fraction_buffer.size(); ++i) {
- divider *= 10;
- }
- value = JsonValue((double)whole + ((double)fraction / divider));
+ auto divider = pow(10.0, static_cast<double>(fraction_buffer.size()));
+ value = JsonValue((double)whole + sign * (fraction / divider));
} else {
#endif
auto to_unsigned_result = number_string.to_uint<u64>();