lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master b18dfca 2/4: Merge useful parts of print_hex_


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b18dfca 2/4: Merge useful parts of print_hex_val() into floating_rep()
Date: Thu, 5 Apr 2018 08:16:54 -0400 (EDT)

branch: master
commit b18dfca3435c0df3691da818349e08b35c6fd998
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Merge useful parts of print_hex_val() into floating_rep()
    
    Took a couple of good ideas from similar code in 'round*test.cpp'. None
    of the old boost code is used, so their copyright is not needed here.
---
 miscellany.hpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/miscellany.hpp b/miscellany.hpp
index d3592fb..4381f8b 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -71,10 +71,13 @@ std::string floating_rep(T t)
 {
     std::ostringstream oss;
     oss << std::hex << std::setfill('0');
-    int realsize = sizeof(T);
-#if defined __GNUC__
-    if(12 == realsize) realsize = 10;
-#endif // defined __GNUC__
+    std::size_t realsize = sizeof(T);
+#if defined __GNUC__ && defined LMI_X87
+    // For gcc with x87, sizeof(long double) == 12, but only
+    // ten bytes are significant--the other two are padding.
+    if(12 == realsize)
+        realsize = 10;
+#endif // defined __GNUC__ && defined LMI_X87
     unsigned char const* u = reinterpret_cast<unsigned char const*>(&t);
     for(int j = realsize - 1; 0 <= j; --j)
         oss << std::setw(2) << static_cast<int>(u[j]);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]