Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77324 - in sandbox/big_number: boost/multiprecision/detail libs/multiprecision/doc libs/multiprecision/example libs/multiprecision/test
From: john_at_[hidden]
Date: 2012-03-13 14:40:53


Author: johnmaddock
Date: 2012-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
New Revision: 77324
URL: http://svn.boost.org/trac/boost/changeset/77324

Log:
Add files missing from last commit, and add new examples to tests.
Added:
   sandbox/big_number/boost/multiprecision/detail/no_et_ops.hpp (contents, props changed)
   sandbox/big_number/libs/multiprecision/example/cpp_int_snips.cpp (contents, props changed)
Removed:
   sandbox/big_number/libs/multiprecision/example/fixed_int_snips.cpp
Text files modified:
   sandbox/big_number/libs/multiprecision/doc/multiprecision.qbk | 2 +-
   sandbox/big_number/libs/multiprecision/test/Jamfile.v2 | 1 +
   2 files changed, 2 insertions(+), 1 deletions(-)

Added: sandbox/big_number/boost/multiprecision/detail/no_et_ops.hpp
==============================================================================
--- (empty file)
+++ sandbox/big_number/boost/multiprecision/detail/no_et_ops.hpp 2012-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
@@ -0,0 +1,303 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright 2012 John Maddock. 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)
+
+#ifndef BOOST_MP_NO_ET_OPS_HPP
+#define BOOST_MP_NO_ET_OPS_HPP
+
+namespace boost{
+namespace multiprecision{
+
+//
+// Operators for non-expression template enabled mp_number.
+// NOTE: this is not a complete header - really just a suffix to default_ops.hpp.
+// NOTE: these operators have to be defined after the methods in default_ops.hpp.
+//
+template <class B>
+inline mp_number<B, false> operator - (const mp_number<B, false>& v)
+{
+ mp_number<B, false> result(v);
+ result.backend().negate();
+ return result;
+}
+template <class B>
+inline mp_number<B, false> operator ~ (const mp_number<B, false>& v)
+{
+ mp_number<B, false> result;
+ eval_complement(result.backend(), v.backend());
+ return result;
+}
+//
+// Addition:
+//
+template <class B>
+inline mp_number<B, false> operator + (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_add;
+ eval_add(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator + (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_add;
+ eval_add(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator + (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_add;
+ eval_add(result.backend(), b.backend(), static_cast<canonical_type>(a));
+ return result;
+}
+//
+// Subtraction:
+//
+template <class B>
+inline mp_number<B, false> operator - (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_subtract;
+ eval_subtract(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator - (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_subtract;
+ eval_subtract(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator - (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_subtract;
+ eval_subtract(result.backend(), static_cast<canonical_type>(a), b.backend());
+ return result;
+}
+//
+// Multiply:
+//
+template <class B>
+inline mp_number<B, false> operator * (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_multiply;
+ eval_multiply(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator * (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_multiply;
+ eval_multiply(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator * (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_multiply;
+ eval_multiply(result.backend(), b.backend(), static_cast<canonical_type>(a));
+ return result;
+}
+//
+// divide:
+//
+template <class B>
+inline mp_number<B, false> operator / (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_divide;
+ eval_divide(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator / (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_divide;
+ eval_divide(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator / (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_divide;
+ eval_divide(result.backend(), static_cast<canonical_type>(a), b.backend());
+ return result;
+}
+//
+// modulus:
+//
+template <class B>
+inline mp_number<B, false> operator % (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_modulus;
+ eval_modulus(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator % (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_modulus;
+ eval_modulus(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator % (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_modulus;
+ eval_modulus(result.backend(), static_cast<canonical_type>(a), b.backend());
+ return result;
+}
+//
+// Bitwise or:
+//
+template <class B>
+inline mp_number<B, false> operator | (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_or;
+ eval_bitwise_or(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator | (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_or;
+ eval_bitwise_or(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator | (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_or;
+ eval_bitwise_or(result.backend(), b.backend(), static_cast<canonical_type>(a));
+ return result;
+}
+//
+// Bitwise xor:
+//
+template <class B>
+inline mp_number<B, false> operator ^ (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_xor;
+ eval_bitwise_xor(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator ^ (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_xor;
+ eval_bitwise_xor(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator ^ (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_xor;
+ eval_bitwise_xor(result.backend(), b.backend(), static_cast<canonical_type>(a));
+ return result;
+}
+//
+// Bitwise and:
+//
+template <class B>
+inline mp_number<B, false> operator & (const mp_number<B, false>& a, const mp_number<B, false>& b)
+{
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_and;
+ eval_bitwise_and(result.backend(), a.backend(), b.backend());
+ return result;
+}
+template <class B, class V>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator & (const mp_number<B, false>& a, const V& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_and;
+ eval_bitwise_and(result.backend(), a.backend(), static_cast<canonical_type>(b));
+ return result;
+}
+template <class V, class B>
+inline typename enable_if<is_arithmetic<V>, mp_number<B, false> >::type
+ operator & (const V& a, const mp_number<B, false>& b)
+{
+ typedef typename detail::canonical<V, B>::type canonical_type;
+ mp_number<B, false> result;
+ using default_ops::eval_bitwise_and;
+ eval_bitwise_and(result.backend(), b.backend(), static_cast<canonical_type>(a));
+ return result;
+}
+//
+// shifts:
+//
+template <class B, class I>
+inline typename enable_if<is_integral<I>, mp_number<B, false> >::type
+ operator << (const mp_number<B, false>& a, const I& b)
+{
+ mp_number<B, false> result(a);
+ using default_ops::eval_left_shift;
+ eval_left_shift(result.backend(), b);
+ return result;
+}
+template <class B, class I>
+inline typename enable_if<is_integral<I>, mp_number<B, false> >::type
+ operator >> (const mp_number<B, false>& a, const I& b)
+{
+ mp_number<B, false> result(a);
+ using default_ops::eval_right_shift;
+ eval_right_shift(result.backend(), b);
+ return result;
+}
+
+}} // namespaces
+
+#endif // BOOST_MP_NO_ET_OPS_HPP

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-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
@@ -22,7 +22,7 @@
 [import ../example/mpfr_snips.cpp]
 [import ../example/cpp_dec_float_snips.cpp]
 [import ../example/tommath_snips.cpp]
-[import ../example/fixed_int_snips.cpp]
+[import ../example/cpp_int_snips.cpp]
 
 [template mpfr[] [@http://www.mpfr.org MPFR]]
 [template gmp[] [@http://gmplib.org GMP]]

Added: sandbox/big_number/libs/multiprecision/example/cpp_int_snips.cpp
==============================================================================
--- (empty file)
+++ sandbox/big_number/libs/multiprecision/example/cpp_int_snips.cpp 2012-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
@@ -0,0 +1,64 @@
+///////////////////////////////////////////////////////////////
+// Copyright 2011 John Maddock. 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_
+
+#include <boost/multiprecision/cpp_int.hpp>
+#include <iostream>
+
+void t1()
+{
+ //[cpp_int_eg
+ //=#include <boost/multiprecision/cpp_int.hpp>
+
+ using namespace boost::multiprecision;
+
+ mp_int128_t v = 1;
+
+ // Do some fixed precision arithmetic:
+ for(unsigned i = 1; i <= 20; ++i)
+ v *= i;
+
+ std::cout << v << std::endl; // prints 20!
+
+ // Try again at arbitrary precision:
+ cpp_int u = 1;
+ for(unsigned i = 1; i <= 100; ++i)
+ u *= i;
+
+ std::cout << u << std::endl; // prints 100!
+
+ //]
+}
+
+void t3()
+{
+ //[cpp_rat_eg
+ //=#include <boost/multiprecision/cpp_int.hpp>
+
+ using namespace boost::multiprecision;
+
+ cpp_rational v = 1;
+
+ // Do some arithmetic:
+ for(unsigned i = 1; i <= 1000; ++i)
+ v *= i;
+ v /= 10;
+
+ std::cout << v << std::endl; // prints 1000! / 10
+ std::cout << numerator(v) << std::endl;
+ std::cout << denominator(v) << std::endl;
+
+ cpp_rational w(2, 3); // component wise constructor
+ std::cout << w << std::endl; // prints 2/3
+ //]
+}
+
+
+int main()
+{
+ t1();
+ t3();
+ return 0;
+}
+

Deleted: sandbox/big_number/libs/multiprecision/example/fixed_int_snips.cpp
==============================================================================
--- sandbox/big_number/libs/multiprecision/example/fixed_int_snips.cpp 2012-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
+++ (empty file)
@@ -1,34 +0,0 @@
-///////////////////////////////////////////////////////////////
-// Copyright 2011 John Maddock. 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_
-
-#include <boost/multiprecision/fixed_int.hpp>
-#include <iostream>
-
-void t1()
-{
- //[fixed_int_eg
- //=#include <boost/multiprecision/fixed_int.hpp>
-
- using namespace boost::multiprecision;
-
- mp_int128_t v = 1;
-
- // Do some arithmetic:
- for(unsigned i = 1; i <= 20; ++i)
- v *= i;
-
- std::cout << v << std::endl; // prints 20!
- v = -v;
- std::cout << std::hex << v << std::endl; // prints 2's complement representation
-
- //]
-}
-
-int main()
-{
- t1();
- return 0;
-}
-

Modified: sandbox/big_number/libs/multiprecision/test/Jamfile.v2
==============================================================================
--- sandbox/big_number/libs/multiprecision/test/Jamfile.v2 (original)
+++ sandbox/big_number/libs/multiprecision/test/Jamfile.v2 2012-03-13 14:40:52 EDT (Tue, 13 Mar 2012)
@@ -631,6 +631,7 @@
          [ check-target-builds ../config//has_mpfr : : <build>no ] ;
 
 run ../example/cpp_dec_float_snips.cpp ;
+run ../example/cpp_int_snips.cpp ;
 
 run ../example/tommath_snips.cpp $(TOMMATH)
         : # command line


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