llvm.org GIT mirror llvm / 9006170
Revert r189442 "Change default # of digits for APFloat::toString" This is breaking numerous Clang tests on the buildbot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189447 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 6 years ago
2 changed file(s) with 9 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
35453545 // Set FormatPrecision if zero. We want to do this before we
35463546 // truncate trailing zeros, as those are part of the precision.
35473547 if (!FormatPrecision) {
3548 // We use enough digits so the number can be round-tripped back to an
3549 // APFloat. The formula comes from "How to Print Floating-Point Numbers
3550 // Accurately" by Steele and White.
3551 // FIXME: Using a formula based purely on the precision is conservative;
3552 // we can print fewer digits depending on the actual value being printed.
3553
3554 // FormatPrecision = 2 + floor(significandBits / lg_2(10))
3555 FormatPrecision = 2 + semantics->precision * 59 / 196;
3548 // It's an interesting question whether to use the nominal
3549 // precision or the active precision here for denormals.
3550
3551 // FormatPrecision = ceil(significandBits / lg_2(10))
3552 FormatPrecision = (semantics->precision * 59 + 195) / 196;
35563553 }
35573554
35583555 // Ignore trailing binary zeros.
865865 ASSERT_EQ("0.0101", convertToString(1.01E-2, 5, 2));
866866 ASSERT_EQ("0.0101", convertToString(1.01E-2, 4, 2));
867867 ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1));
868 ASSERT_EQ("0.78539816339744828", convertToString(0.78539816339744830961, 0, 3));
869 ASSERT_EQ("4.9406564584124654E-324", convertToString(4.9406564584124654e-324, 0, 3));
870 ASSERT_EQ("873.18340000000001", convertToString(873.1834, 0, 1));
871 ASSERT_EQ("8.7318340000000001E+2", convertToString(873.1834, 0, 0));
872 ASSERT_EQ("1.7976931348623157E+308", convertToString(1.7976931348623157E+308, 0, 0));
868 ASSERT_EQ("0.7853981633974483", convertToString(0.78539816339744830961, 0, 3));
869 ASSERT_EQ("4.940656458412465E-324", convertToString(4.9406564584124654e-324, 0, 3));
870 ASSERT_EQ("873.1834", convertToString(873.1834, 0, 1));
871 ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0));
873872 }
874873
875874 TEST(APFloatTest, toInteger) {