|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56476 - sandbox/numeric_adaptor/boost/numeric_adaptor
From: barend.gehrels_at_[hidden]
Date: 2009-09-29 15:47:20
Author: barendgehrels
Date: 2009-09-29 15:47:19 EDT (Tue, 29 Sep 2009)
New Revision: 56476
URL: http://svn.boost.org/trac/boost/changeset/56476
Log:
Added constructors with char const*
Added stream operators
Made free functions inline
Text files modified:
sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp | 47 +++++++++++++++++++++++++++++++------
sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp | 50 ++++++++++++++++++++++++++++++++++-----
2 files changed, 82 insertions(+), 15 deletions(-)
Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_value_type.hpp 2009-09-29 15:47:19 EDT (Tue, 29 Sep 2009)
@@ -10,6 +10,9 @@
#ifndef BOOST_NUMERIC_ADAPTOR_CLN_VALUE_TYPE_HPP
#define BOOST_NUMERIC_ADAPTOR_CLN_VALUE_TYPE_HPP
+// CLN can be downloaded from http://www.ginac.de/CLN/
+
+#include <ostream>
#include <cln/cln.h>
#include <cln/float.h>
@@ -25,7 +28,7 @@
as being of type cl_F.
*/
-struct cln_value_type //: public default_value_type<cln_policy, cln::cl_F>
+struct cln_value_type
{
cln_value_type()
: m_value(cln::cl_float(0.0, cln::float_format(256)))
@@ -38,6 +41,14 @@
m_value = cln::cl_float(v, cln::float_format(256));
}
+ cln_value_type(char const* s)
+ : m_value(cln::cl_float(0.0, cln::float_format(256)))
+ {
+ // Conversions from `const char *' are provided [...]
+ m_value = s;
+ }
+
+
cln_value_type(cln::cl_F const& v)
: m_value(v)
{}
@@ -104,6 +115,20 @@
return cln_value_type(-v.m_value);
}
+
+ template <typename Char, typename Traits>
+ friend inline std::basic_ostream<Char, Traits>& operator<<(
+ std::basic_ostream<Char, Traits>& os, cln_value_type const& v)
+ {
+ cln::cl_print_flags flags;
+ flags.default_float_format = cln::float_format_dfloat;
+ cln::print_float(os, flags, v.m_value);
+ return os;
+ }
+
+
+
+
cln::cl_F m_value;
};
@@ -111,37 +136,43 @@
} // namespace numeric_adaptor
-numeric_adaptor::cln_value_type abs(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type abs(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::abs(v.m_value));
}
-numeric_adaptor::cln_value_type sqrt(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type sqrt(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::sqrt(v.m_value));
}
-numeric_adaptor::cln_value_type cos(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type cos(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::cos(v.m_value));
}
-numeric_adaptor::cln_value_type sin(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type sin(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::sin(v.m_value));
}
-numeric_adaptor::cln_value_type tan(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type tan(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::tan(v.m_value));
}
-numeric_adaptor::cln_value_type atan(numeric_adaptor::cln_value_type const& v)
+inline numeric_adaptor::cln_value_type atan(
+ numeric_adaptor::cln_value_type const& v)
{
return numeric_adaptor::cln_value_type(cln::atan(v.m_value));
}
-numeric_adaptor::cln_value_type hypot(
+inline numeric_adaptor::cln_value_type hypot(
numeric_adaptor::cln_value_type const& a,
numeric_adaptor::cln_value_type const& b)
{
Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_value_type.hpp 2009-09-29 15:47:19 EDT (Tue, 29 Sep 2009)
@@ -30,6 +30,13 @@
mpf_set_d(m_value, v);
}
+ gmp_value_type(char const* s)
+ {
+ mpf_init(m_value);
+ mpf_set_str(m_value, s, 10);
+ }
+
+
gmp_value_type(mpf_t& v)
{
mpf_init(m_value);
@@ -129,6 +136,29 @@
return r;
}
+
+ template <typename Char, typename Traits>
+ friend inline std::basic_ostream<Char, Traits>& operator<<(
+ std::basic_ostream<Char, Traits>& os, gmp_value_type const& v)
+ {
+ mp_exp_t exponent;
+
+ char* s = mpf_get_str(NULL, &exponent, 10, 0, v.m_value);
+
+ if (exponent != 0)
+ {
+ os << "0." << s << "e" << exponent;
+ }
+ else
+ {
+ os << s;
+ }
+ free(s);
+ return os;
+ }
+
+
+
mpf_t m_value;
};
@@ -136,41 +166,47 @@
} // namespace numeric_adaptor
-numeric_adaptor::gmp_value_type abs(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type abs(
+ numeric_adaptor::gmp_value_type const& v)
{
numeric_adaptor::gmp_value_type r;
mpf_abs(r.m_value, v.m_value);
return r;
}
-numeric_adaptor::gmp_value_type sqrt(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type sqrt(
+ numeric_adaptor::gmp_value_type const& v)
{
numeric_adaptor::gmp_value_type r;
mpf_sqrt(r.m_value, v.m_value);
return r;
}
-numeric_adaptor::gmp_value_type cos(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type cos(
+ numeric_adaptor::gmp_value_type const& v)
{
return numeric_adaptor::gmp_value_type(std::cos(v));
}
-numeric_adaptor::gmp_value_type sin(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type sin(
+ numeric_adaptor::gmp_value_type const& v)
{
return numeric_adaptor::gmp_value_type(std::sin(v));
}
-numeric_adaptor::gmp_value_type tan(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type tan(
+ numeric_adaptor::gmp_value_type const& v)
{
return numeric_adaptor::gmp_value_type(std::tan(v));
}
-numeric_adaptor::gmp_value_type atan(numeric_adaptor::gmp_value_type const& v)
+inline numeric_adaptor::gmp_value_type atan(
+ numeric_adaptor::gmp_value_type const& v)
{
return numeric_adaptor::gmp_value_type(std::atan(v));
}
-numeric_adaptor::gmp_value_type hypot(
+inline numeric_adaptor::gmp_value_type hypot(
numeric_adaptor::gmp_value_type const& a,
numeric_adaptor::gmp_value_type const& b)
{
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