Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55016 - in sandbox/numeric_adaptor: boost/numeric_adaptor libs/numeric_adaptor/test
From: bruno.lalande_at_[hidden]
Date: 2009-07-18 13:44:26


Author: bruno.lalande
Date: 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
New Revision: 55016
URL: http://svn.boost.org/trac/boost/changeset/55016

Log:
Refactoring finished.
Removed:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp
   sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp
   sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 221 ---------------------------------------
   sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot | 4
   2 files changed, 3 insertions(+), 222 deletions(-)

Deleted: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
+++ (empty file)
@@ -1,114 +0,0 @@
-// Numeric Adaptor Library
-//
-// Copyright Barend Gehrels 2009, Geodan, Amsterdam
-// Copyright Bruno Lalande 2009
-// Use, modification and distribution is subject to 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)
-
-
-#ifndef NUMERIC_ADAPTOR_CLN_POLICY_HPP
-#define NUMERIC_ADAPTOR_CLN_POLICY_HPP
-
-#include <string>
-
-#include <boost/numeric_adaptor/default_policy.hpp>
-
-#include <cln/cln.h>
-#include <cln/float.h>
-
-
-namespace boost { namespace numeric_adaptor {
-
-
-/*
- CLN documentation, 3.2:
- As a user of CLN, you can forget about the differences between the four
- Floating-point types and just declare all your Foating-point variables
- as being of type cl_F.
-
-*/
-struct cln_policy : public default_policy<cln_policy, cln::cl_F>
-{
- typedef cln::cl_F value_type;
-
- template <typename FromType>
- static inline void set(cln_policy& p, FromType const& v)
- {
- // Conversions from the C built-in type `double' are provided for the
- // classes cl_DF, cl_F, cl_R, cl_N and cl_number
- p.value = cln::cl_float(v, cln::float_format(256));
- }
-
- static inline void set(cln_policy& p, std::string const& v)
- {
- // CLN documentation 4.1.3 + 5.1 ("A precision specifier of the form prec may be appended")
- std::string copy(v);
- copy += "_256";
- p.value = copy.c_str();
- }
-
- static inline void abs(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::abs(a.value);
- }
-
-
- static inline void sqrt(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::sqrt(a.value);
- }
-
- static inline void cos(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::cos(a.value);
- }
-
- static inline void sin(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::sin(a.value);
- }
-
- static inline void tan(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::tan(a.value);
- }
-
- static inline void atan(cln_policy& r, cln_policy const& a)
- {
- r.value = cln::atan(a.value);
- }
-
- static inline void hypot(cln_policy& r, cln_policy const& a, cln_policy const& b)
- {
- r.value = cln::sqrt(a.value * a.value + b.value * b.value);
- }
-
-
- template <typename ToType>
- static inline ToType big_numeric_cast(cln_policy const& b)
- {
- /*
- Conversions from the classes cl_I, cl_RA, cl_SF, cl_FF,
- cl_DF, cl_LF, cl_F and cl_R
- to the C built-in types `float' and `double' are provided
- through the functions
-
- float float_approx (value_type const& x)
- double double_approx (value_type const& x)
-
- Returns an approximation of x of C type ctype. If abs(x) is
- too close to 0 (underflow),
- 0 is returned. If abs(x) is too large (overflow),
- an IEEE infinity is returned.
- */
- return ToType(double_approx(b.value));
- }
-
-};
-
-
-}} // namespace boost::numeric_adaptor
-
-
-#endif

Deleted: sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
+++ (empty file)
@@ -1,104 +0,0 @@
-// Numeric Adaptor Library
-
-// Copyright Barend Gehrels 2009, Geodan, Amsterdam
-// Copyright Bruno Lalande 2009
-// Use, modification and distribution is subject to 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)
-
-
-#ifndef NUMERIC_ADAPTOR_DEFAULT_POLICY_HPP
-#define NUMERIC_ADAPTOR_DEFAULT_POLICY_HPP
-
-#include <sstream>
-#include <iomanip>
-
-
-namespace boost { namespace numeric_adaptor {
-
-
-template <typename Derived, typename T>
-struct default_policy
-{
- typedef T value_type;
-
- default_policy()
- {}
-
- // Use the default assignment
- default_policy(default_policy const& source):
- value(source.value)
- {}
-
- // The default policy uses the default operators +, -, *, /
- static inline void add(default_policy& r, const default_policy& a, const default_policy& b)
- { r.value = a.value + b.value; }
- static inline void add(default_policy& a, const default_policy& b)
- { a.value += b.value; }
- static inline void subtract(default_policy& r, const default_policy& a, const default_policy& b)
- { r.value = a.value - b.value; }
- static inline void subtract(default_policy& a, const default_policy& b)
- { a.value -= b.value; }
- static inline void multiply(default_policy& r, const default_policy& a, const default_policy& b)
- { r.value = a.value * b.value; }
- static inline void multiply(default_policy& a, const default_policy& b)
- { a.value *= b.value; }
- static inline void divide(default_policy& r, const default_policy& a, const default_policy& b)
- { r.value = a.value / b.value; }
- static inline void divide(default_policy& a, const default_policy& b)
- { a.value /= b.value; }
- static inline void neg(default_policy& r, const default_policy& n)
- { r.value = -n.value; }
-
- static inline void cos(default_policy& r, default_policy const& a)
- {
- double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(static_cast<Derived&>(r), std::cos(d));
- }
-
- static inline void sin(default_policy& r, default_policy const& a)
- {
- double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(static_cast<Derived&>(r), std::sin(d));
- }
-
- static inline void tan(default_policy& r, default_policy const& a)
- {
- double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(static_cast<Derived&>(r), std::tan(d));
- }
-
- static inline void atan(default_policy& r, default_policy const& a)
- {
- double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(static_cast<Derived&>(r), std::atan(d));
- }
-
- static inline void sqrt(default_policy& r, default_policy const& a)
- {
- double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(static_cast<Derived&>(r), std::sqrt(d));
- }
-
- // Default use the comparison operators
- static inline int compare(default_policy const& a, default_policy const& b)
- {
- return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
- }
-
- static inline std::string as_string(default_policy const& a)
- {
- std::ostringstream out;
- out << std::setprecision(20) << a.value;
- return out.str();
- }
-
-protected:
- value_type value;
-};
-
-
-}} // namespace boost::numeric_adaptor
-
-
-#endif

Deleted: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
+++ (empty file)
@@ -1,162 +0,0 @@
-// Numeric Adaptor Library
-//
-// Copyright Barend Gehrels 2009, Geodan, Amsterdam
-// Copyright Bruno Lalande 2009
-// Use, modification and distribution is subject to 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)
-
-
-#ifndef NUMERIC_ADAPTOR_GMP_POLICY_HPP
-#define NUMERIC_ADAPTOR_GMP_POLICY_HPP
-
-
-#include <string>
-#include <cstring>
-
-#include <gmp.h>
-
-
-namespace boost { namespace numeric_adaptor {
-
-
-struct gmp_policy: default_policy<gmp_policy, mpf_t>
-{
- gmp_policy()
- {
- mpf_init(value);
- }
-
- ~gmp_policy()
- {
- mpf_clear(value);
- }
-
- gmp_policy(gmp_policy const& source)
- {
- mpf_set(value, source.value);
- }
-
- template <typename OtherType>
- static inline void set(gmp_policy& p, const OtherType& v)
- {
- mpf_set_d(p.value, v);
- }
-
- static inline void set(gmp_policy& p, const std::string& v)
- {
- mpf_set_str(p.value, v.c_str(), 10);
- }
-
-
- // TODO should we add specific overloads for function like mpf_add_ui?
-
- static inline void add(gmp_policy& r, gmp_policy const& a, gmp_policy const& b)
- {
- mpf_add(r.value, a.value, b.value);
- }
-
- static inline void add(gmp_policy& a, gmp_policy const& b)
- {
- mpf_add(a.value, a.value, b.value);
- }
-
- static inline void subtract(gmp_policy& r, gmp_policy const& a, gmp_policy const& b)
- {
- mpf_sub(r.value, a.value, b.value);
- }
-
- static inline void subtract(gmp_policy& a, gmp_policy const& b)
- {
- mpf_sub(a.value, a.value, b.value);
- }
-
- static inline void multiply(gmp_policy& r, gmp_policy const& a, gmp_policy const& b)
- {
- mpf_mul(r.value, a.value, b.value);
- }
-
- static inline void multiply(gmp_policy& a, gmp_policy const& b)
- {
- mpf_mul(a.value, a.value, b.value);
- }
-
- static inline void divide(gmp_policy& r, gmp_policy const& a, gmp_policy const& b)
- {
- mpf_div(r.value, a.value, b.value);
- }
-
- static inline void divide(gmp_policy& a, gmp_policy const& b)
- {
- mpf_div(a.value, a.value, b.value);
- }
-
- static inline void neg(gmp_policy& r, gmp_policy const& n)
- {
- mpf_neg(r.value, n.value);
- }
-
- static inline void abs(gmp_policy& r, gmp_policy const& a)
- {
- mpf_abs(r.value, a.value);
- }
-
- static inline void sqrt(gmp_policy& r, gmp_policy const& a)
- {
- mpf_sqrt(r.value, a.value);
- }
-
- static inline void hypot(gmp_policy& r, gmp_policy const& a, gmp_policy const& b)
- {
- mpf_mul(r.value, a.value, a.value);
- value_type t;
- mpf_init(t);
- mpf_mul(t, b.value, b.value);
- mpf_add(t, r.value, t);
- mpf_sqrt(r.value, t);
- mpf_clear(t);
- }
-
-
- template <typename OtherType>
- static inline OtherType big_numeric_cast(gmp_policy const& b)
- {
- return mpf_get_d(b.value);
- }
-
-
- static inline std::string as_string(gmp_policy const& a)
- {
- mp_exp_t exponent;
- static char s[1024];
- mpf_get_str (s, &exponent, 10, sizeof(s) - 1, a.value);
-
- std::string out;
- out.reserve(100);
-
- // TODO: this is probably not working well for large numbers -> add e0X
-
- register int i = 0;
- for (register const char* ptr = s; *ptr; ptr++, i++)
- {
- if (i == exponent)
- {
- out += ".";
- }
- out += *ptr;
- }
- return out;
- }
-
-
- static inline int compare(gmp_policy const& a, gmp_policy const& b)
- {
- return mpf_cmp(a.value, b.value);
- }
-};
-
-
-}} // namespace boost::numeric_adaptor
-
-
-#endif

