Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2007-12-01 13:08:53


Author: steven_watanabe
Date: 2007-12-01 13:08:53 EST (Sat, 01 Dec 2007)
New Revision: 41541
URL: http://svn.boost.org/trac/boost/changeset/41541

Log:
Added numeric_limits specialization
Added:
   sandbox/units/boost/units/limits.hpp (contents, props changed)
   sandbox/units/libs/units/test/test_limits.cpp (contents, props changed)
Text files modified:
   sandbox/units/libs/units/test/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Added: sandbox/units/boost/units/limits.hpp
==============================================================================
--- (empty file)
+++ sandbox/units/boost/units/limits.hpp 2007-12-01 13:08:53 EST (Sat, 01 Dec 2007)
@@ -0,0 +1,54 @@
+// mcs::units - A C++ library for zero-overhead dimensional analysis and
+// unit/quantity manipulation and conversion
+//
+// Copyright (C) 2003-2007 Matthias Christian Schabel
+// Copyright (C) 2007 Steven Watanabe
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <limits>
+
+#include <boost/units/units_fwd.hpp>
+
+namespace std {
+
+template<class Unit, class T>
+class numeric_limits< ::boost::units::quantity<Unit, T> >
+{
+ public:
+ typedef ::boost::units::quantity<Unit, T> quantity_type;
+ static const bool is_specialized = std::numeric_limits<T>::is_specialized;
+ static quantity_type min() { return(quantity_type::from_value(std::numeric_limits<T>::min())); }
+ static quantity_type max() { return(quantity_type::from_value(std::numeric_limits<T>::max())); }
+ static const int digits = std::numeric_limits<T>::digits;
+ static const int digits10 = std::numeric_limits<T>::digits10;
+ static const bool is_signed = std::numeric_limits<T>::is_signed;
+ static const bool is_integer = std::numeric_limits<T>::is_integer;
+ static const bool is_exact = std::numeric_limits<T>::is_exact;
+ static const int radix = std::numeric_limits<T>::radix;
+ static quantity_type epsilon() { return(quantity_type::from_value(std::numeric_limits<T>::epsilon())); }
+ static quantity_type round_error() { return(quantity_type::from_value(std::numeric_limits<T>::round_error())); }
+ static const int min_exponent = std::numeric_limits<T>::min_exponent;
+ static const int min_exponent10 = std::numeric_limits<T>::min_exponent10;
+ static const int max_exponent = std::numeric_limits<T>::max_exponent;
+ static const int max_exponent10 = std::numeric_limits<T>::max_exponent10;
+ static const bool has_infinity = std::numeric_limits<T>::has_infinity;
+ static const bool has_quiet_NaN = std::numeric_limits<T>::has_quiet_NaN;
+ static const bool has_signaling_NaN = std::numeric_limits<T>::has_signaling_NaN;
+ static const float_denorm_style has_denorm = std::numeric_limits<T>::has_denorm;
+ static const bool has_denorm_loss = std::numeric_limits<T>::has_denorm_loss;
+ static quantity_type infinity() { return(quantity_type::from_value(std::numeric_limits<T>::infinity())); }
+ static quantity_type quiet_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::quiet_NaN())); }
+ static quantity_type signaling_NaN() { return(quantity_type::from_value(std::numeric_limits<T>::signaling_NaN())); }
+ static quantity_type denorm_min() { return(quantity_type::from_value(std::numeric_limits<T>::denorm_min())); }
+ static const bool is_iec559 = std::numeric_limits<T>::is_iec559;
+ static const bool is_bounded = std::numeric_limits<T>::is_bounded;
+ static const bool is_modulo = std::numeric_limits<T>::is_modulo;
+ static const bool traps = std::numeric_limits<T>::traps;
+ static const bool tinyness_before = std::numeric_limits<T>::tinyness_before;
+ static const float_round_style round_style = std::numeric_limits<T>::round_style;
+};
+
+}

Modified: sandbox/units/libs/units/test/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/test/Jamfile.v2 (original)
+++ sandbox/units/libs/units/test/Jamfile.v2 2007-12-01 13:08:53 EST (Sat, 01 Dec 2007)
@@ -27,6 +27,7 @@
     [ run test_absolute.cpp : : : : ]
     [ run test_default_conversion.cpp : : : : ]
     [ run test_cmath.cpp : : : : ]
+ [ run test_limits.cpp : : : : ]
     [ compile-fail fail_implicit_conversion.cpp : : ]
     [ compile-fail fail_quantity_construct.cpp : : ]
     [ compile-fail fail_quantity_assign.cpp : : ]

Added: sandbox/units/libs/units/test/test_limits.cpp
==============================================================================
--- (empty file)
+++ sandbox/units/libs/units/test/test_limits.cpp 2007-12-01 13:08:53 EST (Sat, 01 Dec 2007)
@@ -0,0 +1,117 @@
+// mcs::units - A C++ library for zero-overhead dimensional analysis and
+// unit/quantity manipulation and conversion
+//
+// Copyright (C) 2003-2007 Matthias Christian Schabel
+// Copyright (C) 2007 Steven Watanabe
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+/**
+\file
+
+\brief test_limits.cpp
+
+\detailed
+Test numeric_limits specialization.
+
+Output:
+@verbatim
+@endverbatim
+**/
+
+#include <complex>
+#include <limits>
+
+#include <boost/units/limits.hpp>
+#include <boost/units/cmath.hpp>
+
+#include "test_header.hpp"
+
+typedef boost::units::length unit_type;
+using boost::units::quantity;
+
+template<bool>
+struct check_quiet_NaN;
+
+template<>
+struct check_quiet_NaN<true> {
+ template<class T>
+ static void apply() {
+ BOOST_CHECK(isnan BOOST_PREVENT_MACRO_SUBSTITUTION ((std::numeric_limits<quantity<unit_type, T> >::quiet_NaN)()));
+ }
+};
+
+template<>
+struct check_quiet_NaN<false> {
+ template<class T>
+ static void apply() {}
+};
+
+template<bool>
+struct check_signaling_NaN;
+
+template<>
+struct check_signaling_NaN<true> {
+ template<class T>
+ static void apply() {
+ BOOST_CHECK(isnan BOOST_PREVENT_MACRO_SUBSTITUTION ((std::numeric_limits<quantity<unit_type, T> >::signaling_NaN)()));
+ }
+};
+
+template<>
+struct check_signaling_NaN<false> {
+ template<class T>
+ static void apply() {}
+};
+
+template<class T>
+void do_check() {
+ #define CHECK_FUNCTION(name) BOOST_CHECK(((std::numeric_limits<T>::name)() == (std::numeric_limits<quantity<unit_type, T> >::name)().value()))
+ #define CHECK_CONSTANT(name) BOOST_CHECK((std::numeric_limits<T>::name == std::numeric_limits<quantity<unit_type, T> >::name))
+ CHECK_FUNCTION(min);
+ CHECK_FUNCTION(max);
+ CHECK_FUNCTION(epsilon);
+ CHECK_FUNCTION(round_error);
+ CHECK_FUNCTION(infinity);
+ CHECK_FUNCTION(denorm_min);
+
+ CHECK_CONSTANT(is_specialized);
+ CHECK_CONSTANT(digits);
+ CHECK_CONSTANT(digits10);
+ CHECK_CONSTANT(is_signed);
+ CHECK_CONSTANT(is_integer);
+ CHECK_CONSTANT(is_exact);
+ CHECK_CONSTANT(radix);
+ CHECK_CONSTANT(min_exponent);
+ CHECK_CONSTANT(min_exponent10);
+ CHECK_CONSTANT(max_exponent);
+ CHECK_CONSTANT(max_exponent10);
+ CHECK_CONSTANT(has_infinity);
+ CHECK_CONSTANT(has_quiet_NaN);
+ CHECK_CONSTANT(has_signaling_NaN);
+ CHECK_CONSTANT(has_denorm);
+ CHECK_CONSTANT(has_denorm_loss);
+ CHECK_CONSTANT(is_iec559);
+ CHECK_CONSTANT(is_bounded);
+ CHECK_CONSTANT(is_modulo);
+ CHECK_CONSTANT(traps);
+ CHECK_CONSTANT(tinyness_before);
+ CHECK_CONSTANT(round_style);
+
+ check_quiet_NaN<std::numeric_limits<quantity<unit_type, T> >::has_quiet_NaN>::template apply<T>();
+ check_signaling_NaN<std::numeric_limits<quantity<unit_type, T> >::has_signaling_NaN>::template apply<T>();
+}
+
+int test_main(int,char *[])
+{
+ do_check<float>();
+ do_check<double>();
+ do_check<int>();
+ do_check<long>();
+ do_check<unsigned>();
+ do_check<std::complex<double> >();
+
+ return(0);
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk