[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 747a28d 1/4: Import floating_rep() from branc
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 747a28d 1/4: Import floating_rep() from branch |
Date: |
Thu, 5 Apr 2018 08:16:54 -0400 (EDT) |
branch: master
commit 747a28d5c719160dd02a060c3298624e015be147
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Import floating_rep() from branch
Copied from:
git show odd/1e24-vs-1e24L:sandbox_test.cpp |vim -
---
miscellany.hpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/miscellany.hpp b/miscellany.hpp
index 232137e..d3592fb 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -31,9 +31,11 @@
#include <climits> // UCHAR_MAX
#include <cstddef> // size_t
#include <cstdio> // EOF
+#include <iomanip>
#include <ios>
#include <iterator> // distance()
#include <limits> // numeric_limits
+#include <sstream>
#include <string>
#include <utility>
#include <vector>
@@ -64,6 +66,21 @@ bool each_equal(RangeExpression const& range, T const& t)
bool files_are_identical(std::string const&, std::string const&);
+template<typename T>
+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__
+ 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]);
+ return oss.str();
+}
+
/// Ascertain vector minimum and maximum efficiently.
///
/// Heterogeneous relational operators are necessarily free functions.