Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit221b6be

Browse files
authored
Merge pull request#1061 from CrowCpp/1042-bug-in-serialization-of-small-double
added test for issue#1042
2 parents6ba7d7f +4095ab2 commit221b6be

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

‎include/crow/json.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,9 +1876,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
18761876
if (v.nt == num_type::Double_precision_floating_point)
18771877
{
18781878
#ifdef _MSC_VER
1879-
sprintf_s(outbuf,sizeof(outbuf),"%.*g",DECIMAL_DIG, v.num.d);
1879+
sprintf_s(outbuf,sizeof(outbuf),"%.*g",DBL_DECIMAL_DIG, v.num.d);
18801880
#else
1881-
snprintf(outbuf,sizeof(outbuf),"%.*g",DECIMAL_DIG, v.num.d);
1881+
snprintf(outbuf,sizeof(outbuf),"%.*g",DBL_DECIMAL_DIG, v.num.d);
18821882
#endif
18831883
}
18841884
else

‎tests/unit_tests/test_json.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,14 @@ TEST_CASE("json Incorrect move of wvalue class #953", "[json]")
640640
json["int_value"] =getValue(-500);
641641
REQUIRE(json["int_value"].dump()=="-500");
642642
}
643+
}
644+
645+
TEST_CASE("SmallNumber #1042","[json]")
646+
{
647+
crow::json::wvalue data;
648+
constdouble smallnumber =1e-10;
649+
data["testValue"] = smallnumber;
650+
std::string text = data.dump(4);
651+
constauto expected_text ="{\n\"testValue\": 1e-10\n}";
652+
REQUIRE(text==expected_text);
643653
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp