From: Wolfgang Bangerth Date: Wed, 8 Mar 2006 02:14:18 +0000 (+0000) Subject: Fix a problem where we printed '0' instead of 'nan' when printing a denormal through... X-Git-Tag: v8.0.0~12136 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfbefbaa36f887562134f1d4411ebd1109c4c15e;p=dealii.git Fix a problem where we printed '0' instead of 'nan' when printing a denormal through deallog. git-svn-id: https://svn.dealii.org/trunk@12554 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index 30262423c3..38cbe9ede0 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -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 diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 0b3c42caaf..2b1399c47d 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -258,6 +258,14 @@ inconvenience this causes.

base

    +
  1. Fixed: Writing a denormal "NaN" through LogStream objects such as + deallog erroneously printed zero, rather + than "nan". This is now fixed. +
    + (Luca Heltai, WB 2006/03/07) +

    +
  2. Improved: The TableBase base class of all the Table classes had an operator() that takes a TableIndices object diff --git a/tests/base/Makefile b/tests/base/Makefile index d644f491ce..4740d14a05 100644 --- a/tests/base/Makefile +++ b/tests/base/Makefile @@ -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 index 0000000000..e53cb2c465 --- /dev/null +++ b/tests/base/log_nan.cc @@ -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 +#include +#include + +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::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 index 0000000000..4c160f6e6e --- /dev/null +++ b/tests/base/log_nan/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::nan