Deleted: sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
+++ (empty file)
@@ -1,60 +0,0 @@
-// Numeric Adaptor Library
-
-// Copyright Barend Gehrels 2009, Geodan, Amsterdam
-// Copyright Bruno Lalande 2009
-// Use, modification and distribution is subject to 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)
-
-
-#ifndef NUMERIC_ADAPTOR_IEEE_POLICY_HPP
-#define NUMERIC_ADAPTOR_IEEE_POLICY_HPP
-
-
-#include <cmath>
-
-#include <string>
-
-#include <boost/numeric_adaptor/default_policy.hpp>
-
-#include <boost/numeric/conversion/cast.hpp>
-#include <boost/lexical_cast.hpp>
-
-#include <boost/math/special_functions/hypot.hpp>
-
-
-namespace boost { namespace numeric_adaptor {
-
-
-template <typename T>
-struct ieee_policy : public default_policy<ieee_policy<T>, T>
-{
- typedef T value_type;
-
- template <typename OtherType>
- static inline void set(ieee_policy& p, OtherType const& v)
- { p.value = v; } //boost::numeric_cast<T>(v); }
-
- static inline void set(ieee_policy& p, std::string const& v)
- { p.value = boost::lexical_cast<T>(v); }
-
- static inline void abs(ieee_policy& r, ieee_policy const& a)
- { r.value = std::abs(a.value); }
-
- static inline void hypot(ieee_policy& r, ieee_policy const& a, ieee_policy const& b)
- {
- r.value = boost::math::hypot(a.value, b.value);
- }
-
- template <typename OtherType>
- static inline OtherType big_numeric_cast(ieee_policy const& v)
- {
- return boost::numeric_cast<OtherType>(v.value);
- }
-};
-
-
-}} // namespace boost::numeric_adaptor
-
-
-#endif

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
@@ -12,230 +12,11 @@
 
 
 #include <cmath>
-#include <string>
 #include <boost/static_assert.hpp>
 #include <boost/math/special_functions/hypot.hpp>
 
 
