diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-03-18 09:30:10 +0000 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-03-18 09:30:10 +0000 |
commit | d4f4e6ee2c1eb80b8a1d3199e7747405fee956a3 (patch) | |
tree | 8493bf7873baf689004e71be7911cb4b1f04a335 /lib/Support | |
parent | f09a8b533d8a28550e1a739c1ce8da167260c25f (diff) | |
download | external_llvm-d4f4e6ee2c1eb80b8a1d3199e7747405fee956a3.zip external_llvm-d4f4e6ee2c1eb80b8a1d3199e7747405fee956a3.tar.gz external_llvm-d4f4e6ee2c1eb80b8a1d3199e7747405fee956a3.tar.bz2 |
raw_ostream: [PR6745] Tweak formatting (double)%e for Windows hosts.
On MSVCRT and compatible, output of %e is incompatible to Posix by default. Number of exponent digits should be at least 2. "%+03d"
FIXME: Implement our formatter in future!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/raw_ostream.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index a2ca101..5a71fa3 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -220,6 +220,36 @@ raw_ostream &raw_ostream::operator<<(const void *P) { } raw_ostream &raw_ostream::operator<<(double N) { +#ifdef _WIN32 + // On MSVCRT and compatible, output of %e is incompatible to Posix + // by default. Number of exponent digits should be at least 2. "%+03d" + // FIXME: Implement our formatter to here or Support/Format.h! + int fpcl = _fpclass(N); + + // negative zero + if (fpcl == _FPCLASS_NZ) + return *this << "-0.000000e+00"; + + char buf[16]; + unsigned len; + len = snprintf(buf, sizeof(buf), "%e", N); + if (len <= sizeof(buf) - 2) { + if (len >= 5 && buf[len - 5] == 'e' && buf[len - 3] == '0') { + int cs = buf[len - 4]; + if (cs == '+' || cs == '-') { + int c1 = buf[len - 2]; + int c0 = buf[len - 1]; + if (isdigit(c1) && isdigit(c0)) { + // Trim leading '0': "...e+012" -> "...e+12\0" + buf[len - 3] = c1; + buf[len - 2] = c0; + buf[--len] = 0; + } + } + } + return this->operator<<(buf); + } +#endif return this->operator<<(format("%e", N)); } |