Date: Monday, January 15, 2007 @ 14:00:28
Author: marc
Path: /cvsroot/carob/carob
Modified: src/SQLDataSerialization.cpp (1.38 -> 1.39)
test/40-Parameter-PreparedStatement/TestIEEE754.cpp (1.19 ->
1.20)
Introduced CAROB_DEBUG_FLOAT macro
-----------------------------------------------------+
src/SQLDataSerialization.cpp | 18 ++++--
test/40-Parameter-PreparedStatement/TestIEEE754.cpp | 51 ++++++++++++------
2 files changed, 49 insertions(+), 20 deletions(-)
Index: carob/src/SQLDataSerialization.cpp
diff -u carob/src/SQLDataSerialization.cpp:1.38
carob/src/SQLDataSerialization.cpp:1.39
--- carob/src/SQLDataSerialization.cpp:1.38 Mon Jan 15 12:12:32 2007
+++ carob/src/SQLDataSerialization.cpp Mon Jan 15 14:00:28 2007
@@ -102,6 +102,12 @@
return res;
}
+#ifdef CAROB_DEBUG_FLOAT
+namespace CarobNS {
+#else
+namespace {
+#endif
+
// Float
/**
* Relatively safe "reinterpret_cast" of an IEEE 754 float to its
@@ -110,7 +116,7 @@
* is typically the same as for integer types, but not granted.
* @param f value to convert
*/
-static inline uint32_t
+inline uint32_t
floatToU32Bits(float f)
{
// "union casting" using { float; uint32_t; } or the simpler:
@@ -128,7 +134,7 @@
| (uint32_t) bytes[0];
}
-static inline float
+inline float
U32BitsToFloat(const uint32_t ui)
{
float res;
@@ -150,7 +156,7 @@
* is typically the same as for integer types, but not granted.
* @param d value to convert
*/
-static inline uint64_t
+inline uint64_t
doubleToU64Bits(double d)
{
const unsigned char *bytes = reinterpret_cast<const unsigned char *>(&d);
@@ -165,7 +171,7 @@
| (uint64_t) bytes[0];
}
-static inline double
+inline double
U64BitsToDouble(const uint64_t ui)
{
double res;
@@ -183,6 +189,10 @@
return res;
}
+
+} // anonymous namespace
+
+
/**
* Converts the input integer which is in in IEEE 754 floating-point
* "single format" bit layout to the corresponding float.
Index: carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp
diff -u carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp:1.19
carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp:1.20
--- carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp:1.19 Thu Jan
11 23:30:59 2007
+++ carob/test/40-Parameter-PreparedStatement/TestIEEE754.cpp Mon Jan 15
14:00:28 2007
@@ -47,6 +47,13 @@
using std::signbit;
#endif
+#ifdef CAROB_DEBUG_FLOAT
+namespace CarobNS {
+uint32_t floatToU32Bits(float f);
+uint64_t doubleToU64Bits(double d);
+}
+#endif
+
using namespace CarobNS;
namespace {
@@ -55,23 +62,35 @@
typedef std::numeric_limits<double> Doubles;
typedef struct _fd { float f; double d; } fd_t;
+
void
printrow(float f, double d)
{
- std::cout.setf(std::ios_base::scientific, std::ios_base::floatfield);
- std::cout.setf(std::ios_base::hex, std::ios_base::basefield);
- std::cout.setf(std::ios_base::showbase | std::ios_base::internal);
- std::cout.fill('0');
-
- std::cout.precision(9);
- std::cout << f << " (=";
- std::cout.width(10);
-// export these functions from SQLDataSerialization.[ch]pp for debug
-// std::cout << floatToU32Bits(f) << ") | ";
- std::cout.precision(17);
- std::cout << d << " (=";
- std::cout.width(18);
-// std::cout << doubleToU64Bits(d) << ")";
+ using std::cout;
+
+ std::ios_base::fmtflags old_flags = cout.flags();
+
+ cout.setf(std::ios_base::scientific, std::ios_base::floatfield);
+ cout.setf(std::ios_base::hex, std::ios_base::basefield);
+ cout.setf(std::ios_base::showbase | std::ios_base::internal);
+ cout.fill('0');
+
+ cout.precision(9);
+ cout << f << " (=";
+ cout.width(10);
+#ifdef CAROB_DEBUG_FLOAT // see SQLDataSerialization.cpp
+ cout << floatToU32Bits(f) << ") | ";
+#endif
+ cout.precision(17);
+ cout << d << " (=";
+ cout.width(18);
+#ifdef CAROB_DEBUG_FLOAT
+ cout << doubleToU64Bits(d) << ")";
+#endif
+
+ // restore settings
+ cout.flags(old_flags);
+
}
template <class FP> bool
@@ -121,13 +140,13 @@
CPPUNIT_ASSERT(drsPtr->next());
CPPUNIT_ASSERT(drsPtr->getAsInt(1) == row);
-#define DEBUGIT 0
-#if DEBUGIT
+#if CAROB_DEBUG_FLOAT
std::cout << "tried to send: ";
printrow(data[row].f, data[row].d);
std::cout << std::endl << "received: ";
printrow(drsPtr->getAsFloat(2), drsPtr->getDouble(3));
std::cout << std::endl;
+ // asserting may interrupt test
#else // assert it
CPPUNIT_ASSERT(better_equal(drsPtr->getAsFloat(2), data[row].f));
CPPUNIT_ASSERT(better_equal(drsPtr->getDouble(3), data[row].d));
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits