JsonDeserializer: use float when the value has few digits

This commit is contained in:
Benoit Blanchon committed 2024-09-04 14:33:14 +02:00
1 parent fd6314e132
commit 1f7a3f3174
8 files changed
+163 -28

No files matched your search

+9 -4
View File
@@ -60,10 +60,15 @@ TEST_CASE("parseNumber<float>()") {
SECTION("VeryLong") {
checkFloat("0.00000000000000000000000000000001", 1e-32f);
checkFloat("100000000000000000000000000000000.0", 1e+32f);
checkFloat(
"100000000000000000000000000000000.00000000000000000000000000000",
1e+32f);
// The following don't work because they have many digits so parseNumber()
// treats them as double. But it's not an issue because JsonVariant will use
// a float to store them.
//
// checkFloat("100000000000000000000000000000000.0", 1e+32f);
// checkFloat(
// "100000000000000000000000000000000.00000000000000000000000000000",
// 1e+32f);
}
SECTION("NaN") {
+14 -2
View File
@@ -23,7 +23,7 @@ TEST_CASE("Test unsigned integer overflow") {
}
REQUIRE(first.type() == NumberType::UnsignedInteger);
REQUIRE(second.type() == NumberType::Float);
REQUIRE(second.type() == NumberType::Double);
}
TEST_CASE("Test signed integer overflow") {
@@ -41,7 +41,7 @@ TEST_CASE("Test signed integer overflow") {
}
REQUIRE(first.type() == NumberType::SignedInteger);
REQUIRE(second.type() == NumberType::Float);
REQUIRE(second.type() == NumberType::Double);
}
TEST_CASE("Invalid value") {
@@ -49,3 +49,15 @@ TEST_CASE("Invalid value") {
REQUIRE(result.type() == NumberType::Invalid);
}
TEST_CASE("float") {
auto result = parseNumber("3.402823e38");
REQUIRE(result.type() == NumberType::Float);
}
TEST_CASE("double") {
auto result = parseNumber("1.7976931348623157e308");
REQUIRE(result.type() == NumberType::Double);
}