From 6e4088985ea6d9b4ac40a4ff51282ddc364101d9 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 2 Jun 2013 21:37:19 -0400 Subject: Take endian-ness into account when producing hexadecimal output for floating point numbers --- test.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test.cc b/test.cc index 18e20de..a4c35b5 100644 --- a/test.cc +++ b/test.cc @@ -73,15 +73,26 @@ struct vecmathlib_test { + static bool is_big_endian() + { + const int i = 1; + unsigned char cs[sizeof i]; + memcpy(cs, &i, sizeof i); + return cs[0]==0; + } + template - static string hex(T x) + static string hex(const T x) { unsigned char cs[sizeof x]; memcpy(cs, &x, sizeof x); ostringstream buf; buf << "0x"; const char *const hexdigits = "0123456789abcdef"; - for (size_t n=0; n>4] << hexdigits[cs[n]&15]; } return buf.str(); -- cgit v1.1