-namespace boost { namespace numeric_adaptor {
-
-
-template <typename Base, typename T>
-struct enable_cast
-{
- inline operator T()
- {
- return static_cast<Base*>(this)->template big_numeric_cast<T>();
- }
-};
-
-
-template <typename Policy>
-struct numeric_adaptor:
- Policy,
- enable_cast<numeric_adaptor<Policy>, int>,
- enable_cast<numeric_adaptor<Policy>, unsigned int>,
- enable_cast<numeric_adaptor<Policy>, short int>,
- enable_cast<numeric_adaptor<Policy>, unsigned short int>,
- enable_cast<numeric_adaptor<Policy>, long int>,
- enable_cast<numeric_adaptor<Policy>, unsigned long int>,
- enable_cast<numeric_adaptor<Policy>, float>,
- enable_cast<numeric_adaptor<Policy>, double>,
- enable_cast<numeric_adaptor<Policy>, long double>
-{
- inline numeric_adaptor()
- {}
-
- // Copy constructor
- inline numeric_adaptor(numeric_adaptor<Policy> const& v):
- Policy(v)
- {}
-
- // Constructor from a string
- inline numeric_adaptor(std::string const& v)
- {
- Policy::set(*this, v);
- }
-
- inline numeric_adaptor(const char* v)
- {
- Policy::set(*this, std::string(v));
- }
-
- // Constructor with a normal IEEE type
- template <typename FromType>
- inline numeric_adaptor(FromType const& v)
- {
- Policy::template set<FromType>(*this, v);
- }
-
- // Assignment from normal IEEE type
- template <typename FromType>
- inline numeric_adaptor<Policy> operator=(FromType const& v)
- {
- Policy::template set<FromType>(*this, v);
- return *this;
- }
-
- template <class ToType>
- inline ToType big_numeric_cast()
- {
- return Policy::template big_numeric_cast<ToType>(*this);
- }
-
- // tuple/fusion/variant-like get template function
- inline operator std::string()
- {
- return Policy::as_string(*this);
- }
-
-
- // Comparisons
- inline bool operator<(numeric_adaptor<Policy> const& other) const
- {
- return Policy::compare(*this, other) < 0;
- }
-
- inline bool operator>(numeric_adaptor<Policy> const& other) const
- {
- return Policy::compare(*this, other) > 0;
- }
-
- inline bool operator==(numeric_adaptor<Policy> const& other) const
- {
- return Policy::compare(*this, other) == 0;
- }
-
- // Operators
- friend inline numeric_adaptor<Policy> operator+(
- numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
- {
- numeric_adaptor<Policy> r;
- Policy::add(r, a, b);
- return r;
- }
-
- numeric_adaptor<Policy>& operator+=(numeric_adaptor<Policy> const& other)
- {
- Policy::add(*this, other);
- return *this;
- }
-
- friend inline numeric_adaptor<Policy> operator*(
- numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
- {
- numeric_adaptor<Policy> r;
- Policy::multiply(r, a, b);
- return r;
- }
-
- numeric_adaptor<Policy>& operator*=(numeric_adaptor<Policy> const& other)
- {
- Policy::multiply(*this, other);
- return *this;
- }
-
- friend inline numeric_adaptor<Policy> operator-(
- numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
- {
- numeric_adaptor<Policy> r;
- Policy::subtract(r, a, b);
- return r;
- }
-
- numeric_adaptor<Policy>& operator-=(numeric_adaptor<Policy> const& other)
- {
- Policy::subtract(*this, other);
- return *this;
- }
-
- friend inline numeric_adaptor<Policy> operator/(
- numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
- {
- numeric_adaptor<Policy> r;
- Policy::divide(r, a, b);
- return r;
- }
-
- numeric_adaptor<Policy>& operator/=(numeric_adaptor<Policy> const& other)
- {
- Policy::divide(*this, other);
- return *this;
- }
-
- friend inline numeric_adaptor<Policy> operator-(numeric_adaptor<Policy> const& n)
- {
- numeric_adaptor<Policy> r;
- Policy::neg(r, n);
- return r;
- }
-};
-
-
-template <typename Policy>
-inline numeric_adaptor<Policy> abs(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::abs(r, v);
- return r;
-}
-
-template <typename Policy>
-inline numeric_adaptor<Policy> sqrt(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::sqrt(r, v);
- return r;
-}
-
-template <typename Policy>
-inline numeric_adaptor<Policy> cos(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::cos(r, v);
- return r;
-}
-
-template <typename Policy>
-inline numeric_adaptor<Policy> sin(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::sin(r, v);
- return r;
-}
-
-template <typename Policy>
-inline numeric_adaptor<Policy> tan(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::tan(r, v);
- return r;
-}
-
-template <typename Policy>
-inline numeric_adaptor<Policy> atan(numeric_adaptor<Policy> const& v)
-{
- numeric_adaptor<Policy> r;
- Policy::atan(r, v);
- return r;
-}
-
-
-template <typename Policy>
-inline numeric_adaptor<Policy> hypot(numeric_adaptor<Policy> const& a,
- numeric_adaptor<Policy> const& b)
-{
- numeric_adaptor<Policy> r;
- Policy::hypot(r, a, b);
- return r;
-}
-
-
-} // namespace numeric_adaptor
+namespace boost {
 
 
 template <class T>

Modified: sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot
==============================================================================
--- sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot (original)
+++ sandbox/numeric_adaptor/libs/numeric_adaptor/test/Jamroot 2009-07-18 13:44:24 EDT (Sat, 18 Jul 2009)
@@ -18,7 +18,7 @@
 
 import testing ;
 
-#run test_heron.cpp ;
-#run test_arithmetic.cpp ;
+run test_heron.cpp ;
+run test_arithmetic.cpp ;
 run test_trig.cpp ;
 #run test_conversions.cpp ;


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