Use fixed format in double->string conversion by default.
GitOrigin-RevId: 5fdffeefb6f843ff3290bda21b2a71d5ea275f3f
This commit is contained in:
parent
e3867152e7
commit
ecf5405d86
@ -71,6 +71,7 @@ StringBuilder &StringBuilder::operator<<(double x) {
|
||||
static TD_THREAD_LOCAL std::stringstream *ss;
|
||||
if (init_thread_local<std::stringstream>(ss)) {
|
||||
ss->imbue(std::locale::classic());
|
||||
ss->setf(std::ios_base::fixed, std::ios_base::floatfield);
|
||||
} else {
|
||||
ss->str(std::string());
|
||||
ss->clear();
|
||||
|
@ -200,19 +200,20 @@ static void test_to_double_one(CSlice str, Slice expected) {
|
||||
}
|
||||
|
||||
static void test_to_double() {
|
||||
test_to_double_one("0", "0");
|
||||
test_to_double_one("1", "1");
|
||||
test_to_double_one("-10", "-10");
|
||||
test_to_double_one("1.234", "1.234");
|
||||
test_to_double_one("-1.234e2", "-123.4");
|
||||
test_to_double_one("0", "0.000000");
|
||||
test_to_double_one("1", "1.000000");
|
||||
test_to_double_one("-10", "-10.000000");
|
||||
test_to_double_one("1.234", "1.234000");
|
||||
test_to_double_one("-1.234e2", "-123.400000");
|
||||
test_to_double_one("inf", "inf");
|
||||
test_to_double_one(" inF asdasd", "inf");
|
||||
test_to_double_one(" inFasdasd", "0");
|
||||
test_to_double_one(" inFasdasd", "0.000000");
|
||||
test_to_double_one(" NaN", "nan");
|
||||
test_to_double_one(" 12345678910111213141516171819 asdasd", "1.23457e+28");
|
||||
test_to_double_one("1.234567891011121314E123", "1.23457e+123");
|
||||
test_to_double_one("123456789", "1.23457e+08");
|
||||
test_to_double_one("-1,234567891011121314E123", "-1");
|
||||
test_to_double_one(" 12345678910111213141516171819 asdasd", "12345678910111213670658736128.000000");
|
||||
test_to_double_one("1.234567891011121314E123", "1234567891011121363209105003376291141757777526749278953577304234065881343284952489418916814035346625663604561924259911303168.000000");
|
||||
test_to_double_one("1.234567891011121314E-9", "0.000000");
|
||||
test_to_double_one("123456789", "123456789.000000");
|
||||
test_to_double_one("-1,234567891011121314E123", "-1.000000");
|
||||
}
|
||||
|
||||
TEST(Misc, to_double) {
|
||||
|
Reference in New Issue
Block a user