Skip to content

Commit

Permalink
[YAML] Fix edge case in formatDouble serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Dec 2, 2021
1 parent 1b46a24 commit e34aec2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/base/AnyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ string formatDouble(double x, long int precision)
string s0;
if (useExp) {
s0 = fmt::format(fmt::format("{:.{}e}", x, precision));
last = s0.size() - 5; // last digit of significand
last = s0.find('e') - 1; // last digit of significand
} else {
log10x = static_cast<int>(std::floor(std::log10(std::abs(x))));
s0 = fmt::format("{:.{}f}", x, precision - log10x);
Expand Down
3 changes: 3 additions & 0 deletions test/general/test_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ TEST(YamlWriter, formatDouble)
// check edge cases
m["a"] = -1061.793215682400;
EXPECT_EQ(m.toYamlString(), "a: -1061.7932156824\n");

m["a"] = 7.820059054328200e-111;
EXPECT_EQ(m.toYamlString(), "a: 7.8200590543282e-111\n");
}

TEST(YamlWriter, formatDoubleExp)
Expand Down

0 comments on commit e34aec2

Please sign in to comment.