|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80577 - in sandbox/big_number: boost/multiprecision boost/multiprecision/detail libs/multiprecision/doc libs/multiprecision/test
From: john_at_[hidden]
Date: 2012-09-18 12:47:06
Author: johnmaddock
Date: 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
New Revision: 80577
URL: http://svn.boost.org/trac/boost/changeset/80577
Log:
Fix GCC C++11 mode failures.
Tidy up TODO list.
Text files modified:
sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp | 13 +++++-
sandbox/big_number/boost/multiprecision/cpp_int.hpp | 10 ++--
sandbox/big_number/boost/multiprecision/detail/default_ops.hpp | 24 +++++++++++++
sandbox/big_number/libs/multiprecision/doc/multiprecision.qbk | 71 ++++++++++++++++++++-------------------
sandbox/big_number/libs/multiprecision/test/test.hpp | 35 +++++++++++++++---
sandbox/big_number/libs/multiprecision/test/test_arithmetic.cpp | 18 +++------
6 files changed, 111 insertions(+), 60 deletions(-)
Modified: sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_dec_float.hpp 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -16,6 +16,7 @@
#include <boost/array.hpp>
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/detail/big_lanczos.hpp>
+#include <vector>
//
// Headers required for Boost.Math integration:
@@ -38,11 +39,17 @@
namespace detail{
+template <class T, class Allocator>
+struct rebind
+{
+ typedef typename Allocator::template rebind<T>::other type;
+};
+
template <class T, unsigned S, class Allocator>
-struct dynamic_array : public std::vector<T, Allocator>
+struct dynamic_array : public std::vector<T, typename rebind<T, Allocator>::type>
{
dynamic_array()
- : std::vector<T, Allocator>(static_cast<std::vector<T, Allocator>::size_type>(S), static_cast<T>(0)) {}
+ : std::vector<T, typename rebind<T, Allocator>::type>(static_cast<typename std::vector<T, typename rebind<T, Allocator>::type>::size_type>(S), static_cast<T>(0)) {}
};
}
@@ -1668,7 +1675,7 @@
// Thus the integer part is zero.
return zero();
}
- else if(exp >= Digits10 - 1)
+ else if(exp >= static_cast<ExponentType>(Digits10 - 1))
{
// The number is too large to resolve the integer part.
// Thus it is already a pure integer part.
Modified: sandbox/big_number/boost/multiprecision/cpp_int.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/cpp_int.hpp (original)
+++ sandbox/big_number/boost/multiprecision/cpp_int.hpp 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -1702,7 +1702,7 @@
subtract_unsigned(result, o);
}
template <unsigned MinBits1, bool Signed1, class Allocator1, unsigned MinBits2, bool Signed2, class Allocator2>
-BOOST_FORCEINLINE void eval_subtract(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& a, const limb_type& o) BOOST_NOEXCEPT_IF(boost::is_void<Allocator>::value)
+BOOST_FORCEINLINE void eval_subtract(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& a, const limb_type& o) BOOST_NOEXCEPT_IF(boost::is_void<Allocator1>::value)
{
if(a.sign())
{
@@ -2682,22 +2682,22 @@
template <unsigned MinBits1, bool Signed1, class Allocator1, unsigned MinBits2, bool Signed2, class Allocator2>
BOOST_FORCEINLINE void eval_bitwise_and(
cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result,
- const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o)BOOST_NOEXCEPT_IF(is_void<Allocator>::value)
+ const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o)BOOST_NOEXCEPT_IF(is_void<Allocator1>::value)
{
bitwise_op(result, o, bit_and());
}
template <unsigned MinBits1, bool Signed1, class Allocator1, unsigned MinBits2, bool Signed2, class Allocator2>
-BOOST_FORCEINLINE void eval_bitwise_or(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(is_void<Allocator>::value)
+BOOST_FORCEINLINE void eval_bitwise_or(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(is_void<Allocator1>::value)
{
bitwise_op(result, o, bit_or());
}
template <unsigned MinBits1, bool Signed1, class Allocator1, unsigned MinBits2, bool Signed2, class Allocator2>
-BOOST_FORCEINLINE void eval_bitwise_xor(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(is_void<Allocator>::value)
+BOOST_FORCEINLINE void eval_bitwise_xor(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(is_void<Allocator1>::value)
{
bitwise_op(result, o, bit_xor());
}
template <unsigned MinBits1, bool Signed1, class Allocator1, unsigned MinBits2, bool Signed2, class Allocator2>
-BOOST_FORCEINLINE void eval_complement(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(boost::is_void<Allocator>::value)
+BOOST_FORCEINLINE void eval_complement(cpp_int_backend<MinBits1, Signed1, Allocator1, false>& result, const cpp_int_backend<MinBits2, Signed2, Allocator2, false>& o) BOOST_NOEXCEPT_IF(boost::is_void<Allocator1>::value)
{
// Increment and negate:
result = o;
Modified: sandbox/big_number/boost/multiprecision/detail/default_ops.hpp
==============================================================================
--- sandbox/big_number/boost/multiprecision/detail/default_ops.hpp (original)
+++ sandbox/big_number/boost/multiprecision/detail/default_ops.hpp 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -177,6 +177,9 @@
//
// Default versions of 3-arg arithmetic functions, these mostly just forward to the 2 arg versions:
//
+template <class T, class U, class V>
+void eval_add(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_add_default(T& t, const T& u, const T& v)
{
@@ -224,6 +227,9 @@
eval_add_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_subtract(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_subtract_default(T& t, const T& u, const T& v)
{
@@ -273,6 +279,9 @@
eval_subtract_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_multiply(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_multiply_default(T& t, const T& u, const T& v)
{
@@ -320,6 +329,9 @@
eval_multiply_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_divide(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_divide_default(T& t, const T& u, const T& v)
{
@@ -375,6 +387,9 @@
eval_divide_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_modulus(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_modulus_default(T& t, const T& u, const T& v)
{
@@ -430,6 +445,9 @@
eval_modulus_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_bitwise_and(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_bitwise_and_default(T& t, const T& u, const T& v)
{
@@ -477,6 +495,9 @@
eval_bitwise_and_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_bitwise_or(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_bitwise_or_default(T& t, const T& u, const T& v)
{
@@ -524,6 +545,9 @@
eval_bitwise_or_default(t, u, v);
}
+template <class T, class U, class V>
+void eval_bitwise_xor(T& t, const U& u, const V& v);
+
template <class T>
inline void eval_bitwise_xor_default(T& t, const T& u, const T& v)
{
Modified: sandbox/big_number/libs/multiprecision/doc/multiprecision.qbk
==============================================================================
--- sandbox/big_number/libs/multiprecision/doc/multiprecision.qbk (original)
+++ sandbox/big_number/libs/multiprecision/doc/multiprecision.qbk 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -2682,6 +2682,20 @@
[section:todo TODO]
+
+
+More a list of what ['could] be done, rather than what ['should] be done (which may be a much smaller list!).
+
+* Add back-end support for libdecNumber.
+* Add an adapter back-end for complex number types.
+* Add a back-end for MPFR interval arithmetic.
+* Add better multiplication routines (Karatsuba, FFT etc) to cpp_int_backend.
+* Add assembly level routines to cpp_int_backend.
+* Add an all C++ binary floating point type.
+* Can ring types (exact floating point types) be supported? The answer should be yes, but someone needs to write it,
+the hard part is IO and binary-decimal convertion.
+* Should there be a choice of rounding mode (probably MPFR specific)?
+
Things requested in review:
* A 2's complement fixed precision int that uses exactly N bits and no more.
@@ -2689,31 +2703,13 @@
* Each back-end should document the requirements it satisfies (not currently scheduled for inclusion: it's
deliberately an implementation detail, and "optional" requirements are optimisations which can't be detected
by the user).
-* IIUC convert_to is used to emulate in c++98 compilers C++11 explicit
-conversions. Could the explicit conversion operator be added on
-compilers supporting it? (Done 2012/09/15).
-* The front-end should make the differences between implicit and explicit
-construction (Done 2012/09/15).
* The use of bool in template parameters could be improved by the use of
an enum class which will be more explicit. E.g `enum class expression_template {disabled, enabled};
enum class sign {unsigned, signed};` (Partly done 2012/09/15).
* The ExpresionTemplate parameter could be defaulted to a traits class for more sensible defaults.
-* The library interface should use the noexcept (BOOST_NOEXCEPT, ...)
-facilities (Done 2012/09/15).
-* It is unfortunate that the generic mp_number front end can not make use
-contexpr as not all the backends can ensure this (done - we can go quite a way).
-* literals: The library doesn't provide some kind of literals. I think that the
-mp_number class should provide a way to create literals if the backend
-is able to. (Done 2012/09/15).
* The performances of mp_number<a_trivial_adaptor<float>, false>respect to
float and mp_number<a_trivial_adaptor<int>, false> and int should be
given to show the cost of using the generic interface (Mostly done, just need to update docs to the latest results).
-* The documentation should contain Throws specification on the mp_number
-and backend requirements operations. (Done 2012/09/15).
-* The tutorial should add more examples concerning implicit or explicit
-conversions. (Done 2012/09/15).
-* The documentation must explain how move semantics helps in this domain
-and what the backend needs to do to profit from this optimization. (Done 2012/09/15).
* The rounding applied when converting must be documented.
* cpp_dec_float should round to nearest.
* In a = exp1 op exp2 where a occurs inside one of exp1 or exp2 then we can optimise and eliminate one more temporary.
@@ -2723,35 +2719,42 @@
* Document what happens to small fixed precision cpp_int's.
* Should we provide min/max overloads for expression templates?
* Document why we don't abstract out addition/multiplication algorithms etc.
+* IIUC convert_to is used to emulate in c++98 compilers C++11 explicit
+conversions. Could the explicit conversion operator be added on
+compilers supporting it? (Done 2012/09/15).
+* The front-end should make the differences between implicit and explicit
+construction (Done 2012/09/15).
+* The tutorial should add more examples concerning implicit or explicit
+conversions. (Done 2012/09/15).
+* The documentation must explain how move semantics helps in this domain
+and what the backend needs to do to profit from this optimization. (Done 2012/09/15).
+* The documentation should contain Throws specification on the mp_number
+and backend requirements operations. (Done 2012/09/15).
+* The library interface should use the noexcept (BOOST_NOEXCEPT, ...)
+facilities (Done 2012/09/15).
+* It is unfortunate that the generic mp_number front end can not make use
+contexpr as not all the backends can ensure this (done - we can go quite a way).
+* literals: The library doesn't provide some kind of literals. I think that the
+mp_number class should provide a way to create literals if the backend
+is able to. (Done 2012/09/15).
-
-
-More a list of what ['could] be done, rather than what ['should] be done (which may be a much smaller list!).
-
-* Add back-end support for libdecNumber.
-* Add an adapter back-end for complex number types.
-* Add a back-end for MPFR interval arithmetic.
-* Add better multiplication routines (Karatsuba, FFT etc) to cpp_int_backend.
-* Add assembly level routines to cpp_int_backend.
-* Add an all C++ binary floating point type.
-
[h4 Pre-Review Comments]
-* Can ring types (exact floating point types) be supported? The answer should be yes, but someone needs to write it.
+* Make fixed precision orthogonal to Allocator type in cpp_int. Possible solution - add an additional MaxBits
+template argument that defaults to 0 (meaning keep going till no more space/memory).
+* Add support for fused multiply add (and subtract). GMP mpz_t could use this.
+* Can ring types (exact floating point types) be supported? The answer should be yes, but someone needs to write it (Moved to TODO list).
+* Should there be a choice of rounding mode (probably MPFR specific)? Moved to TODO list.
* Make the exponent type for cpp_dec_float a templare parameter, maybe include support for big-integer exponents.
Open question - what should be the default - int32_t or int64_t? (done 2012/09/06)
* Document the size requirements of fixed precision ints (done 2012/09/15).
* Document std lib function accuracy (done 2012/09/15).
-* Make fixed precision orthogonal to Allocator type in cpp_int. Possible solution - add an additional MaxBits
-template argument that defaults to 0 (meaning keep going till no more space/memory).
-* Add support for fused multiply add (and subtract). GMP mpz_t could use this.
* Be a bit clearer on the effects of sign-magnitude representation of cpp_int - min == -max etc - done.
* Document cpp_dec_float precision, rounding, and exponent size (done 2012/09/06).
* Can we be clearer in the docs that mixed arithmetic doesn't work (no longer applicable as of 2012/09/06)?
* Document round functions behaviour better (they behave as in C++11) (added note 2012/09/06).
-* Should there be a choice of rounding mode (probably MPFR specific)?
* Document limits on size of cpp_dec_float (done 2012/09/06).
[endsect]
Modified: sandbox/big_number/libs/multiprecision/test/test.hpp
==============================================================================
--- sandbox/big_number/libs/multiprecision/test/test.hpp (original)
+++ sandbox/big_number/libs/multiprecision/test/test.hpp 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -14,19 +14,40 @@
#include <boost/detail/lightweight_test.hpp>
#include <boost/current_function.hpp>
#include <boost/static_assert.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
+
+namespace detail{
+
+template <class T>
+inline typename boost::disable_if<boost::is_unsigned<T>, T>::type abs(const T& a)
+{
+ return a < 0 ? -a : a;
+}
+
+template <class T>
+inline typename boost::enable_if<boost::is_unsigned<T>, T>::type abs(const T& a)
+{
+ return a;
+}
+
+}
template <class T>
T relative_error(T a, T b)
{
+ using std::abs;
+ using detail::abs;
+
T min_val = (std::numeric_limits<T>::min)();
T max_val = (std::numeric_limits<T>::max)();
if((a != 0) && (b != 0))
{
// TODO: use isfinite:
- if(fabs(b) >= max_val)
+ if(abs(b) >= max_val)
{
- if(fabs(a) >= max_val)
+ if(abs(a) >= max_val)
return 0; // one infinity is as good as another!
}
// If the result is denormalised, treat all denorms as equivalent:
@@ -38,17 +59,17 @@
b = min_val;
else if((b > -min_val) && (b < 0))
b = -min_val;
- return (std::max)(fabs((a-b)/a), fabs((a-b)/b)) / std::numeric_limits<T>::epsilon();
+ return (std::max)(abs(T((a-b)/a)), abs(T((a-b)/b))) / std::numeric_limits<T>::epsilon();
}
// Handle special case where one or both are zero:
if(min_val == 0)
- return fabs(a-b);
- if(fabs(a) < min_val)
+ return abs(T(a-b));
+ if(abs(a) < min_val)
a = min_val;
- if(fabs(b) < min_val)
+ if(abs(b) < min_val)
b = min_val;
- return (std::max)(fabs((a-b)/a), fabs((a-b)/b)) / std::numeric_limits<T>::epsilon();
+ return (std::max)(abs(T((a-b)/a)), abs(T((a-b)/b))) / std::numeric_limits<T>::epsilon();
}
enum
Modified: sandbox/big_number/libs/multiprecision/test/test_arithmetic.cpp
==============================================================================
--- sandbox/big_number/libs/multiprecision/test/test_arithmetic.cpp (original)
+++ sandbox/big_number/libs/multiprecision/test/test_arithmetic.cpp 2012-09-18 12:47:03 EDT (Tue, 18 Sep 2012)
@@ -121,29 +121,25 @@
namespace detail{
-template <class T>
-typename boost::disable_if<boost::is_unsigned<T>, T>::type abs(T v)
-{
- return v < 0 ? -v : v;
-}
-template <class T>
-typename boost::enable_if<boost::is_unsigned<T>, T>::type abs(T v)
+template<class tag, class Arg1, class Arg2, class Arg3, class Arg4>
+typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type
+ abs(boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> const& v)
{
- return v;
+ typedef typename boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type result_type;
+ return v < 0 ? result_type(-v) : result_type(v);
}
}
#define BOOST_TEST_CLOSE(x, y, tol)\
- using std::abs; using detail::abs;\
if(x == 0){\
BOOST_TEST(y == 0); }\
else if(!isfloat(x)){\
BOOST_TEST(x == y); }\
- else if((x != y) && (abs((x-y)/x) > tol))\
+ else if((x != y) && (detail::abs((x-y)/x) > tol))\
{\
BOOST_ERROR("Expected tolerance was exceeded: ");\
- BOOST_LIGHTWEIGHT_TEST_OSTREAM << std::setprecision(34) << "(x-y)/x = " << abs((x-y)/x) \
+ BOOST_LIGHTWEIGHT_TEST_OSTREAM << std::setprecision(34) << "(x-y)/x = " << detail::abs((x-y)/x) \
<< " tolerance = " << tol << std::endl;\
}
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