mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
fix exponential notation parsing (#857)
This commit is contained in:
commit
b024b6cddf
2 changed files with 25 additions and 2 deletions
|
|
@ -22,9 +22,26 @@ namespace {
|
|||
}
|
||||
|
||||
inline double power(double base, int64_t power) {
|
||||
if (power == 0) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
uint64_t exp;
|
||||
if (power < 0) {
|
||||
base = 1.0 / base;
|
||||
exp = static_cast<uint64_t>(-(power + 1)) + 1;
|
||||
} else {
|
||||
exp = static_cast<uint64_t>(power);
|
||||
}
|
||||
|
||||
double result = 1.0;
|
||||
for (int64_t i = 0; i < power; i++) {
|
||||
result *= base;
|
||||
|
||||
while (exp > 0) {
|
||||
if (exp & 1)
|
||||
result *= base;
|
||||
|
||||
base *= base;
|
||||
exp >>= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ TEST(JSON, EncodeDecode) {
|
|||
const int bytesSize = 20;
|
||||
const int year = 2019;
|
||||
const float score = 3.141592;
|
||||
const double distance = 1.23e45;
|
||||
const double epsilon = 1e-6;
|
||||
const bool visible = true;
|
||||
dv::objects::Bytes srcBytes(bytesSize);
|
||||
for (int i = 0; i < bytesSize; i ++) {
|
||||
|
|
@ -20,6 +22,8 @@ TEST(JSON, EncodeDecode) {
|
|||
object["name"] = name;
|
||||
object["year"] = year;
|
||||
object["score"] = score;
|
||||
object["distance"] = distance;
|
||||
object["epsilon"] = epsilon;
|
||||
object["visible"] = visible;
|
||||
object["data"] = srcBytes;
|
||||
|
||||
|
|
@ -30,6 +34,8 @@ TEST(JSON, EncodeDecode) {
|
|||
EXPECT_EQ(object["name"].asString(), name);
|
||||
EXPECT_EQ(object["year"].asInteger(), year);
|
||||
EXPECT_FLOAT_EQ(object["score"].asNumber(), score);
|
||||
EXPECT_DOUBLE_EQ(object["distance"].asNumber(), distance);
|
||||
EXPECT_DOUBLE_EQ(object["epsilon"].asNumber(), epsilon);
|
||||
EXPECT_EQ(object["visible"].asBoolean(), visible);
|
||||
auto b64string = object["data"].asString();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue