[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5003] Rename 'quiet_nan*.?pp' to 'ieee754*.?pp'
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5003] Rename 'quiet_nan*.?pp' to 'ieee754*.?pp' |
Date: |
Tue, 22 Jun 2010 00:11:38 +0000 |
Revision: 5003
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5003
Author: chicares
Date: 2010-06-22 00:11:37 +0000 (Tue, 22 Jun 2010)
Log Message:
-----------
Rename 'quiet_nan*.?pp' to 'ieee754*.?pp'
Modified Paths:
--------------
lmi/trunk/Makefile.am
lmi/trunk/objects.make
Added Paths:
-----------
lmi/trunk/ieee754.hpp
lmi/trunk/ieee754_test.cpp
Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am 2010-06-21 20:51:46 UTC (rev 5002)
+++ lmi/trunk/Makefile.am 2010-06-22 00:11:37 UTC (rev 5003)
@@ -104,6 +104,7 @@
test_financial \
test_global_settings \
test_handle_exceptions \
+ test_ieee754 \
test_input_seq \
test_input \
test_irc7702a \
@@ -124,7 +125,6 @@
test_print_matrix \
test_product_file \
test_progress_meter \
- test_quiet_nan \
test_round \
test_round_to \
test_rtti_lmi \
@@ -595,6 +595,11 @@
handle_exceptions_test.cpp
test_handle_exceptions_CXXFLAGS = $(AM_CXXFLAGS)
+test_ieee754_SOURCES = \
+ $(common_test_objects) \
+ ieee754_test.cpp
+test_ieee754_CXXFLAGS = $(AM_CXXFLAGS)
+
test_input_seq_SOURCES = \
$(common_test_objects) \
input_seq_test.cpp \
@@ -778,11 +783,6 @@
test_progress_meter_LDADD = \
liblmi.la
-test_quiet_nan_SOURCES = \
- $(common_test_objects) \
- quiet_nan_test.cpp
-test_quiet_nan_CXXFLAGS = $(AM_CXXFLAGS)
-
test_round_SOURCES = \
$(common_test_objects) \
round_test.cpp
@@ -940,6 +940,7 @@
group_values.hpp \
handle_exceptions.hpp \
icon_monger.hpp \
+ ieee754.hpp \
ihs_irc7702.hpp \
ihs_irc7702a.hpp \
ihs_server7702.hpp \
@@ -1021,7 +1022,6 @@
product_editor.hpp \
product_names.hpp \
progress_meter.hpp \
- quiet_nan.hpp \
round_to.hpp \
rounding_document.hpp \
rounding_rules.hpp \
Copied: lmi/trunk/ieee754.hpp (from rev 4964, lmi/trunk/quiet_nan.hpp)
===================================================================
--- lmi/trunk/ieee754.hpp (rev 0)
+++ lmi/trunk/ieee754.hpp 2010-06-22 00:11:37 UTC (rev 5003)
@@ -0,0 +1,78 @@
+// IEEE 754 esoterica.
+//
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Gregory W.
Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// http://savannah.nongnu.org/projects/lmi
+// email: <address@hidden>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+// $Id$
+
+#ifndef ieee754_hpp
+#define ieee754_hpp
+
+#include "config.hpp"
+
+#if !defined __BORLANDC__
+# include <boost/static_assert.hpp>
+# include <boost/type_traits/arithmetic_traits.hpp>
+#else // Defined __BORLANDC__ .
+# define BOOST_STATIC_ASSERT(deliberately_ignored) class IgNoRe
+#endif // Defined __BORLANDC__ .
+
+#include <limits>
+
+/// Quiet NaN on IEC559-conforming implementations; otherwise, an
+/// implausible value, optionally specified.
+///
+/// It is sometimes profitable to initialize a floating-point variable
+/// to a recognizably implausible value. A quiet NaN is generally the
+/// best such value.
+///
+/// For non-conforming implementations, an 'implausible' value may be
+/// specified if desired, although there's no guarantee that it won't
+/// arise in practice. If none is specified, then we choose one with
+/// FLT_DIG decimal digits and an exponent a bit under FLT_MAX_10_EXP,
+/// using the minimum values of those macros in C99 5.2.4.2.2/8. The
+/// same behavior is used for borland tools, which claim to support
+/// qNaNs but do not:
+/// http://lists.boost.org/MailArchives/boost/msg12131.php
+/// there's no borland option to set the floating-point hardware to
+/// allow quiet NaNs to work without raising an exception.
+/// Without this workaround, bc++5.5.1 would produce a BSOD on msw xp.
+
+template<typename T>
+T implausible_value(T const& t = -9.99999e35)
+{
+ BOOST_STATIC_ASSERT(::boost::is_float<T>::value);
+
+#if defined __BORLANDC__
+ return t;
+#else // !defined __BORLANDC__
+
+ if(std::numeric_limits<T>::has_quiet_NaN)
+ {
+ return std::numeric_limits<T>::quiet_NaN();
+ }
+ else
+ {
+ return t;
+ }
+#endif // !defined __BORLANDC__
+}
+
+#endif // ieee754_hpp
+
Copied: lmi/trunk/ieee754_test.cpp (from rev 4964, lmi/trunk/quiet_nan_test.cpp)
===================================================================
--- lmi/trunk/ieee754_test.cpp (rev 0)
+++ lmi/trunk/ieee754_test.cpp 2010-06-22 00:11:37 UTC (rev 5003)
@@ -0,0 +1,59 @@
+// IEEE 754 esoterica.
+//
+// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// http://savannah.nongnu.org/projects/lmi
+// email: <address@hidden>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+// $Id$
+
+#ifdef __BORLANDC__
+# include "pchfile.hpp"
+# pragma hdrstop
+#endif // __BORLANDC__
+
+#include "ieee754.hpp"
+
+#include "test_tools.hpp"
+
+#include <limits>
+
+int test_main(int, char*[])
+{
+ if(std::numeric_limits<double>::has_quiet_NaN)
+ {
+ std::cerr << "has quiet NaN" << std::endl;
+ }
+ else
+ {
+ std::cerr << "lacks quiet NaN" << std::endl;
+ }
+
+ float x = implausible_value<float> ();
+ double y = implausible_value<double> ();
+ long double z = implausible_value<long double>();
+
+ bool xx = x == x;
+ BOOST_TEST(!xx);
+ bool yy = y == y;
+ BOOST_TEST(!yy);
+ bool zz = z == z;
+ BOOST_TEST(!zz);
+
+ return 0;
+}
+
Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make 2010-06-21 20:51:46 UTC (rev 5002)
+++ lmi/trunk/objects.make 2010-06-22 00:11:37 UTC (rev 5003)
@@ -460,6 +460,7 @@
getopt_test \
global_settings_test \
handle_exceptions_test \
+ ieee754_test \
input_seq_test \
input_test \
irc7702a_test \
@@ -480,7 +481,6 @@
print_matrix_test \
product_file_test \
progress_meter_test \
- quiet_nan_test \
regex_test \
round_test \
round_to_test \
@@ -643,6 +643,10 @@
$(common_test_objects) \
handle_exceptions_test.o \
+ieee754_test$(EXEEXT): \
+ $(common_test_objects) \
+ ieee754_test.o \
+
input_seq_test$(EXEEXT): \
$(common_test_objects) \
input_seq_test.o \
@@ -815,10 +819,6 @@
progress_meter_cli.o \
progress_meter_test.o \
-quiet_nan_test$(EXEEXT): \
- $(common_test_objects) \
- quiet_nan_test.o \
-
regex_test$(EXEEXT): EXTRA_LDFLAGS = -Wl,--allow-multiple-definition
regex_test$(EXEEXT): \
$(boost_regex_objects) \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5003] Rename 'quiet_nan*.?pp' to 'ieee754*.?pp',
Greg Chicares <=