LogStream::operator<< (const T& t)
{
// do the work that is common to
- // the two operator<< functions
+ // the operator<< functions
print (t);
return *this;
}
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');
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
<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
--- /dev/null
+//---------------------------- 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;
+}
+