]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a problem where we printed '0' instead of 'nan' when printing a denormal through...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 8 Mar 2006 02:14:18 +0000 (02:14 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 8 Mar 2006 02:14:18 +0000 (02:14 +0000)
git-svn-id: https://svn.dealii.org/trunk@12554 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/logstream.h
deal.II/doc/news/changes.html
tests/base/Makefile
tests/base/log_nan.cc [new file with mode: 0644]
tests/base/log_nan/cmp/generic [new file with mode: 0644]

index 30262423c3587e0ab8a896bd3ebde9f0da9c5443..38cbe9ede09632eeaf0549fd5856c874aef3a6c9 100644 (file)
@@ -416,7 +416,7 @@ LogStream &
 LogStream::operator<< (const T& t)
 {
                                   // do the work that is common to
-                                  // the two operator<< functions
+                                  // the operator<< functions
   print (t);
   return *this;
 }
@@ -427,9 +427,25 @@ inline
 LogStream &
 LogStream::operator<< (const double t)
 {
-                                  // do the work that is common to
-                                  // the two operator<< functions
-  if (std::fabs(t) > double_threshold)
+                                  // for doubles, we want to make
+                                  // sure that if a number is smaller
+                                  // than a given threshold, then we
+                                  // simply print zero (the default
+                                  // threshold is zero, but can be
+                                  // changed for automated testsuite
+                                  // runs)
+                                   //
+                                   // we have to make sure that we
+                                   // don't catch NaN's and +-Inf's
+                                   // with the test, because for these
+                                   // denormals all comparisons are
+                                   // always false. thus, for a NaN,
+                                   // both t<=0 and t>=0 are false at
+                                   // the same time, which can't be
+                                   // said for any other number
+  if ((std::fabs(t) > double_threshold)
+      ||
+      (! (t<=0) && !(t>=0)))
     print (t);
   else
     print('0');
@@ -444,7 +460,7 @@ LogStream &
 LogStream::operator<< (std::ostream& (*p) (std::ostream&))
 {
                                   // do the work that is common to
-                                  // the two operator<< functions
+                                  // the operator<< functions
   print (p);
 
                                   // next check whether this is the
index 0b3c42caafede669cb8dbb849503aed166858a03..2b1399c47dc14955bc779a35423d42ab66c2837c 100644 (file)
@@ -258,6 +258,14 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li> <p>Fixed: Writing a denormal "NaN" through <code
+       class="class">LogStream</code> objects such as 
+       <code class="member">deallog</code> erroneously printed zero, rather
+       than "nan". This is now fixed.
+       <br>
+       (Luca Heltai, WB 2006/03/07)
+       </p>
+
   <li> <p>Improved: The <code class="member">TableBase</code> base class of all
        the <code class="member">Table</code> classes had an
        <code>operator()</code> that takes a <code>TableIndices</code> object
index d644f491ce447ec954bdd80c2fd9025adf046aa7..4740d14a05e0d648f4a1dc39a7ebb491164c86aa 100644 (file)
@@ -23,6 +23,7 @@ threads.cc : threads.pl
        @$(PERL) $^ > $@
 
 tests_x =  logtest \
+          log_nan \
           reference \
           quadrature_* qprojector \
           path_search \
diff --git a/tests/base/log_nan.cc b/tests/base/log_nan.cc
new file mode 100644 (file)
index 0000000..e53cb2c
--- /dev/null
@@ -0,0 +1,35 @@
+//----------------------------  log_nan.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005, 2006 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  log_nan.cc  ---------------------------
+
+// check for a bug reported by Luca Heltai 2006-03-07 on the mailing
+// list. the test should actually output "nan", but prints "0"
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("log_nan/output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  double rn = std::numeric_limits<double>::quiet_NaN();
+  deallog << rn << std::endl;
+
+  return 0;
+}
+
diff --git a/tests/base/log_nan/cmp/generic b/tests/base/log_nan/cmp/generic
new file mode 100644 (file)
index 0000000..4c160f6
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::nan

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.