aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2013-08-28 06:21:46 +0000
committerTed Kremenek <kremenek@apple.com>2013-08-28 06:21:46 +0000
commit900617094505bba1fcf4d29c54901f48a0dacfa5 (patch)
tree1fa5cfc66e7fd32070de6a795ea09e81e1200cd7
parent631bce51b962df5f4821dfd4f91599d3f7ba05f9 (diff)
downloadexternal_llvm-900617094505bba1fcf4d29c54901f48a0dacfa5.zip
external_llvm-900617094505bba1fcf4d29c54901f48a0dacfa5.tar.gz
external_llvm-900617094505bba1fcf4d29c54901f48a0dacfa5.tar.bz2
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
-rw-r--r--lib/Support/APFloat.cpp13
-rw-r--r--unittests/ADT/APFloatTest.cpp9
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index 676e2d4..34bc6b6 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -3546,14 +3546,11 @@ void APFloat::toString(SmallVectorImpl<char> &Str,
// Set FormatPrecision if zero. We want to do this before we
// truncate trailing zeros, as those are part of the precision.
if (!FormatPrecision) {
- // We use enough digits so the number can be round-tripped back to an
- // APFloat. The formula comes from "How to Print Floating-Point Numbers
- // Accurately" by Steele and White.
- // FIXME: Using a formula based purely on the precision is conservative;
- // we can print fewer digits depending on the actual value being printed.
-
- // FormatPrecision = 2 + floor(significandBits / lg_2(10))
- FormatPrecision = 2 + semantics->precision * 59 / 196;
+ // It's an interesting question whether to use the nominal
+ // precision or the active precision here for denormals.
+
+ // FormatPrecision = ceil(significandBits / lg_2(10))
+ FormatPrecision = (semantics->precision * 59 + 195) / 196;
}
// Ignore trailing binary zeros.
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp
index e57c8d4..3b69de2 100644
--- a/unittests/ADT/APFloatTest.cpp
+++ b/unittests/ADT/APFloatTest.cpp
@@ -866,11 +866,10 @@ TEST(APFloatTest, toString) {
ASSERT_EQ("0.0101", convertToString(1.01E-2, 5, 2));
ASSERT_EQ("0.0101", convertToString(1.01E-2, 4, 2));
ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1));
- ASSERT_EQ("0.78539816339744828", convertToString(0.78539816339744830961, 0, 3));
- ASSERT_EQ("4.9406564584124654E-324", convertToString(4.9406564584124654e-324, 0, 3));
- ASSERT_EQ("873.18340000000001", convertToString(873.1834, 0, 1));
- ASSERT_EQ("8.7318340000000001E+2", convertToString(873.1834, 0, 0));
- ASSERT_EQ("1.7976931348623157E+308", convertToString(1.7976931348623157E+308, 0, 0));
+ ASSERT_EQ("0.7853981633974483", convertToString(0.78539816339744830961, 0, 3));
+ ASSERT_EQ("4.940656458412465E-324", convertToString(4.9406564584124654e-324, 0, 3));
+ ASSERT_EQ("873.1834", convertToString(873.1834, 0, 1));
+ ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0));
}
TEST(APFloatTest, toInteger) {