lmi
[Top][All Lists]
Advanced

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

[lmi] 0x0000000000000000 != 0x0000000000000000


From: Greg Chicares
Subject: [lmi] 0x0000000000000000 != 0x0000000000000000
Date: Sun, 21 May 2017 22:56:05 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

The patch below [0] seems to construct a 'double' that is bitwise
identical to zero, yet compares unequal to zero. How can this be?

This outcome is seen only with 64-bit msw (not with 32-bit msw,
and not with 64-bit GNU/Linux).

The patch merely embellishes a failing unit test. Most of the patch
just copies some boost code from another unit test.

Here's the cross-compiler I installed from debian:

$x86_64-w64-mingw32-g++ -dumpversion
4.9.1

Commands used to compile and link:

x86_64-w64-mingw32-g++ -MMD -MP -MT tn_range_test.o -MF tn_range_test.d  -c -I 
/opt/lmi/src/lmi -I /opt/lmi/src/lmi/tools/pete-2.1.1 -I 
/opt/lmi/third_party/include -I /opt/lmi/third_party/src -I 
/opt/lmi/local/include -I /opt/lmi/local/include/libxml2 -DLMI_WX_NEW_USE_SO  
-DLIBXML_USE_DLL -DSTRICT     -DBOOST_STRICT_CONFIG   -std=c++11 
-pedantic-errors -Werror -Wall -Wcast-align -Wconversion 
-Wdeprecated-declarations -Wdisabled-optimization -Wextra -Wimport -Wmultichar 
-Wpacked -Wpointer-arith -Wredundant-decls -Wsign-compare -Wundef 
-Wwrite-strings  -Wno-long-long -Wctor-dtor-privacy -Wdeprecated 
-Wnon-template-friend -Woverloaded-virtual -Wpmf-conversions -Wsynth  
-Wcast-qual  -Wno-conversion -Wno-deprecated-declarations -Wno-parentheses 
-Wno-unused-local-typedefs -Wno-unused-variable     -ggdb -O2 
-fno-omit-frame-pointer    /opt/lmi/src/lmi/tn_range_test.cpp -otn_range_test.o
x86_64-w64-mingw32-g++ -o tn_range_test.exe alert.o alert_cli.o fenv_lmi.o 
getopt.o license.o datum_base.o facets.o tn_range_test.o tn_range_test_aux.o -L 
. -L /opt/lmi/local-x86_64-w64/lib -L /opt/lmi/local-x86_64-w64/bin -L 
/opt/lmi/local/lib -L /opt/lmi/local/bin   -lexslt -lxslt -lxml2      
-Wl,-Map,tn_range_test.exe.map 

Outcome of running the test under 64-bit wine:

Running tn_range_test:
hex value of 0.0 is: 0000000000000000 / 0000000000000000
hex value of p1.minimum() is: 0000000000000000 / 0000000000000000

tiny 2.225074e-308
p1.minimum() 0.000000e+000
0

???? test failed:   '0.000000e+000' == '0.000000e+000'
[file /opt/lmi/src/lmi/tn_range_test.cpp, line 690]

???? test failed:   '0.000000e+000' == '0.000000e+000'
[file /opt/lmi/src/lmi/tn_range_test.cpp, line 694]

???? 2 test errors detected; 323 tests succeeded

---------

[0] "The patch below":

---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/tn_range_test.cpp b/tn_range_test.cpp
index 5d115a4..e9da7e7 100644
--- a/tn_range_test.cpp
+++ b/tn_range_test.cpp
@@ -579,6 +579,56 @@ void tn_range_test::test_diagnostics()
     BOOST_TEST_EQUAL(s, v);
 }
 
+// print_hex_val() bears the following copyright and permission:
+/* boost limits_test.cpp   test your <limits> file for important
+ *
+ * Copyright Jens Maurer 2000
+ * Permission to use, copy, modify, sell, and distribute this software
+ * is hereby granted without free [sic] provided that the above copyright 
notice
+ * appears in all copies and that both that copyright notice and this
+ * permission notice appear in supporting documentation,
+ *
+ * Jens Maurer makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ */
+// GWC modified the code as noted below, e.g. to print in byte-reversed
+// order as well, and made some trivial formatting changes.
+template<typename T>
+void print_hex_val(T t, char const* name)
+{
+  // GWC changed C cast to reinterpret_cast:
+  unsigned char const* p = reinterpret_cast<unsigned char const*>(&t);
+  std::cout << "hex value of " << name << " is: ";
+
+// GWC modifications begin
+  // For gcc with x87, sizeof(long double) == 12, but only
+  // ten bytes are significant--the other two are padding.
+  std::size_t size_of_T = sizeof(T);
+#if defined __GNUC__ && defined LMI_X87
+  if(12 == size_of_T)
+    size_of_T = 10;
+#endif // defined __GNUC__ && defined LMI_X87
+// GWC modifications end
+
+  for(unsigned int i = 0; i < size_of_T; ++i) { // modified by GWC
+    if(p[i] <= 0xF)
+      std::cout << "0";
+    // GWC changed C cast to static_cast:
+    std::cout << std::hex << static_cast<int>(p[i]);
+  }
+// GWC modifications begin
+  std::cout << " / ";
+  for(int i = size_of_T - 1; 0 <= i; --i) {
+    if(p[i] <= 0xF)
+      std::cout << "0";
+    std::cout << std::hex << static_cast<int>(p[i]);
+  }
+  std::cout << std::dec << std::endl;
+// GWC modifications end
+}
+
 void tn_range_test::test_absurd_limits()
 {
     absurd<int> a;
@@ -628,10 +678,20 @@ void tn_range_test::test_absurd_limits()
         ,"Cannot change upper bound to 101, which is greater than supremum 100 
."
         );
 
+print_hex_val(0.0, "0.0");
+print_hex_val(p1.minimum(), "p1.minimum()");
+std::cout << std::endl;
     // Make sure p1's limits aren't affected by the change in p0's.
+double tiny = std::numeric_limits<double>::min();
+std::cout << std::scientific << "tiny " << tiny << std::endl;
+std::cout << std::scientific << "p1.minimum() " << p1.minimum() << std::endl;
+std::cout << (0 == p1.minimum()) << std::endl;
 
     BOOST_TEST_EQUAL(p1.minimum(),   0.0);
     BOOST_TEST_EQUAL(p1.maximum(), 100.0);
+
+    double const p1min = p1.minimum();
+    BOOST_TEST_EQUAL(p1min,   0.0);
 }
 
 void tn_range_test::test_nonfundamental_number_type()
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------



reply via email to

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