[llvm-commits] [llvm] r127872 - in /llvm/trunk: lib/Support/raw_ostream.cpp utils/lit/lit/TestingConfig.py

NAKAMURA Takumi geek4civic at gmail.com
Fri Mar 18 02:30:10 PDT 2011


Author: chapuni
Date: Fri Mar 18 04:30:10 2011
New Revision: 127872

URL: http://llvm.org/viewvc/llvm-project?rev=127872&view=rev
Log:
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!

Modified:
    llvm/trunk/lib/Support/raw_ostream.cpp
    llvm/trunk/utils/lit/lit/TestingConfig.py

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=127872&r1=127871&r2=127872&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Fri Mar 18 04:30:10 2011
@@ -220,6 +220,36 @@
 }
 
 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));
 }
 

Modified: llvm/trunk/utils/lit/lit/TestingConfig.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestingConfig.py?rev=127872&r1=127871&r2=127872&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestingConfig.py (original)
+++ llvm/trunk/utils/lit/lit/TestingConfig.py Fri Mar 18 04:30:10 2011
@@ -17,7 +17,6 @@
                 'PATHEXT' : os.environ.get('PATHEXT',''),
                 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
                 'LLVM_DISABLE_CRT_DEBUG' : '1',
-                'PRINTF_EXPONENT_DIGITS' : '2',
                 'PYTHONUNBUFFERED' : '1',
                 }
 





More information about the llvm-commits mailing list