Date: Thursday, January 26, 2006 @ 16:51:20
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: SQLDataSerialization.cpp (1.18 -> 1.19)

Simplified a bit floats_little_endianness() and ints_little_endianness()


--------------------------+
 SQLDataSerialization.cpp |   56 +++++++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 24 deletions(-)


Index: carob/src/SQLDataSerialization.cpp
diff -u carob/src/SQLDataSerialization.cpp:1.18 
carob/src/SQLDataSerialization.cpp:1.19
--- carob/src/SQLDataSerialization.cpp:1.18     Wed Jan 25 23:59:02 2006
+++ carob/src/SQLDataSerialization.cpp  Thu Jan 26 16:51:20 2006
@@ -36,12 +36,12 @@
 //   by Java's DataOutput class
 
 #ifndef __STDC_IEC_559__
-#error only IEEE 754 platforms are supported
+#error "only IEEE 754 platforms are supported"
 #endif
  // run-time equivalent is: numeric_limits<double|float>.is_iec559()
 
 #if (CHAR_BIT != 8)
-#error CHAR_BIT != 8 is not supported
+#error "CHAR_BIT != 8 is not supported"
 #endif
 
 using std::wstring;
@@ -335,9 +335,11 @@
     // insert a '1' in the digit before the last
     float e125fbis_ = e125f_ + e125f_ / (1 << 22);
 
-    uint32_t e125f = F2I(e125f_);
-    uint32_t e125fbis = F2I(e125fbis_);
+    const uint32_t e125f = F2I(e125f_);
+    const uint32_t e125fbis = F2I(e125fbis_);
 
+    const unsigned char *e125f_uc = reinterpret_cast<const unsigned 
char*>(&e125f);
+    const unsigned char *e125fbis_uc = reinterpret_cast<const unsigned 
char*>(&e125fbis);
 
     // build some magical double constants
 
@@ -348,24 +350,27 @@
     // insert a '1' in the digit before the last
     double e1007dbis_ = e1007d_ + e1007d_ / ((uint64_t) 1 << 51);
 
-    uint64_t e1007d = D2I(e1007d_);
-    uint64_t e1007dbis = D2I(e1007dbis_);
+    const uint64_t e1007d = D2I(e1007d_);
+    const uint64_t e1007dbis = D2I(e1007dbis_);
+
+    const unsigned char *e1007d_uc = reinterpret_cast<const unsigned 
char*>(&e1007d);
+    const unsigned char *e1007dbis_uc = reinterpret_cast<const unsigned 
char*>(&e1007dbis);
 
     // then check if we have an classical MSB-float arch
     // (sign, exponent, fraction)
     // UNTESTED
-    if (reinterpret_cast<unsigned char*>(&e125f)[0] == 1
-        && reinterpret_cast<unsigned char*>(&e125fbis)[3] == 2
-        && reinterpret_cast<unsigned char*>(&e1007d)[0] == 1
-        && reinterpret_cast<unsigned char*>(&e1007dbis)[7] == 2)
+    if (e125f_uc[0] == 1
+        && e125fbis_uc[3] == 2
+        && e1007d_uc[0] == 1
+        && e1007dbis_uc[7] == 2)
         return false;
 
     // else check if we have an classical LSB-float arch
     // TESTED (on IA32)
-    if (reinterpret_cast<unsigned char*>(&e125f)[3] == 1
-        && reinterpret_cast<unsigned char*>(&e125fbis)[0] == 2
-        && reinterpret_cast<unsigned char*>(&e1007d)[7] == 1
-        && reinterpret_cast<unsigned char*>(&e1007dbis)[0] == 2)
+    if (e125f_uc[3] == 1
+        && e125fbis_uc[0] == 2
+        && e1007d_uc[7] == 1
+        && e1007dbis_uc[0] == 2)
         return true;
 
     // else weird unsupported arch, abort
@@ -375,24 +380,27 @@
 bool
 ints_little_endianness()
 {
-    uint32_t i = 0x01000002U;
-    uint64_t l = 0x0100000000000002ULL;
+    const uint32_t I = 0x01000002U;
+    const uint64_t L = 0x0100000000000002ULL;
+
+    const unsigned char *i_uc = reinterpret_cast<const unsigned char*>(&I);
+    const unsigned char *l_uc = reinterpret_cast<const unsigned char*>(&L);
 
     // then check if we have an classical MSB-float arch
     // (sign, exponent, fraction)
     // UNTESTED
-    if (reinterpret_cast<unsigned char*>(&i)[0] == 1
-        && reinterpret_cast<unsigned char*>(&i)[3] == 2
-        && reinterpret_cast<unsigned char*>(&l)[0] == 1
-        && reinterpret_cast<unsigned char*>(&l)[7] == 2)
+    if (i_uc[0] == 1
+        && i_uc[3] == 2
+        && l_uc[0] == 1
+        && l_uc[7] == 2)
         return false;
 
     // else check if we have an classical LSB-float arch
     // TESTED (on IA32)
-    if (reinterpret_cast<unsigned char*>(&i)[3] == 1
-        && reinterpret_cast<unsigned char*>(&i)[0] == 2
-        && reinterpret_cast<unsigned char*>(&l)[7] == 1
-        && reinterpret_cast<unsigned char*>(&l)[0] == 2)
+    if (i_uc[3] == 1
+        && i_uc[0] == 2
+        && l_uc[7] == 1
+        && l_uc[0] == 2)
         return true;
 
     // else weird unsupported arch, abort

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to