From 94d6513d38bc833fcb7009e6af1abd1fcbc9f36b Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 26 Sep 2011 17:03:55 +0000 Subject: [PATCH] Giant file and directory rename: changed directory name from math to multiprecision and updated code to match. [SVN r74582] --- include/boost/math/big_number.hpp | 1570 ----------------- .../math/big_number/arithmetic_backend.hpp | 147 -- .../boost/math/big_number/big_number_base.hpp | 983 ----------- include/boost/math/big_number/default_ops.hpp | 903 ---------- include/boost/math/big_number/e_float.hpp | 80 - include/boost/math/big_number/gmp.hpp | 1532 ---------------- include/boost/math/big_number/mpfr.hpp | 952 ---------- .../math/concepts/big_number_architypes.hpp | 293 --- 8 files changed, 6460 deletions(-) delete mode 100644 include/boost/math/big_number.hpp delete mode 100644 include/boost/math/big_number/arithmetic_backend.hpp delete mode 100644 include/boost/math/big_number/big_number_base.hpp delete mode 100644 include/boost/math/big_number/default_ops.hpp delete mode 100644 include/boost/math/big_number/e_float.hpp delete mode 100644 include/boost/math/big_number/gmp.hpp delete mode 100644 include/boost/math/big_number/mpfr.hpp delete mode 100644 include/boost/math/concepts/big_number_architypes.hpp diff --git a/include/boost/math/big_number.hpp b/include/boost/math/big_number.hpp deleted file mode 100644 index 6b84e39b..00000000 --- a/include/boost/math/big_number.hpp +++ /dev/null @@ -1,1570 +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_0.txt) - -#ifndef BOOST_MATH_EXTENDED_REAL_HPP -#define BOOST_MATH_EXTENDED_REAL_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost{ namespace math{ - -template -class big_number -{ - typedef big_number self_type; -public: - big_number(){} - big_number(const big_number& e) : m_backend(e.m_backend){} - template - big_number(V v, typename enable_if, is_same, is_convertible > >::type* dummy1 = 0) - { - m_backend = canonical_value(v); - } - big_number(const big_number& e, unsigned digits10) : m_backend(e.m_backend, digits10){} - template - big_number(V v, unsigned digits10, typename enable_if, is_same, is_convertible > >::type* dummy1 = 0) - { - m_backend.precision(digits10); - m_backend = canonical_value(v); - } - - template - big_number(V v, typename enable_if, mpl::not_ > > >::type* dummy1 = 0) - : m_backend(v){} - - template - big_number& operator=(const detail::big_number_exp& e) - { - do_assign(e, tag()); - return *this; - } - - big_number& operator=(const big_number& e) - { - m_backend = e.m_backend; - return *this; - } - - template - typename enable_if, is_same, is_convertible >, big_number& >::type - operator=(const V& v) - { - m_backend = canonical_value(v); - return *this; - } - - template - big_number(const detail::big_number_exp& e) - { - do_assign(e, tag()); - } - -#ifndef BOOST_NO_RVALUE_REFERENCES - big_number(big_number&& r) : m_backend(r.m_backend){} - big_number& operator=(big_number&& r) - { - m_backend.swap(r.m_backend); - return *this; - } -#endif - - big_number& operator+=(const self_type& val) - { - do_add(detail::big_number_exp(val), detail::terminal()); - return *this; - } - - template - big_number& operator+=(const detail::big_number_exp& e) - { - // Create a copy if e contains this, but not if we're just doing a - // x *= x - if(contains_self(e) && !is_self(e)) - { - self_type temp(e); - do_add(detail::big_number_exp(temp), detail::terminal()); - } - else - { - do_add(e, tag()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator+=(const V& v) - { - using big_num_default_ops::add; - add(m_backend, canonical_value(v)); - return *this; - } - - big_number& operator-=(const self_type& val) - { - do_subtract(detail::big_number_exp(val), detail::terminal()); - return *this; - } - - template - big_number& operator-=(const detail::big_number_exp& e) - { - // Create a copy if e contains this, but not if we're just doing a - if(contains_self(e)) - { - self_type temp(e); - do_subtract(temp, typename self_type::tag_type()); - } - else - { - do_subtract(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator-=(const V& v) - { - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(v)); - return *this; - } - - - big_number& operator *= (const self_type& e) - { - do_multiplies(detail::big_number_exp(e), detail::terminal()); - return *this; - } - - template - big_number& operator*=(const detail::big_number_exp& e) - { - // Create a temporary if the RHS references *this, but not - // if we're just doing an x += x; - if(contains_self(e) && !is_self(e)) - { - self_type temp(e); - do_multiplies(detail::big_number_exp(temp), detail::terminal()); - } - else - { - do_multiplies(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator*=(const V& v) - { - using big_num_default_ops::multiply; - multiply(m_backend, canonical_value(v)); - return *this; - } - - big_number& operator%=(const self_type& e) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - do_modulus(detail::big_number_exp(e), detail::terminal()); - return *this; - } - template - big_number& operator%=(const detail::big_number_exp& e) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - // Create a temporary if the RHS references *this: - if(contains_self(e)) - { - self_type temp(e); - do_modulus(temp, typename self_type::tag_type()); - } - else - { - do_modulus(e, typename Exp::tag_type()); - } - return *this; - } - template - typename enable_if, big_number& >::type - operator%=(const V& v) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - using big_num_default_ops::modulus; - modulus(m_backend, canonical_value(v)); - return *this; - } - - // - // These operators are *not* proto-ized. - // The issue is that the increment/decrement must happen - // even if the result of the operator *is never used*. - // Possibly we could modify our expression wrapper to - // execute the increment/decrement on destruction, but - // correct implemetation will be tricky, so defered for now... - // - big_number& operator++() - { - using big_num_default_ops::increment; - increment(m_backend); - return *this; - } - - big_number& operator--() - { - using big_num_default_ops::decrement; - decrement(m_backend); - return *this; - } - - big_number operator++(int) - { - using big_num_default_ops::increment; - self_type temp(*this); - increment(m_backend); - return temp; - } - - big_number operator--(int) - { - using big_num_default_ops::decrement; - self_type temp(*this); - decrement(m_backend); - return temp; - } - - template - typename enable_if, big_number&>::type operator <<= (V val) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The left-shift operation is only valid for integer types"); - check_shift_range(val, mpl::bool_<(sizeof(V) > sizeof(std::size_t))>(), is_signed()); - left_shift(m_backend, canonical_value(val)); - return *this; - } - - template - typename enable_if, big_number&>::type operator >>= (V val) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The right-shift operation is only valid for integer types"); - check_shift_range(val, mpl::bool_<(sizeof(V) > sizeof(std::size_t))>(), is_signed()); - right_shift(m_backend, canonical_value(val)); - return *this; - } - - big_number& operator /= (const self_type& e) - { - do_divide(detail::big_number_exp(e), detail::terminal()); - return *this; - } - - template - big_number& operator/=(const detail::big_number_exp& e) - { - // Create a temporary if the RHS references *this: - if(contains_self(e)) - { - self_type temp(e); - do_divide(detail::big_number_exp(temp), typename self_type::tag_type()); - } - else - { - do_divide(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator/=(const V& v) - { - using big_num_default_ops::divide; - divide(m_backend, canonical_value(v)); - return *this; - } - - big_number& operator&=(const self_type& e) - { - do_bitwise_and(detail::big_number_exp(e), detail::terminal()); - return *this; - } - - template - big_number& operator&=(const detail::big_number_exp& e) - { - // Create a temporary if the RHS references *this, but not - // if we're just doing an x &= x; - if(contains_self(e) && !is_self(e)) - { - self_type temp(e); - do_bitwise_and(temp, typename self_type::tag_type()); - } - else - { - do_bitwise_and(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator&=(const V& v) - { - using big_num_default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(v)); - return *this; - } - - big_number& operator|=(const self_type& e) - { - do_bitwise_or(detail::big_number_exp(e), detail::terminal()); - return *this; - } - - template - big_number& operator|=(const detail::big_number_exp& e) - { - // Create a temporary if the RHS references *this, but not - // if we're just doing an x |= x; - if(contains_self(e) && !is_self(e)) - { - self_type temp(e); - do_bitwise_or(temp, typename self_type::tag_type()); - } - else - { - do_bitwise_or(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator|=(const V& v) - { - using big_num_default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(v)); - return *this; - } - - big_number& operator^=(const self_type& e) - { - do_bitwise_xor(detail::big_number_exp(e), detail::terminal()); - return *this; - } - - template - big_number& operator^=(const detail::big_number_exp& e) - { - if(contains_self(e)) - { - self_type temp(e); - do_bitwise_xor(temp, typename self_type::tag_type()); - } - else - { - do_bitwise_xor(e, typename Exp::tag_type()); - } - return *this; - } - - template - typename enable_if, big_number& >::type - operator^=(const V& v) - { - using big_num_default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(v)); - return *this; - } - // - // Use in boolean context: - // - typedef bool (self_type::*unmentionable_type)()const; - - operator unmentionable_type()const - { - return is_zero() ? 0 : &self_type::is_zero; - } - - // - // swap: - // - void swap(self_type& other) - { - m_backend.swap(other.backend()); - } - // - // Zero and sign: - // - bool is_zero()const - { - using big_num_default_ops::is_zero; - return is_zero(m_backend); - } - int sign()const - { - using big_num_default_ops::get_sign; - return get_sign(m_backend); - } - // - // String conversion functions: - // - std::string str(unsigned digits = 0, bool scientific = true)const - { - return m_backend.str(digits, scientific); - } - template - T convert_to()const - { - using big_num_default_ops::convert_to; - T result; - convert_to(&result, m_backend); - return result; - } - // - // Default precision: - // - static unsigned default_precision() - { - return Backend::default_precision(); - } - static void default_precision(unsigned digits10) - { - Backend::default_precision(digits10); - } - unsigned precision()const - { - return m_backend.precision(); - } - void precision(unsigned digits10) - { - m_backend.precision(digits10); - } - // - // Comparison: - // - int compare(const big_number& o)const - { - return m_backend.compare(o.m_backend); - } - template - typename enable_if, int>::type compare(const V& o)const - { - using big_num_default_ops::get_sign; - if(o == 0) - return get_sign(m_backend); - return m_backend.compare(canonical_value(o)); - } - Backend& backend() - { - return m_backend; - } - const Backend& backend()const - { - return m_backend; - } -private: - template - void check_shift_range(V val, const mpl::true_&, const mpl::true_&) - { - if(val > (std::numeric_limits::max)()) - BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits::max().")); - if(val < 0) - BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value.")); - } - template - void check_shift_range(V val, const mpl::false_&, const mpl::true_&) - { - if(val < 0) - BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value.")); - } - template - void check_shift_range(V val, const mpl::true_&, const mpl::false_&) - { - if(val > (std::numeric_limits::max)()) - BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits::max().")); - } - template - void check_shift_range(V val, const mpl::false_&, const mpl::false_&){} - - template - void do_assign(const Exp& e, const detail::add_immediates&) - { - using big_num_default_ops::add; - add(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } -/* - template - void do_assign(const Exp& e, const detail::add_and_negate_immediates&) - { - using big_num_default_ops::add; - add(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - m_backend.negate(); - } -*/ - template - void do_assign(const Exp& e, const detail::subtract_immediates&) - { - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - /* - template - void do_assign(const Exp& e, const detail::subtract_and_negate_immediates&) - { - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - m_backend.negate(); - } - */ - template - void do_assign(const Exp& e, const detail::multiply_immediates&) - { - using big_num_default_ops::multiply; - multiply(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - - template - void do_assign(const Exp& e, const detail::divide_immediates&) - { - using big_num_default_ops::divide; - divide(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - -#if 0 - template - void do_assign(const Exp& e, const detail::multiply_and_negate_immediates&) - { - using big_num_default_ops::multiply; - multiply(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - m_backend.negate(); - } - - template - void do_assign(const Exp& e, const detail::divide_and_negate_immediates&) - { - using big_num_default_ops::divide; - divide(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - m_backend.negate(); - } - - template - void do_assign(const Exp& e, const detail::unary_plus&) - { - typedef typename Exp::left_type left_type; - do_assign(e.left(), typename left_type::tag_type()); - } - -#endif - template - void do_assign(const Exp& e, const detail::negate&) - { - typedef typename Exp::left_type left_type; - do_assign(e.left(), typename left_type::tag_type()); - m_backend.negate(); - } - template - void do_assign(const Exp& e, const detail::plus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_add(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - // Ignore the right node, it's *this, just add the left: - do_add(e.left(), typename left_type::tag_type()); - } - else if(bl || br) - { - self_type temp(e); - temp.m_backend.swap(this->m_backend); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_add(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_add(e.left(), typename left_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::minus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just subtract the right: - do_subtract(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - // Ignore the right node, it's *this, just subtract the left and negate the result: - do_subtract(e.left(), typename left_type::tag_type()); - m_backend.negate(); - } - else if(bl || br) - { - self_type temp(e); - temp.m_backend.swap(this->m_backend); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_subtract(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_subtract(e.left(), typename left_type::tag_type()); - m_backend.negate(); - } - } - template - void do_assign(const Exp& e, const detail::multiplies&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_multiplies(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - // Ignore the right node, it's *this, just add the left: - do_multiplies(e.left(), typename left_type::tag_type()); - } - else if(bl || br) - { - self_type temp(e); - temp.m_backend.swap(this->m_backend); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_multiplies(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_multiplies(e.left(), typename left_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::divides&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_divide(e.right(), typename right_type::tag_type()); - } - else if(bl || br) - { - self_type temp(e); - temp.m_backend.swap(this->m_backend); - } - else - { - do_assign(e.left(), typename left_type::tag_type()); - do_divide(e.right(), typename right_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::modulus&) - { - // - // This operation is only valid for integer backends: - // - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_modulus(e.right(), typename right_type::tag_type()); - } - else if(bl || br) - { - self_type temp(e); - temp.m_backend.swap(this->m_backend); - } - else - { - do_assign(e.left(), typename left_type::tag_type()); - do_modulus(e.right(), typename right_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::modulus_immediates&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - using big_num_default_ops::modulus; - modulus(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - - template - void do_assign(const Exp& e, const detail::bitwise_and&) - { - // - // This operation is only valid for integer backends: - // - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_bitwise_and(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - do_bitwise_and(e.left(), typename left_type::tag_type()); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_bitwise_and(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_bitwise_and(e.left(), typename left_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::bitwise_and_immediates&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - using big_num_default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - - template - void do_assign(const Exp& e, const detail::bitwise_or&) - { - // - // This operation is only valid for integer backends: - // - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_bitwise_or(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - do_bitwise_or(e.left(), typename left_type::tag_type()); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_bitwise_or(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_bitwise_or(e.left(), typename left_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::bitwise_or_immediates&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - using big_num_default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - - template - void do_assign(const Exp& e, const detail::bitwise_xor&) - { - // - // This operation is only valid for integer backends: - // - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - - static int const left_depth = left_type::depth; - static int const right_depth = right_type::depth; - - bool bl = contains_self(e.left()); - bool br = contains_self(e.right()); - - if(bl && is_self(e.left())) - { - // Ignore the left node, it's *this, just add the right: - do_bitwise_xor(e.right(), typename right_type::tag_type()); - } - else if(br && is_self(e.right())) - { - do_bitwise_xor(e.left(), typename left_type::tag_type()); - } - else if(left_depth >= right_depth) - { - do_assign(e.left(), typename left_type::tag_type()); - do_bitwise_xor(e.right(), typename right_type::tag_type()); - } - else - { - do_assign(e.right(), typename right_type::tag_type()); - do_bitwise_xor(e.left(), typename left_type::tag_type()); - } - } - template - void do_assign(const Exp& e, const detail::bitwise_xor_immediates&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "Bitwise operations are only valid for integer types"); - using big_num_default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); - } - template - void do_assign(const Exp& e, const detail::terminal&) - { - if(!is_self(e)) - { - m_backend = canonical_value(e.value()); - } - } - template - void do_assign(const Exp& e, const detail::function&) - { - typedef typename Exp::arity tag_type; - do_assign_function(e, tag_type()); - } - template - void do_assign(const Exp& e, const detail::shift_left&) - { - // We can only shift by an integer value, not an arbitrary expression: - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - typedef typename right_type::arity right_arity; - BOOST_STATIC_ASSERT_MSG(right_arity::value == 0, "The left shift operator requires an integer value for the shift operand."); - typedef typename right_type::result_type right_value_type; - BOOST_STATIC_ASSERT_MSG(is_integral::value, "The left shift operator requires an integer value for the shift operand."); - typedef typename left_type::tag_type tag_type; - do_assign_left_shift(e.left(), canonical_value(e.right().value()), tag_type()); - } - - template - void do_assign(const Exp& e, const detail::shift_right&) - { - // We can only shift by an integer value, not an arbitrary expression: - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - typedef typename right_type::arity right_arity; - BOOST_STATIC_ASSERT_MSG(right_arity::value == 0, "The left shift operator requires an integer value for the shift operand."); - typedef typename right_type::result_type right_value_type; - BOOST_STATIC_ASSERT_MSG(is_integral::value, "The left shift operator requires an integer value for the shift operand."); - typedef typename left_type::tag_type tag_type; - do_assign_right_shift(e.left(), canonical_value(e.right().value()), tag_type()); - } - - template - void do_assign(const Exp& e, const detail::bitwise_complement&) - { - using big_num_default_ops::complement; - self_type temp(e.left()); - complement(m_backend, temp.backend()); - } - - template - void do_assign(const Exp& e, const detail::complement_immediates&) - { - using big_num_default_ops::complement; - complement(m_backend, canonical_value(e.left().value())); - } - - template - void do_assign_right_shift(const Exp& e, const Val& val, const detail::terminal&) - { - using big_num_default_ops::right_shift; - right_shift(m_backend, canonical_value(e.value()), val); - } - - template - void do_assign_left_shift(const Exp& e, const Val& val, const detail::terminal&) - { - using big_num_default_ops::left_shift; - left_shift(m_backend, canonical_value(e.value()), val); - } - - template - void do_assign_right_shift(const Exp& e, const Val& val, const Tag&) - { - using big_num_default_ops::right_shift; - self_type temp(e); - right_shift(m_backend, temp.backend(), val); - } - - template - void do_assign_left_shift(const Exp& e, const Val& val, const Tag&) - { - using big_num_default_ops::left_shift; - self_type temp(e); - left_shift(m_backend, temp.backend(), val); - } - - template - void do_assign_function(const Exp& e, const mpl::int_<1>&) - { - e.left().value()(&m_backend); - } - template - void do_assign_function(const Exp& e, const mpl::int_<2>&) - { - typedef typename Exp::right_type right_type; - typedef typename right_type::tag_type tag_type; - do_assign_function_1(e.left().value(), e.right(), tag_type()); - } - template - void do_assign_function_1(const F& f, const Exp& val, const detail::terminal&) - { - f(m_backend, canonical_value(val.value())); - } - template - void do_assign_function_1(const F& f, const Exp& val, const Tag&) - { - big_number t(val); - f(m_backend, t.backend()); - } - template - void do_assign_function(const Exp& e, const mpl::int_<3>&) - { - typedef typename Exp::middle_type middle_type; - typedef typename middle_type::tag_type tag_type; - typedef typename Exp::right_type end_type; - typedef typename end_type::tag_type end_tag; - do_assign_function_2(e.left().value(), e.middle(), e.right(), tag_type(), end_tag()); - } - template - void do_assign_function_2(const F& f, const Exp1& val1, const Exp2& val2, const detail::terminal&, const detail::terminal&) - { - f(m_backend, canonical_value(val1.value()), canonical_value(val2.value())); - } - template - void do_assign_function_2(const F& f, const Exp1& val1, const Exp2& val2, const Tag1&, const detail::terminal&) - { - self_type temp1(val1); - f(m_backend, temp1.backend(), canonical_value(val2.value())); - } - template - void do_assign_function_2(const F& f, const Exp1& val1, const Exp2& val2, const detail::terminal&, const Tag2&) - { - self_type temp2(val2); - f(m_backend, canonical_value(val1.value()), temp2.backend()); - } - template - void do_assign_function_2(const F& f, const Exp1& val1, const Exp2& val2, const Tag1&, const Tag2&) - { - self_type temp1(val1); - self_type temp2(val2); - f(m_backend, temp1.backend(), temp2.backend()); - } - - template - void do_add(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::add; - add(m_backend, canonical_value(e.value())); - } - - template - void do_add(const Exp& e, const detail::negate&) - { - typedef typename Exp::left_type left_type; - do_subtract(e.left(), typename left_type::tag_type()); - } - - template - void do_add(const Exp& e, const detail::plus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_add(e.left(), typename left_type::tag_type()); - do_add(e.right(), typename right_type::tag_type()); - } - - template - void do_add(const Exp& e, const detail::minus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_add(e.left(), typename left_type::tag_type()); - do_subtract(e.right(), typename right_type::tag_type()); - } - - template - void do_add(const Exp& e, const unknown&) - { - self_type temp(e); - do_add(detail::big_number_exp(temp), detail::terminal()); - } - - template - void do_add(const Exp& e, const detail::add_immediates&) - { - using big_num_default_ops::add; - add(m_backend, canonical_value(e.left().value())); - add(m_backend, canonical_value(e.right().value())); - } - template - void do_add(const Exp& e, const detail::subtract_immediates&) - { - using big_num_default_ops::add; - using big_num_default_ops::subtract; - add(m_backend, canonical_value(e.left().value())); - subtract(m_backend, canonical_value(e.right().value())); - } - template - void do_subtract(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(e.value())); - } - - template - void do_subtract(const Exp& e, const detail::negate&) - { - typedef typename Exp::left_type left_type; - do_add(e.left(), typename left_type::tag_type()); - } - - template - void do_subtract(const Exp& e, const detail::plus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_subtract(e.left(), typename left_type::tag_type()); - do_subtract(e.right(), typename right_type::tag_type()); - } - - template - void do_subtract(const Exp& e, const detail::minus&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_subtract(e.left(), typename left_type::tag_type()); - do_add(e.right(), typename right_type::tag_type()); - } - template - void do_subtract(const Exp& e, const detail::add_immediates&) - { - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value())); - subtract(m_backend, canonical_value(e.right().value())); - } - template - void do_subtract(const Exp& e, const detail::subtract_immediates&) - { - using big_num_default_ops::add; - using big_num_default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value())); - add(m_backend, canonical_value(e.right().value())); - } - template - void do_subtract(const Exp& e, const unknown&) - { - self_type temp(e); - do_subtract(detail::big_number_exp(temp), detail::terminal()); - } - - template - void do_multiplies(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::multiply; - multiply(m_backend, canonical_value(e.value())); - } - - template - void do_multiplies(const Exp& e, const detail::negate&) - { - typedef typename Exp::left_type left_type; - do_multiplies(e.left(), typename left_type::tag_type()); - m_backend.negate(); - } - - template - void do_multiplies(const Exp& e, const detail::multiplies&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_multiplies(e.left(), typename left_type::tag_type()); - do_multiplies(e.right(), typename right_type::tag_type()); - } - - template - void do_multiplies(const Exp& e, const detail::divides&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_multiplies(e.left(), typename left_type::tag_type()); - do_divide(e.right(), typename right_type::tag_type()); - } - - template - void do_multiplies(const Exp& e, const detail::multiply_immediates&) - { - using big_num_default_ops::multiply; - multiply(m_backend, canonical_value(e.left().value())); - multiply(m_backend, canonical_value(e.right().value())); - } - template - void do_multiplies(const Exp& e, const detail::divide_immediates&) - { - using big_num_default_ops::multiply; - using big_num_default_ops::divide; - multiply(m_backend, canonical_value(e.left().value())); - divide(m_backend, canonical_value(e.right().value())); - } - template - void do_multiplies(const Exp& e, const unknown&) - { - using big_num_default_ops::multiply; - self_type temp(e); - multiply(m_backend, temp.m_backend); - } - - template - void do_divide(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::divide; - divide(m_backend, canonical_value(e.value())); - } - - template - void do_divide(const Exp& e, const detail::negate&) - { - typedef typename Exp::left_type left_type; - do_divide(e.left(), typename left_type::tag_type()); - m_backend.negate(); - } - - template - void do_divide(const Exp& e, const detail::multiplies&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_divide(e.left(), typename left_type::tag_type()); - do_divide(e.right(), typename right_type::tag_type()); - } - - template - void do_divide(const Exp& e, const detail::divides&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_divide(e.left(), typename left_type::tag_type()); - do_multiplies(e.right(), typename right_type::tag_type()); - } - - template - void do_divides(const Exp& e, const detail::multiply_immediates&) - { - using big_num_default_ops::divide; - divide(m_backend, canonical_value(e.left().value())); - divide(m_backend, canonical_value(e.right().value())); - } - template - void do_divides(const Exp& e, const detail::divide_immediates&) - { - using big_num_default_ops::multiply; - using big_num_default_ops::divide; - divide(m_backend, canonical_value(e.left().value())); - mutiply(m_backend, canonical_value(e.right().value())); - } - - template - void do_divide(const Exp& e, const unknown&) - { - using big_num_default_ops::multiply; - self_type temp(e); - divide(m_backend, temp.m_backend); - } - - template - void do_modulus(const Exp& e, const detail::terminal&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - using big_num_default_ops::modulus; - modulus(m_backend, canonical_value(e.value())); - } - - template - void do_modulus(const Exp& e, const Unknown&) - { - BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - using big_num_default_ops::modulus; - self_type temp(e); - modulus(m_backend, canonical_value(temp)); - } - - template - void do_bitwise_and(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(e.value())); - } - template - void do_bitwise_and(const Exp& e, const detail::bitwise_and&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_bitwise_and(e.left(), typename left_type::tag_type()); - do_bitwise_and(e.right(), typename right_type::tag_type()); - } - template - void do_bitwise_and(const Exp& e, const unknown&) - { - using big_num_default_ops::bitwise_and; - self_type temp(e); - bitwise_and(m_backend, temp.m_backend); - } - - template - void do_bitwise_or(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(e.value())); - } - template - void do_bitwise_or(const Exp& e, const detail::bitwise_or&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_bitwise_or(e.left(), typename left_type::tag_type()); - do_bitwise_or(e.right(), typename right_type::tag_type()); - } - template - void do_bitwise_or(const Exp& e, const unknown&) - { - using big_num_default_ops::bitwise_or; - self_type temp(e); - bitwise_or(m_backend, temp.m_backend); - } - - template - void do_bitwise_xor(const Exp& e, const detail::terminal&) - { - using big_num_default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(e.value())); - } - template - void do_bitwise_xor(const Exp& e, const detail::bitwise_xor&) - { - typedef typename Exp::left_type left_type; - typedef typename Exp::right_type right_type; - do_bitwise_xor(e.left(), typename left_type::tag_type()); - do_bitwise_xor(e.right(), typename right_type::tag_type()); - } - template - void do_bitwise_xor(const Exp& e, const unknown&) - { - using big_num_default_ops::bitwise_xor; - self_type temp(e); - bitwise_xor(m_backend, temp.m_backend); - } - - // Tests if the expression contains a reference to *this: - template - bool contains_self(const Exp& e)const - { - return contains_self(e, typename Exp::arity()); - } - template - bool contains_self(const Exp& e, mpl::int_<0> const&)const - { - return is_really_self(e.value()); - } - template - bool contains_self(const Exp& e, mpl::int_<1> const&)const - { - typedef typename Exp::left_type child_type; - return contains_self(e.left(), typename child_type::arity()); - } - template - bool contains_self(const Exp& e, mpl::int_<2> const&)const - { - typedef typename Exp::left_type child0_type; - typedef typename Exp::right_type child1_type; - return contains_self(e.left(), typename child0_type::arity()) - || contains_self(e.right(), typename child1_type::arity()); - } - template - bool contains_self(const Exp& e, mpl::int_<3> const&)const - { - typedef typename Exp::left_type child0_type; - typedef typename Exp::middle_type child1_type; - typedef typename Exp::right_type child2_type; - return contains_self(e.left(), typename child0_type::arity()) - || contains_self(e.middle(), typename child1_type::arity()) - || contains_self(e.right(), typename child2_type::arity()); - } - - // Test if the expression is a reference to *this: - template - bool is_self(const Exp& e)const - { - return is_self(e, typename Exp::arity()); - } - template - bool is_self(const Exp& e, mpl::int_<0> const&)const - { - return is_really_self(e.value()); - } - template - bool is_self(const Exp& e, mpl::int_ const&)const - { - return false; - } - - template - bool is_really_self(const Val&)const { return false; } - bool is_really_self(const self_type& v)const { return &v == this; } - - static const Backend& canonical_value(const self_type& v){ return v.m_backend; } - //static const Backend& canonical_value(const self_type* v){ return v->m_backend; } - //static const Backend& canonical_value(self_type* v){ return v->m_backend; } - //static const Backend& canonical_value(self_type& v){ return v.m_backend; } - template - static typename detail::canonical::type canonical_value(const V& v){ return v; } - static typename detail::canonical::type canonical_value(const std::string& v){ return v.c_str(); } - Backend m_backend; -}; - -namespace detail -{ - -template -inline int big_number_compare(const big_number& a, const big_number& b) -{ - return a.compare(b); -} - -template -inline int big_number_compare(const big_number& a, const big_number_exp& b) -{ - return a.compare(big_number(b)); -} - -template -inline int big_number_compare(const big_number_exp& a, const big_number& b) -{ - return -b.compare(big_number(a)); -} - -template -inline int big_number_compare(const big_number& a, const Val b) -{ - return a.compare(b); -} - -template -inline int big_number_compare(const Val a, const big_number& b) -{ - return -b.compare(a); -} - -template -inline int big_number_compare(const big_number_exp& a, const big_number_exp& b) -{ - typedef typename big_number_exp::result_type real1; - typedef typename big_number_exp::result_type real2; - return real1(a).compare(real2(b)); -} - -template -inline typename enable_if, int>::type big_number_compare(const big_number_exp& a, const Val b) -{ - typedef typename big_number_exp::result_type real; - real t(a); - return t.compare(b); -} - -template -inline typename enable_if, int>::type big_number_compare(const Val a, const big_number_exp& b) -{ - typedef typename big_number_exp::result_type real; - return -real(b).compare(a); -} - -template -struct is_valid_comparison_imp -{ - typedef typename mpl::or_< - is_big_number, - is_big_number_exp - >::type is1; - typedef typename mpl::or_< - is_big_number, - is_big_number_exp - >::type is2; - typedef typename mpl::or_< - mpl::and_< - is1, - mpl::or_< - is2, - is_arithmetic - > - >, - mpl::and_< - is2, - mpl::or_< - is1, - is_arithmetic - > - > - >::type type; -}; - -template -struct is_valid_comparison : public boost::math::detail::is_valid_comparison_imp::type {}; - -} - - -template -inline typename boost::enable_if, bool>::type - operator == (const Exp1& a, const Exp2& b) -{ - return 0 == detail::big_number_compare(a, b); -} - -template -inline typename boost::enable_if, bool>::type - operator != (const Exp1& a, const Exp2& b) -{ - return 0 != detail::big_number_compare(a, b); -} - -template -inline typename boost::enable_if, bool>::type - operator <= (const Exp1& a, const Exp2& b) -{ - return 0 >= detail::big_number_compare(a, b); -} - -template -inline typename boost::enable_if, bool>::type - operator < (const Exp1& a, const Exp2& b) -{ - return 0 > detail::big_number_compare(a, b); -} - -template -inline typename boost::enable_if, bool>::type - operator >= (const Exp1& a, const Exp2& b) -{ - return 0 <= detail::big_number_compare(a, b); -} - -template -inline typename boost::enable_if, bool>::type - operator > (const Exp1& a, const Exp2& b) -{ - return 0 < detail::big_number_compare(a, b); -} - -template -inline std::ostream& operator << (std::ostream& os, const big_number& r) -{ - return os << r.str(static_cast(os.precision(), os.flags() & os.scientific)); -} - -namespace detail{ - -template -inline std::ostream& operator << (std::ostream& os, const big_number_exp& r) -{ - typedef typename big_number_exp::result_type value_type; - value_type temp(r); - return os << temp; -} - -} // namespace detail - -template -inline std::istream& operator >> (std::istream& is, big_number& r) -{ - std::string s; - is >> s; - r = s; - return is; -} - -}} // namespaces - -#endif diff --git a/include/boost/math/big_number/arithmetic_backend.hpp b/include/boost/math/big_number/arithmetic_backend.hpp deleted file mode 100644 index ba8d7165..00000000 --- a/include/boost/math/big_number/arithmetic_backend.hpp +++ /dev/null @@ -1,147 +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_ - -#ifndef BOOST_MATH_ARITH_BACKEND_HPP -#define BOOST_MATH_ARITH_BACKEND_HPP - -#include -#include -#include -#include -#include - -namespace boost{ -namespace math{ - -template -struct arithmetic_backend -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - arithmetic_backend(){} - arithmetic_backend(const arithmetic_backend& o) - { - m_value = o.m_value; - } - arithmetic_backend(const Arithmetic& o) : m_value(o) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - arithmetic_backend(arithmetic_backend&& o) : m_value(o.m_value) {} - arithmetic_backend(Arithmetic&& o) : m_value(o) {} -#endif - arithmetic_backend& operator = (const arithmetic_backend& o) - { - m_value = o.m_value; - return *this; - } - arithmetic_backend& operator = (boost::uintmax_t i) - { - m_value = i; - return *this; - } - arithmetic_backend& operator = (boost::intmax_t i) - { - m_value = i; - return *this; - } - arithmetic_backend& operator = (long double d) - { - m_value = d; - return *this; - } - arithmetic_backend& operator = (const char* s) - { - m_value = boost::lexical_cast(s); - return *this; - } - void swap(arithmetic_backend& o) - { - std::swap(m_value, o.m_value); - } - std::string str(unsigned digits, bool scientific)const - { - return boost::lexical_cast(m_value); - } - void negate() - { - m_value = -m_value; - } - int compare(const arithmetic_backend& o)const - { - return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0); - } - int compare(boost::intmax_t i)const - { - return m_value > i ? 1 : (m_value < i ? -1 : 0); - } - int compare(boost::uintmax_t i)const - { - return m_value > i ? 1 : (m_value < i ? -1 : 0); - } - int compare(long double d)const - { - return m_value > d ? 1 : (m_value < d ? -1 : 0); - } - Arithmetic& data() { return m_value; } - const Arithmetic& data()const { return m_value; } -private: - Arithmetic m_value; -}; - -template -inline void add(arithmetic_backend& result, const arithmetic_backend& o) -{ - result.data() += o.data(); -} -template -inline void subtract(arithmetic_backend& result, const arithmetic_backend& o) -{ - result.data() -= o.data(); -} -template -inline void multiply(arithmetic_backend& result, const arithmetic_backend& o) -{ - result.data() *= o.data(); -} -template -inline void divide(arithmetic_backend& result, const arithmetic_backend& o) -{ - result.data() /= o.data(); -} - -}} // namespaces - - -namespace std{ - -#ifdef BOOST_NO_NOEXCEPT -# define noexcept -#endif - -template -class numeric_limits > > : public std::numeric_limits -{ - typedef std::numeric_limits base_type; - typedef boost::math::big_number > number_type; -public: - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept { return (base_type::min)(); } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept { return (base_type::max)(); } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept { return -(max)(); } - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept { return base_type::epsilon(); } - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept { return epsilon() / 2; } - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return base_type::infinity(); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return base_type::quiet_NaN(); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return base_type::signaling_NaN(); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return base_type::denorm_min(); } -}; - -#ifdef BOOST_NO_NOEXCEPT -# undef noexcept -#endif - -} - -#endif diff --git a/include/boost/math/big_number/big_number_base.hpp b/include/boost/math/big_number/big_number_base.hpp deleted file mode 100644 index 8eef7048..00000000 --- a/include/boost/math/big_number/big_number_base.hpp +++ /dev/null @@ -1,983 +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_0.txt) - -#ifndef BOOST_MATH_BIG_NUM_BASE_HPP -#define BOOST_MATH_BIG_NUM_BASE_HPP - -#include -#include -#include - -namespace boost{ namespace math{ - -template -class big_number; - -namespace detail{ - -// Forward-declare an expression wrapper -template -struct big_number_exp; - -template -struct has_enough_bits -{ - template - struct type : public mpl::bool_::digits >= b>{}; -}; - -template -struct canonical_imp -{ - typedef Val type; -}; -template -struct canonical_imp > -{ - typedef typename has_enough_bits::digits>::template type pred_type; - typedef typename mpl::find_if< - typename Backend::signed_types, - pred_type - >::type iter_type; - typedef typename mpl::deref::type type; -}; -template -struct canonical_imp > -{ - typedef typename has_enough_bits::digits>::template type pred_type; - typedef typename mpl::find_if< - typename Backend::unsigned_types, - pred_type - >::type iter_type; - typedef typename mpl::deref::type type; -}; -template -struct canonical_imp > -{ - typedef typename has_enough_bits::digits>::template type pred_type; - typedef typename mpl::find_if< - typename Backend::real_types, - pred_type - >::type iter_type; - typedef typename mpl::deref::type type; -}; -template -struct canonical_imp > -{ - typedef const char* type; -}; - -template -struct canonical -{ - typedef typename mpl::if_< - is_signed, - mpl::int_<0>, - typename mpl::if_< - is_unsigned, - mpl::int_<1>, - typename mpl::if_< - is_floating_point, - mpl::int_<2>, - typename mpl::if_< - mpl::or_< - is_convertible, - is_same - >, - mpl::int_<3>, - mpl::int_<4> - >::type - >::type - >::type - >::type tag_type; - - typedef typename canonical_imp::type type; -}; - -struct terminal{}; -struct negate{}; -struct plus{}; -struct minus{}; -struct multiplies{}; -struct divides{}; -struct modulus{}; -struct shift_left{}; -struct shift_right{}; -struct bitwise_and{}; -struct bitwise_or{}; -struct bitwise_xor{}; -struct bitwise_complement{}; -struct add_immediates{}; -struct subtract_immediates{}; -struct multiply_immediates{}; -struct divide_immediates{}; -struct modulus_immediates{}; -struct bitwise_and_immediates{}; -struct bitwise_or_immediates{}; -struct bitwise_xor_immediates{}; -struct complement_immediates{}; -struct function{}; - -template -struct backend_type; - -template -struct backend_type > -{ - typedef T type; -}; - -template -struct backend_type > -{ - typedef typename backend_type::result_type>::type type; -}; - - -template -struct is_big_number : public mpl::false_{}; -template -struct is_big_number > : public mpl::true_{}; -template -struct is_big_number_exp : public mpl::false_{}; -template -struct is_big_number_exp > : public mpl::true_{}; - -template -struct combine_expression; - -template -struct combine_expression, T2> -{ - typedef big_number type; -}; - -template -struct combine_expression > -{ - typedef big_number type; -}; - -template -struct combine_expression, big_number > -{ - typedef big_number type; -}; - -template -struct arg_type -{ - typedef big_number_exp type; -}; - -template -struct arg_type > -{ - typedef big_number_exp type; -}; - -template -struct unmentionable -{ - static void proc(){} -}; - -typedef void (*unmentionable_type)(); - -template -struct big_number_exp_storage -{ - typedef const T& type; -}; - -template -struct big_number_exp_storage -{ - typedef T* type; -}; - -template -struct big_number_exp_storage -{ - typedef const T* type; -}; - -template -struct big_number_exp_storage > -{ - typedef big_number_exp type; -}; - -template -struct big_number_exp -{ - typedef mpl::int_<1> arity; - typedef typename arg_type::type left_type; - typedef typename left_type::result_type result_type; - typedef tag tag_type; - - big_number_exp(const Arg1& a) : arg(a) {} - - left_type left()const { return arg; } - - const Arg1& left_ref()const{ return arg; } - - static const unsigned depth = left_type::depth + 1; - - operator unmentionable_type()const - { - result_type r(*this); - return r ? &unmentionable::proc : 0; - } - -private: - typename big_number_exp_storage::type arg; -}; - -template -struct big_number_exp -{ - typedef mpl::int_<0> arity; - typedef Arg1 result_type; - typedef terminal tag_type; - - big_number_exp(const Arg1& a) : arg(a) {} - - const Arg1& value()const { return arg; } - - static const unsigned depth = 0; - - operator unmentionable_type()const - { - return arg ? &unmentionable::proc : 0; - } - -private: - typename big_number_exp_storage::type arg; -}; - -template -struct big_number_exp -{ - typedef mpl::int_<2> arity; - typedef typename arg_type::type left_type; - typedef typename arg_type::type right_type; - typedef typename left_type::result_type left_result_type; - typedef typename right_type::result_type right_result_type; - typedef typename combine_expression::type result_type; - typedef tag tag_type; - - big_number_exp(const Arg1& a1, const Arg2& a2) : arg1(a1), arg2(a2) {} - - left_type left()const { return arg1; } - right_type right()const { return arg2; } - const Arg1& left_ref()const{ return arg1; } - const Arg2& right_ref()const{ return arg2; } - - operator unmentionable_type()const - { - result_type r(*this); - return r ? &unmentionable::proc : 0; - } - - static const unsigned left_depth = left_type::depth + 1; - static const unsigned right_depth = right_type::depth + 1; - static const unsigned depth = left_depth > right_depth ? left_depth : right_depth; -private: - typename big_number_exp_storage::type arg1; - typename big_number_exp_storage::type arg2; -}; - -template -struct big_number_exp -{ - typedef mpl::int_<3> arity; - typedef typename arg_type::type left_type; - typedef typename arg_type::type middle_type; - typedef typename arg_type::type right_type; - typedef typename left_type::result_type left_result_type; - typedef typename middle_type::result_type middle_result_type; - typedef typename right_type::result_type right_result_type; - typedef typename combine_expression< - left_result_type, - typename combine_expression::type - >::type result_type; - typedef tag tag_type; - - big_number_exp(const Arg1& a1, const Arg2& a2, const Arg3& a3) : arg1(a1), arg2(a2), arg3(a3) {} - - left_type left()const { return arg1; } - middle_type middle()const { return arg2; } - right_type right()const { return arg3; } - const Arg1& left_ref()const{ return arg1; } - const Arg2& middle_ref()const{ return arg2; } - const Arg3& right_ref()const{ return arg3; } - - operator unmentionable_type()const - { - result_type r(*this); - return r ? &unmentionable::proc : 0; - } - - static const unsigned left_depth = left_type::depth + 1; - static const unsigned middle_depth = middle_type::depth + 1; - static const unsigned right_depth = right_type::depth + 1; - static const unsigned depth = left_depth > right_depth ? (left_depth > middle_depth ? left_depth : middle_depth) : (right_depth > middle_depth ? right_depth : middle_depth); -private: - typename big_number_exp_storage::type arg1; - typename big_number_exp_storage::type arg2; - typename big_number_exp_storage::type arg3; -}; - -} // namespace detail - -// -// Non-member operators for big_number: -// -// Unary operators first: -// -template -inline const big_number& operator + (const big_number& v) { return v; } -template -inline const detail::big_number_exp& operator + (const detail::big_number_exp& v) { return v; } -template -inline detail::big_number_exp > operator - (const big_number& v) { return v; } -template -inline detail::big_number_exp > operator - (const detail::big_number_exp& v) { return v; } -template -inline detail::big_number_exp > operator ~ (const big_number& v) { return v; } -template -inline detail::big_number_exp > operator ~ (const detail::big_number_exp& v) { return v; } -// -// Then addition: -// -template -inline detail::big_number_exp, big_number > - operator + (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator + (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator + (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator + (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator + (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator + (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator + (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator + (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Repeat operator for negated arguments: propagate the negation to the top level to avoid temporaries: -// -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > - operator + (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(a, b.left_ref()); -} -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > - operator + (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(b, a.left_ref()); -} -template -inline detail::big_number_exp, big_number > - operator + (const big_number& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, big_number >(a, b.left_ref()); -} -template -inline detail::big_number_exp, big_number > - operator + (const detail::big_number_exp >& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(b, a.left_ref()); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator + (const detail::big_number_exp >& a, const V& b) -{ - return detail::big_number_exp >(b, a.left_ref()); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator + (const V& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, big_number >(a, b.left_ref()); -} -// -// Subtraction: -// -template -inline detail::big_number_exp, big_number > - operator - (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator - (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator - (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator - (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator - (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator - (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator - (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator - (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Repeat operator for negated arguments: propagate the negation to the top level to avoid temporaries: -// -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > - operator - (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(a, b.left_ref()); -} -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > > - operator - (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(b, a.left_ref()); -} -template -inline detail::big_number_exp, big_number > - operator - (const big_number& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, big_number >(a, b.left_ref()); -} -template -inline detail::big_number_exp, big_number > > - operator - (const detail::big_number_exp >& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(b, a.left_ref()); -} -template -inline typename enable_if, detail::big_number_exp, V > > >::type - operator - (const detail::big_number_exp >& a, const V& b) -{ - return detail::big_number_exp >(b, a.left_ref()); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator - (const V& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp >(a, b.left_ref()); -} -// -// Multiplication: -// -template -inline detail::big_number_exp, big_number > - operator * (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator * (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator * (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator * (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator * (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator * (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator * (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator * (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Repeat operator for negated arguments: propagate the negation to the top level to avoid temporaries: -// -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > > - operator * (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type > (a, b.left_ref()); -} -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > > - operator * (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(b, a.left_ref()); -} -template -inline detail::big_number_exp, big_number > > - operator * (const big_number& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, big_number >(a, b.left_ref()); -} -template -inline detail::big_number_exp, big_number > > - operator * (const detail::big_number_exp >& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(b, a.left_ref()); -} -template -inline typename enable_if, detail::big_number_exp, V > > >::type - operator * (const detail::big_number_exp >& a, const V& b) -{ - return detail::big_number_exp, V >(a.left_ref(), b); -} -template -inline typename enable_if, detail::big_number_exp, V > > >::type - operator * (const V& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, V >(b.left_ref(), a); -} -// -// Division: -// -template -inline detail::big_number_exp, big_number > - operator / (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator / (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator / (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator / (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator / (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator / (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator / (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator / (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Repeat operator for negated arguments: propagate the negation to the top level to avoid temporaries: -// -template -inline detail::big_number_exp, typename detail::big_number_exp::left_type > > - operator / (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, typename detail::big_number_exp::left_type >(a, b.left_ref()); -} -template -inline detail::big_number_exp::left_type, big_number > > - operator / (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp::left_type, big_number >(a.left_ref(), b); -} -template -inline detail::big_number_exp, big_number > > - operator / (const big_number& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp, big_number >(a, b.left_ref()); -} -template -inline detail::big_number_exp, big_number > > - operator / (const detail::big_number_exp >& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a.left_ref(), b); -} -template -inline typename enable_if, detail::big_number_exp, V > > >::type - operator / (const detail::big_number_exp >& a, const V& b) -{ - return detail::big_number_exp, V>(a.left_ref(), b); -} -template -inline typename enable_if, detail::big_number_exp > > >::type - operator / (const V& a, const detail::big_number_exp >& b) -{ - return detail::big_number_exp >(a, b.left_ref()); -} -// -// Modulus: -// -template -inline detail::big_number_exp, big_number > - operator % (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator % (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator % (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator % (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator % (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator % (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator % (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator % (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Left shift: -// -template -inline typename enable_if, detail::big_number_exp, I > >::type - operator << (const big_number& a, const I& b) -{ - return detail::big_number_exp, I>(a, b); -} -template -inline typename enable_if, detail::big_number_exp, I> >::type - operator << (const detail::big_number_exp& a, const I& b) -{ - return detail::big_number_exp, I>(a, b); -} -// -// Right shift: -// -template -inline typename enable_if, detail::big_number_exp, I > >::type - operator >> (const big_number& a, const I& b) -{ - return detail::big_number_exp, I>(a, b); -} -template -inline typename enable_if, detail::big_number_exp, I> >::type - operator >> (const detail::big_number_exp& a, const I& b) -{ - return detail::big_number_exp, I>(a, b); -} -// -// Bitwise AND: -// -template -inline detail::big_number_exp, big_number > - operator & (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator & (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator & (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator & (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator & (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator & (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator & (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator & (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Bitwise OR: -// -template -inline detail::big_number_exp, big_number > - operator| (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator| (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator| (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator| (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator| (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator| (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator| (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator| (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} -// -// Bitwise XOR: -// -template -inline detail::big_number_exp, big_number > - operator^ (const big_number& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator^ (const big_number& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator^ (const V& a, const big_number& b) -{ - return detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator^ (const big_number& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline detail::big_number_exp, big_number > - operator^ (const detail::big_number_exp& a, const big_number& b) -{ - return detail::big_number_exp, big_number >(a, b); -} -template -inline detail::big_number_exp, detail::big_number_exp > - operator^ (const detail::big_number_exp& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp, detail::big_number_exp >(a, b); -} -template -inline typename enable_if, detail::big_number_exp, V > >::type - operator^ (const detail::big_number_exp& a, const V& b) -{ - return detail::big_number_exp, V >(a, b); -} -template -inline typename enable_if, detail::big_number_exp > >::type - operator^ (const V& a, const detail::big_number_exp& b) -{ - return detail::big_number_exp >(a, b); -} - -// -// Traits class, lets us know what kind of number we have, defaults to a floating point type: -// -enum number_category_type -{ - number_kind_integer = 0, - number_kind_floating_point = 1, - number_kind_rational = 2, - number_kind_fixed_point = 3 -}; - -template -struct number_category : public mpl::int_ {}; -template -struct number_category > : public number_category{}; -template -struct number_category > : public number_category::result_type>{}; - -}} // namespaces - -namespace boost{ namespace math{ namespace tools{ - -template -struct promote_arg; - -template -struct promote_arg > -{ - typedef typename boost::math::detail::big_number_exp::result_type type; -}; - -}}} - -#endif // BOOST_MATH_BIG_NUM_BASE_HPP - - diff --git a/include/boost/math/big_number/default_ops.hpp b/include/boost/math/big_number/default_ops.hpp deleted file mode 100644 index ea034e00..00000000 --- a/include/boost/math/big_number/default_ops.hpp +++ /dev/null @@ -1,903 +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_0.txt) - -#ifndef BOOST_MATH_BIG_NUM_DEF_OPS -#define BOOST_MATH_BIG_NUM_DEF_OPS - -#include -#include -#include -#include -#include -#include - -namespace boost{ namespace math{ namespace big_num_default_ops{ - -// -// Default versions of mixed arithmetic, these just construct a temporary -// from the arithmetic value and then do the arithmetic on that: -// -template -inline typename enable_if, is_convertible, is_same > >::type - add(T& result, V const& v) -{ - T t; - t = v; - add(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - subtract(T& result, V const& v) -{ - T t; - t = v; - subtract(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - multiply(T& result, V const& v) -{ - T t; - t = v; - multiply(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - divide(T& result, V const& v) -{ - T t; - t = v; - divide(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - modulus(T& result, V const& v) -{ - T t; - t = v; - modulus(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - bitwise_and(T& result, V const& v) -{ - T t; - t = v; - bitwise_and(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - bitwise_or(T& result, V const& v) -{ - T t; - t = v; - bitwise_or(result, t); -} -template -inline typename enable_if, is_convertible, is_same > >::type - bitwise_xor(T& result, V const& v) -{ - T t; - t = v; - bitwise_xor(result, t); -} - -template -inline typename enable_if, is_convertible, is_same > >::type - complement(T& result, V const& v) -{ - T t; - t = v; - complement(result, t); -} - -template -inline bool is_same_object(const T& u, const T&v) -{ return &u == &v; } -template -inline bool is_same_object(const T& u, const U&v) -{ return false; } - -// -// Default versions of 3-arg arithmetic functions, these just forward to the 2 arg versions: -// -template -inline void add(T& t, const U& u, const V& v) -{ - if(is_same_object(t, v)) - { - add(t, u); - } - else if(is_same_object(t, u)) - { - add(t, v); - } - else - { - t = u; - add(t, v); - } -} -template -inline void subtract(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - subtract(t, v); - else if(is_same_object(t, v)) - { - subtract(t, u); - t.negate(); - } - else - { - t = u; - subtract(t, v); - } -} -template -inline void multiply(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - multiply(t, v); - else if(is_same_object(t, v)) - multiply(t, u); - else - { - t = u; - multiply(t, v); - } -} -template -inline void divide(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - divide(t, v); - else if(is_same_object(t, v)) - { - T temp = t; - divide(temp, u, v); - temp.swap(t); - } - else - { - t = u; - divide(t, v); - } -} -template -inline void modulus(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - modulus(t, v); - else if(is_same_object(t, v)) - { - T temp; - modulus(temp, u, v); - temp.swap(t); - } - else - { - t = u; - modulus(t, v); - } -} -template -inline void bitwise_and(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - bitwise_and(t, v); - else if(is_same_object(t, v)) - bitwise_and(t, u); - else - { - t = u; - bitwise_and(t, v); - } -} - -template -inline void bitwise_or(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - bitwise_or(t, v); - else if(is_same_object(t, v)) - bitwise_or(t, u); - else - { - t = u; - bitwise_or(t, v); - } -} - -template -inline void bitwise_xor(T& t, const U& u, const V& v) -{ - if(is_same_object(t, u)) - bitwise_xor(t, v); - else if(is_same_object(t, v)) - bitwise_xor(t, u); - else - { - t = u; - bitwise_xor(t, v); - } -} - -template -inline void increment(T& val) -{ - typedef typename mpl::front::type ui_type; - add(val, static_cast(1u)); -} - -template -inline void decrement(T& val) -{ - typedef typename mpl::front::type ui_type; - subtract(val, static_cast(1u)); -} - -template -inline void left_shift(T& result, const T& arg, const V val) -{ - result = arg; - left_shift(result, val); -} - -template -inline void right_shift(T& result, const T& arg, const V val) -{ - result = arg; - right_shift(result, val); -} - -template -inline bool is_zero(const T& val) -{ - typedef typename mpl::front::type ui_type; - return val.compare(static_cast(0)) == 0; -} -template -inline int get_sign(const T& val) -{ - typedef typename mpl::front::type ui_type; - return val.compare(static_cast(0)); -} - -template -struct has_enough_bits -{ - template - struct type : public mpl::and_ >, mpl::bool_::digits >= b> >{}; -}; - -template -struct terminal -{ - terminal(const R& v) : value(v){} - terminal(){} - terminal& operator = (R val) { value = val; } - R value; - operator R()const { return value; } -}; - -template -struct calculate_next_larger_type -{ - typedef typename mpl::if_< - is_signed, - typename B::signed_types, - typename mpl::if_< - is_unsigned, - typename B::unsigned_types, - typename B::real_types - >::type - >::type list_type; - typedef typename has_enough_bits::digits>::template type pred_type; - typedef typename mpl::find_if< - list_type, - pred_type - >::type iter_type; - typedef typename mpl::eval_if< - is_same::type, iter_type>, - mpl::identity >, - mpl::deref - >::type type; -}; - -template -inline void convert_to(R* result, const B& backend) -{ - typedef typename calculate_next_larger_type::type next_type; - next_type n; - convert_to(&n, backend); - *result = static_cast(n); -} - -template -inline void convert_to(terminal* result, const B& backend) -{ - // - // We ran out of types to try for the convertion, try - // a lexical_cast and hope for the best: - // - result->value = boost::lexical_cast(backend.str(0, false)); -} - -// -// Functions: -// -template -void eval_abs(T& result, const T& arg) -{ - typedef typename T::signed_types type_list; - typedef typename mpl::front::type front; - *result = arg; - if(arg.compare(front(0)) < 0) - result->negate(); -} -template -void eval_fabs(T& result, const T& arg) -{ - typedef typename T::signed_types type_list; - typedef typename mpl::front::type front; - *result = arg; - if(arg.compare(front(0)) < 0) - result->negate(); -} - -template -inline int eval_fpclassify(const Backend& arg) -{ - return is_zero(arg) ? FP_ZERO : FP_NORMAL; -} - -template -inline void eval_fmod(T& result, const T& a, const T& b) -{ - if((&result == &a) || (&result == &b)) - { - T temp; - eval_fmod(temp, a, b); - result = temp; - } - T n; - divide(result, a, b); - if(get_sign(a) < 0) - eval_ceil(n, result); - else - eval_floor(n, result); - multiply(n, b); - subtract(result, a, n); -} - -// -// These have to implemented by the backend, declared here so that our macro generated code compiles OK. -// -template -typename enable_if_c::type eval_floor(); -template -typename enable_if_c::type eval_ceil(); -template -typename enable_if_c::type eval_trunc(); -template -typename enable_if_c::type eval_sqrt(); -template -typename enable_if_c::type eval_ldexp(); -template -typename enable_if_c::type eval_frexp(); -// -// TODO: implement default versions of these: -// -template -typename enable_if_c::type eval_exp(); -template -typename enable_if_c::type eval_log(); -template -typename enable_if_c::type eval_sin(); -template -typename enable_if_c::type eval_cos(); -template -typename enable_if_c::type eval_tan(); -template -typename enable_if_c::type eval_asin(); -template -typename enable_if_c::type eval_acos(); -template -typename enable_if_c::type eval_atan(); -template -typename enable_if_c::type eval_sinh(); -template -typename enable_if_c::type eval_cosh(); -template -typename enable_if_c::type eval_tanh(); -// -// These functions are implemented in separate files, but expanded inline here: -// -#include - -} - -template -class big_number; - -// -// Default versions of floating point classification routines: -// -template -inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const big_number& arg) -{ - using big_num_default_ops::eval_fpclassify; - return eval_fpclassify(arg.backend()); -} -template -inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::big_number_exp& arg) -{ - typedef typename detail::big_number_exp::result_type value_type; - return fpclassify(value_type(arg)); -} -template -inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const big_number& arg) -{ - int v = fpclassify(arg); - return (v != FP_INFINITE) && (v != FP_NAN); -} -template -inline bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::big_number_exp& arg) -{ - typedef typename detail::big_number_exp::result_type value_type; - return isfinite(value_type(arg)); -} -template -inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const big_number& arg) -{ - return fpclassify(arg) == FP_NAN; -} -template -inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::big_number_exp& arg) -{ - typedef typename detail::big_number_exp::result_type value_type; - return isnan(value_type(arg)); -} -template -inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const big_number& arg) -{ - return fpclassify(arg) == FP_INFINITE; -} -template -inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::big_number_exp& arg) -{ - typedef typename detail::big_number_exp::result_type value_type; - return isinf(value_type(arg)); -} -template -inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const big_number& arg) -{ - return fpclassify(arg) == FP_NORMAL; -} -template -inline bool isnormal BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::big_number_exp& arg) -{ - typedef typename detail::big_number_exp::result_type value_type; - return isnormal(value_type(arg)); -} - -template -inline int itrunc(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_type number_type; - number_type r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, v, 0, pol).template convert_to(); - return r.template convert_to(); -} -template -inline int itrunc(const big_number& v, const Policy& pol) -{ - big_number r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, v, 0, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long ltrunc(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_result number_type; - number_type r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, v, 0L, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long ltrunc(const big_number& v, const Policy& pol) -{ - big_number r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, v, 0L, pol).template convert_to(); - return r.template convert_to(); -} -#ifndef BOOST_NO_LONG_LONG -template -inline long long lltrunc(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_result number_type; - number_type r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, 0LL, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long long lltrunc(const big_number& v, const Policy& pol) -{ - big_number r = trunc(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, 0LL, pol).template convert_to(); - return r.template convert_to(); -} -#endif -template -inline int iround(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_result number_type; - number_type r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol).template convert_to(); - return r.template convert_to(); -} -template -inline int iround(const big_number& v, const Policy& pol) -{ - big_number r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long lround(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_result number_type; - number_type r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, 0L, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long lround(const big_number& v, const Policy& pol) -{ - big_number r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, 0L, pol).template convert_to(); - return r.template convert_to(); -} -#ifndef BOOST_NO_LONG_LONG -template -inline long long llround(const detail::big_number_exp& v, const Policy& pol) -{ - typedef typename detail::big_number_exp::result_result number_type; - number_type r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0LL, pol).template convert_to(); - return r.template convert_to(); -} -template -inline long long llround(const big_number& v, const Policy& pol) -{ - big_number r = round(v, pol); - if(fabs(r) > (std::numeric_limits::max)()) - return policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0LL, pol).template convert_to(); - return r.template convert_to(); -} -#endif -// -// Overload of Boost.Math functions that find the wrong overload when used with big_number: -// -namespace detail{ - template T sinc_pi_imp(T); - template T sinhc_pi_imp(T); -} -template -inline big_number sinc_pi(const big_number& x) -{ - return detail::sinc_pi_imp(x); -} - -template -inline big_number sinc_pi(const big_number& x, const Policy&) -{ - return detail::sinc_pi_imp(x); -} - -template -inline big_number sinhc_pi(const big_number& x) -{ - return detail::sinhc_pi_imp(x); -} - -template -inline big_number sinhc_pi(const big_number& x, const Policy&) -{ - return boost::math::sinhc_pi(x); -} - -#define UNARY_OP_FUNCTOR(func)\ -namespace detail{\ -template \ -struct BOOST_JOIN(func, _funct)\ -{\ - void operator()(Backend& result, const Backend& arg)const\ - {\ - using big_num_default_ops::BOOST_JOIN(eval_,func);\ - BOOST_JOIN(eval_,func)(result, arg);\ - }\ -};\ -\ -}\ -\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ -> \ -func(const detail::big_number_exp& arg)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ -> (\ - detail::BOOST_JOIN(func, _funct) >::type>() \ - , arg \ - );\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ -> \ -func(const big_number& arg)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg \ - );\ -} - -#define BINARY_OP_FUNCTOR(func)\ -namespace detail{\ -template \ -struct BOOST_JOIN(func, _funct)\ -{\ - void operator()(Backend& result, const Backend& arg, const Backend& a)const\ - {\ - using big_num_default_ops:: BOOST_JOIN(eval_,func);\ - BOOST_JOIN(eval_,func)(result, arg, a);\ - }\ - template \ - void operator()(Backend& result, const Backend& arg, const Arithmetic& a)const\ - {\ - using big_num_default_ops:: BOOST_JOIN(eval_,func);\ - BOOST_JOIN(eval_,func)(result, arg, a);\ - }\ -};\ -\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , big_number \ -> \ -func(const big_number& arg, const big_number& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , big_number \ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg,\ - a\ - );\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , detail::big_number_exp \ -> \ -func(const big_number& arg, const detail::big_number_exp& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , detail::big_number_exp \ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg,\ - a\ - );\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , detail::big_number_exp \ - , big_number \ -> \ -func(const detail::big_number_exp& arg, const big_number& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , detail::big_number_exp \ - , big_number \ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg,\ - a\ - );\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , detail::big_number_exp \ -> \ -func(const detail::big_number_exp& arg, const detail::big_number_exp& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , detail::big_number_exp \ - >(\ - detail::BOOST_JOIN(func, _funct) >::type>() \ - , arg,\ - a\ - );\ -}\ -template \ -typename enable_if<\ - is_arithmetic,\ - detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , Arithmetic\ - > \ ->::type \ -func(const big_number& arg, const Arithmetic& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , Arithmetic\ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg,\ - a\ - );\ -}\ -template \ -typename enable_if<\ - is_arithmetic,\ - detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , Arithmetic\ - > \ ->::type \ -func(const detail::big_number_exp& arg, const Arithmetic& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , Arithmetic\ - >(\ - detail::BOOST_JOIN(func, _funct) >::type>() \ - , arg,\ - a\ - );\ -}\ - - -#define HETERO_BINARY_OP_FUNCTOR(func, Arg2)\ -namespace detail{\ -template \ -struct BOOST_JOIN(func, _funct)\ -{\ - void operator()(Backend& result, Backend const& arg, Arg2 a)const\ - {\ - using big_num_default_ops:: BOOST_JOIN(eval_,func);\ - BOOST_JOIN(eval_,func)(result, arg, a);\ - }\ -};\ -\ -}\ -\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , Arg2\ -> \ -func(const detail::big_number_exp& arg, Arg2 const& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) >::type> \ - , detail::big_number_exp \ - , Arg2\ - >(\ - detail::BOOST_JOIN(func, _funct) >::type>() \ - , arg, a \ - );\ -}\ -template \ -detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , Arg2\ -> \ -func(const big_number& arg, Arg2 const& a)\ -{\ - return detail::big_number_exp<\ - detail::function\ - , detail::BOOST_JOIN(func, _funct) \ - , big_number \ - , Arg2\ - >(\ - detail::BOOST_JOIN(func, _funct)() \ - , arg,\ - a\ - );\ -}\ - -UNARY_OP_FUNCTOR(abs) -UNARY_OP_FUNCTOR(fabs) -UNARY_OP_FUNCTOR(sqrt) -UNARY_OP_FUNCTOR(floor) -UNARY_OP_FUNCTOR(ceil) -UNARY_OP_FUNCTOR(trunc) -UNARY_OP_FUNCTOR(exp) -UNARY_OP_FUNCTOR(log) -UNARY_OP_FUNCTOR(cos) -UNARY_OP_FUNCTOR(sin) -UNARY_OP_FUNCTOR(tan) -UNARY_OP_FUNCTOR(asin) -UNARY_OP_FUNCTOR(acos) -UNARY_OP_FUNCTOR(atan) -UNARY_OP_FUNCTOR(cosh) -UNARY_OP_FUNCTOR(sinh) -UNARY_OP_FUNCTOR(tanh) - -HETERO_BINARY_OP_FUNCTOR(ldexp, int) -HETERO_BINARY_OP_FUNCTOR(frexp, int*) -BINARY_OP_FUNCTOR(pow) -BINARY_OP_FUNCTOR(fmod) - -#undef BINARY_OP_FUNCTOR -#undef UNARY_OP_FUNCTOR - -}} // namespaces - -#endif - diff --git a/include/boost/math/big_number/e_float.hpp b/include/boost/math/big_number/e_float.hpp deleted file mode 100644 index 9ce737c4..00000000 --- a/include/boost/math/big_number/e_float.hpp +++ /dev/null @@ -1,80 +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_ - -#ifndef BOOST_MATH_EFX_BACKEND_HPP -#define BOOST_MATH_EFX_BACKEND_HPP - -#include -#include -#include -#include -#include - -namespace boost{ -namespace math{ - -typedef big_number > e_float; - -template<> -inline void arithmetic_backend::negate() -{ - m_value.negate(); -} -template<> -inline std::string arithmetic_backend::str(unsigned digits, bool scientific)const -{ - std::fstream os; - os << std::setprecision(digits ? digits : efx::e_float::ef_digits + 5); - if(scientific) - os << std::scientific; - std::string result; - this->data().wr_string(result, os); - return result; -} - -inline void eval_abs(arithmetic_backend& result, const arithmetic_backend& arg) -{ - result.data() = ef::fabs(arg.data()); -} - -inline void eval_fabs(arithmetic_backend& result, const arithmetic_backend& arg) -{ - result.data() = ef::fabs(arg.data()); -} - -inline bool is_zero(const arithmetic_backend& val) -{ - return val.data().iszero(); -} -inline int get_sign(const arithmetic_backend& val) -{ - return val.data().isneg() ? -1 : val.data().iszero() ? 0 : 1; -} - -inline void convert_to(boost::uintmax_t* result, const arithmetic_backend& val) -{ - *result = val.data().extract_unsigned_long_long(); -} -inline void convert_to(boost::intmax_t* result, const arithmetic_backend& val) -{ - *result = val.data().extract_signed_long_long(); -} -inline void convert_to(double* result, const arithmetic_backend& val) -{ - *result = val.data().extract_double(); -} -inline void convert_to(long double* result, const arithmetic_backend& val) -{ - *result = val.data().extract_long_double(); -} -inline int eval_fpclassify(const arithmetic_backend& val) -{ - return val.data().isinf() ? FP_INFINITE : val.data().isnan() ? FP_NAN : val.data().iszero() ? FP_ZERO : FP_NORMAL; -} - - -}} // namespaces - -#endif diff --git a/include/boost/math/big_number/gmp.hpp b/include/boost/math/big_number/gmp.hpp deleted file mode 100644 index 3ee95512..00000000 --- a/include/boost/math/big_number/gmp.hpp +++ /dev/null @@ -1,1532 +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_0.txt) - -#ifndef BOOST_MATH_ER_GMP_BACKEND_HPP -#define BOOST_MATH_ER_GMP_BACKEND_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost{ namespace math{ - -template -struct gmp_real; - -namespace detail{ - -template -struct gmp_real_imp -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - gmp_real_imp(){} - - gmp_real_imp(const gmp_real_imp& o) - { - // - // We have to do an init followed by a set here, otherwise *this may be at - // a lower precision than o: seems like mpf_init_set copies just enough bits - // to get the right value, but if it's then used in further calculations - // things go badly wrong!! - // - mpf_init2(m_data, (((digits10 ? digits10 : get_default_precision()) + 1) * 1000L) / 301L); - mpf_set(m_data, o.m_data); - } -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real_imp(gmp_real_imp&& o) - { - m_data[0] = o.m_data[0]; - o.m_data[0]._mp_d = 0; - } -#endif - gmp_real_imp& operator = (const gmp_real_imp& o) - { - mpf_set(m_data, o.m_data); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real_imp& operator = (gmp_real_imp&& o) - { - mpf_swap(m_data, o.m_data); - return *this; - } -#endif - gmp_real_imp& operator = (boost::uintmax_t i) - { - boost::uintmax_t mask = ((1uLL << std::numeric_limits::digits) - 1); - unsigned shift = 0; - mpf_t t; - mpf_init2(t, (((digits10 ? digits10 : get_default_precision()) + 1) * 1000L) / 301L); - mpf_set_ui(m_data, 0); - while(i) - { - mpf_set_ui(t, static_cast(i & mask)); - if(shift) - mpf_mul_2exp(t, t, shift); - mpf_add(m_data, m_data, t); - shift += std::numeric_limits::digits; - i >>= std::numeric_limits::digits; - } - mpf_clear(t); - return *this; - } - gmp_real_imp& operator = (boost::intmax_t i) - { - bool neg = i < 0; - *this = static_cast(std::abs(i)); - if(neg) - mpf_neg(m_data, m_data); - return *this; - } - gmp_real_imp& operator = (unsigned long i) - { - mpf_set_ui(m_data, i); - return *this; - } - gmp_real_imp& operator = (long i) - { - mpf_set_si(m_data, i); - return *this; - } - gmp_real_imp& operator = (double d) - { - mpf_set_d(m_data, d); - return *this; - } - gmp_real_imp& operator = (long double a) - { - using std::frexp; - using std::ldexp; - using std::floor; - - if (a == 0) { - mpf_set_si(m_data, 0); - return *this; - } - - if (a == 1) { - mpf_set_si(m_data, 1); - return *this; - } - - BOOST_ASSERT(!(boost::math::isinf)(a)); - BOOST_ASSERT(!(boost::math::isnan)(a)); - - int e; - long double f, term; - mpf_init_set_ui(m_data, 0u); - - f = frexp(a, &e); - - static const int shift = std::numeric_limits::digits - 1; - - while(f) - { - // extract int sized bits from f: - f = ldexp(f, shift); - term = floor(f); - e -= shift; - mpf_mul_2exp(m_data, m_data, shift); - if(term > 0) - mpf_add_ui(m_data, m_data, static_cast(term)); - else - mpf_sub_ui(m_data, m_data, static_cast(-term)); - f -= term; - } - if(e > 0) - mpf_mul_2exp(m_data, m_data, e); - else if(e < 0) - mpf_div_2exp(m_data, m_data, -e); - return *this; - } - gmp_real_imp& operator = (const char* s) - { - mpf_set_str(m_data, s, 10); - return *this; - } - void swap(gmp_real_imp& o) - { - mpf_swap(m_data, o.m_data); - } - std::string str(unsigned digits, bool scientific)const - { - std::string result; - mp_exp_t e; - void *(*alloc_func_ptr) (size_t); - void *(*realloc_func_ptr) (void *, size_t, size_t); - void (*free_func_ptr) (void *, size_t); - const char* ps = mpf_get_str (0, &e, 10, digits, m_data); - std::ptrdiff_t sl = std::strlen(ps); - if(sl == 0) - return "0"; - if(*ps == '-') - --sl; // number of digits excluding sign. - if(!scientific - && (sl <= std::numeric_limits::digits10 + 1) - && (e >= sl) - && (sl <= std::numeric_limits::digits10 + 1)) - { - result = ps; - result.append(e-sl, '0'); - } - else - { - result = ps; - if(ps[0] == '-') - result.insert(2, 1, '.'); - else - result.insert(1, 1, '.'); - --e; - if(e) - result += "e" + lexical_cast(e); - } - mp_get_memory_functions(&alloc_func_ptr, &realloc_func_ptr, &free_func_ptr); - (*free_func_ptr)((void*)ps, std::strlen(ps) + 1); - return result; - } - ~gmp_real_imp() - { - if(m_data[0]._mp_d) - mpf_clear(m_data); - } - void negate() - { - mpf_neg(m_data, m_data); - } - int compare(const gmp_real& o)const - { - return mpf_cmp(m_data, o.m_data); - } - int compare(long i)const - { - return mpf_cmp_si(m_data, i); - } - int compare(unsigned long i)const - { - return mpf_cmp_ui(m_data, i); - } - template - int compare(V v)const - { - gmp_real d; - d = v; - return compare(d); - } - mpf_t& data() { return m_data; } - const mpf_t& data()const { return m_data; } -protected: - mpf_t m_data; - static unsigned& get_default_precision() - { - static unsigned val = 50; - return val; - } -}; - -} // namespace detail - -template -struct gmp_real : public detail::gmp_real_imp -{ - gmp_real() - { - mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - } - gmp_real(const gmp_real& o) : detail::gmp_real_imp(o) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real(gmp_real&& o) : detail::gmp_real_imp(o) {} -#endif - gmp_real& operator=(const gmp_real& o) - { - *static_cast*>(this) = static_cast const&>(o); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real& operator=(gmp_real&& o) - { - *static_cast*>(this) = static_cast&&>(o); - return *this; - } -#endif - template - gmp_real& operator=(const V& v) - { - *static_cast*>(this) = v; - return *this; - } -}; - -template <> -struct gmp_real<0> : public detail::gmp_real_imp<0> -{ - gmp_real() - { - mpf_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L); - } - gmp_real(unsigned digits10) - { - mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - } - gmp_real(const gmp_real& o) : detail::gmp_real_imp<0>(o) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real(gmp_real&& o) : detail::gmp_real_imp<0>(o) {} -#endif - gmp_real(const gmp_real& o, unsigned digits10) - { - mpf_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - *this = o; - } - - gmp_real& operator=(const gmp_real& o) - { - *static_cast*>(this) = static_cast const&>(o); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - gmp_real& operator=(gmp_real&& o) - { - *static_cast*>(this) = static_cast &&>(o); - return *this; - } -#endif - template - gmp_real& operator=(const V& v) - { - *static_cast*>(this) = v; - return *this; - } - static unsigned default_precision() - { - return get_default_precision(); - } - static void default_precision(unsigned v) - { - get_default_precision() = v; - } - unsigned precision()const - { - return mpf_get_prec(this->m_data) * 301L / 1000 - 1; - } - void precision(unsigned digits10) - { - mpf_set_prec(this->m_data, (digits10 + 1) * 1000L / 301); - } -}; - -template -inline void add(gmp_real& result, const gmp_real& o) -{ - mpf_add(result.data(), result.data(), o.data()); -} -template -inline void subtract(gmp_real& result, const gmp_real& o) -{ - mpf_sub(result.data(), result.data(), o.data()); -} -template -inline void multiply(gmp_real& result, const gmp_real& o) -{ - mpf_mul(result.data(), result.data(), o.data()); -} -template -inline void divide(gmp_real& result, const gmp_real& o) -{ - mpf_div(result.data(), result.data(), o.data()); -} -template -inline void add(gmp_real& result, unsigned long i) -{ - mpf_add_ui(result.data(), result.data(), i); -} -template -inline void subtract(gmp_real& result, unsigned long i) -{ - mpf_sub_ui(result.data(), result.data(), i); -} -template -inline void multiply(gmp_real& result, unsigned long i) -{ - mpf_mul_ui(result.data(), result.data(), i); -} -template -inline void divide(gmp_real& result, unsigned long i) -{ - mpf_div_ui(result.data(), result.data(), i); -} -template -inline void add(gmp_real& result, long i) -{ - if(i > 0) - mpf_add_ui(result.data(), result.data(), i); - else - mpf_sub_ui(result.data(), result.data(), std::abs(i)); -} -template -inline void subtract(gmp_real& result, long i) -{ - if(i > 0) - mpf_sub_ui(result.data(), result.data(), i); - else - mpf_add_ui(result.data(), result.data(), std::abs(i)); -} -template -inline void multiply(gmp_real& result, long i) -{ - mpf_mul_ui(result.data(), result.data(), std::abs(i)); - if(i < 0) - mpf_neg(result.data(), result.data()); -} -template -inline void divide(gmp_real& result, long i) -{ - mpf_div_ui(result.data(), result.data(), std::abs(i)); - if(i < 0) - mpf_neg(result.data(), result.data()); -} -// -// Specialised 3 arg versions of the basic operators: -// -template -inline void add(gmp_real& a, const gmp_real& x, const gmp_real& y) -{ - mpf_add(a.data(), x.data(), y.data()); -} -template -inline void add(gmp_real& a, const gmp_real& x, unsigned long y) -{ - mpf_add_ui(a.data(), x.data(), y); -} -template -inline void add(gmp_real& a, const gmp_real& x, long y) -{ - if(y < 0) - mpf_sub_ui(a.data(), x.data(), -y); - else - mpf_add_ui(a.data(), x.data(), y); -} -template -inline void add(gmp_real& a, unsigned long x, const gmp_real& y) -{ - mpf_add_ui(a.data(), y.data(), x); -} -template -inline void add(gmp_real& a, long x, const gmp_real& y) -{ - if(x < 0) - { - mpf_ui_sub(a.data(), -x, y.data()); - mpf_neg(a.data(), a.data()); - } - else - mpf_add_ui(a.data(), y.data(), x); -} -template -inline void subtract(gmp_real& a, const gmp_real& x, const gmp_real& y) -{ - mpf_sub(a.data(), x.data(), y.data()); -} -template -inline void subtract(gmp_real& a, const gmp_real& x, unsigned long y) -{ - mpf_sub_ui(a.data(), x.data(), y); -} -template -inline void subtract(gmp_real& a, const gmp_real& x, long y) -{ - if(y < 0) - mpf_add_ui(a.data(), x.data(), -y); - else - mpf_sub_ui(a.data(), x.data(), y); -} -template -inline void subtract(gmp_real& a, unsigned long x, const gmp_real& y) -{ - mpf_ui_sub(a.data(), x, y.data()); -} -template -inline void subtract(gmp_real& a, long x, const gmp_real& y) -{ - if(x < 0) - { - mpf_add_ui(a.data(), y.data(), -x); - mpf_neg(a.data(), a.data()); - } - else - mpf_ui_sub(a.data(), x, y.data()); -} - -template -inline void multiply(gmp_real& a, const gmp_real& x, const gmp_real& y) -{ - mpf_mul(a.data(), x.data(), y.data()); -} -template -inline void multiply(gmp_real& a, const gmp_real& x, unsigned long y) -{ - mpf_mul_ui(a.data(), x.data(), y); -} -template -inline void multiply(gmp_real& a, const gmp_real& x, long y) -{ - if(y < 0) - { - mpf_mul_ui(a.data(), x.data(), -y); - a.negate(); - } - else - mpf_mul_ui(a.data(), x.data(), y); -} -template -inline void multiply(gmp_real& a, unsigned long x, const gmp_real& y) -{ - mpf_mul_ui(a.data(), y.data(), x); -} -template -inline void multiply(gmp_real& a, long x, const gmp_real& y) -{ - if(x < 0) - { - mpf_mul_ui(a.data(), y.data(), -x); - mpf_neg(a.data(), a.data()); - } - else - mpf_mul_ui(a.data(), y.data(), x); -} - -template -inline void divide(gmp_real& a, const gmp_real& x, const gmp_real& y) -{ - mpf_div(a.data(), x.data(), y.data()); -} -template -inline void divide(gmp_real& a, const gmp_real& x, unsigned long y) -{ - mpf_div_ui(a.data(), x.data(), y); -} -template -inline void divide(gmp_real& a, const gmp_real& x, long y) -{ - if(y < 0) - { - mpf_div_ui(a.data(), x.data(), -y); - a.negate(); - } - else - mpf_div_ui(a.data(), x.data(), y); -} -template -inline void divide(gmp_real& a, unsigned long x, const gmp_real& y) -{ - mpf_ui_div(a.data(), x, y.data()); -} -template -inline void divide(gmp_real& a, long x, const gmp_real& y) -{ - if(x < 0) - { - mpf_ui_div(a.data(), -x, y.data()); - mpf_neg(a.data(), a.data()); - } - else - mpf_ui_div(a.data(), x, y.data()); -} - -template -inline bool is_zero(const gmp_real& val) -{ - return mpf_sgn(val.data()) == 0; -} -template -inline int get_sign(const gmp_real& val) -{ - return mpf_sgn(val.data()); -} - -template -inline void convert_to(unsigned long* result, const gmp_real& val) -{ - *result = mpf_get_ui(val.data()); -} -template -inline void convert_to(long* result, const gmp_real& val) -{ - *result = mpf_get_si(val.data()); -} -template -inline void convert_to(double* result, const gmp_real& val) -{ - *result = mpf_get_d(val.data()); -} - -// -// Native non-member operations: -// -template -inline void eval_sqrt(gmp_real& result, const gmp_real& val) -{ - mpf_sqrt(result.data(), val.data()); -} - -template -inline void eval_abs(gmp_real& result, const gmp_real& val) -{ - mpf_abs(result.data(), val.data()); -} - -template -inline void eval_fabs(gmp_real& result, const gmp_real& val) -{ - mpf_abs(result.data(), val.data()); -} -template -inline void eval_ceil(gmp_real& result, const gmp_real& val) -{ - mpf_ceil(result.data(), val.data()); -} -template -inline void eval_floor(gmp_real& result, const gmp_real& val) -{ - mpf_floor(result.data(), val.data()); -} -template -inline void eval_trunc(gmp_real& result, const gmp_real& val) -{ - mpf_trunc(result.data(), val.data()); -} -template -inline void eval_ldexp(gmp_real& result, const gmp_real& val, long e) -{ - if(e > 0) - mpf_mul_2exp(result.data(), val.data(), e); - else if(e < 0) - mpf_div_2exp(result.data(), val.data(), -e); -} -template -inline void eval_frexp(gmp_real& result, const gmp_real& val, int* e) -{ - long v; - mpf_get_d_2exp(&v, val.data()); - *e = v; - eval_ldexp(result, val, -v); -} -template -inline void eval_frexp(gmp_real& result, const gmp_real& val, long* e) -{ - mpf_get_d_2exp(e, val.data()); - eval_ldexp(result, val, -*e); -} - -struct gmp_int -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - gmp_int() - { - mpz_init(this->m_data); - } - gmp_int(const gmp_int& o) - { - mpz_init_set(m_data, o.m_data); - } - gmp_int& operator = (const gmp_int& o) - { - mpz_set(m_data, o.m_data); - return *this; - } - gmp_int& operator = (boost::uintmax_t i) - { - boost::uintmax_t mask = ((1uLL << std::numeric_limits::digits) - 1); - unsigned shift = 0; - mpz_t t; - mpz_init(m_data); - mpz_init(t); - while(i) - { - mpz_set_ui(t, static_cast(i & mask)); - if(shift) - mpz_mul_2exp(t, t, shift); - mpz_add(m_data, m_data, t); - shift += std::numeric_limits::digits; - i >>= std::numeric_limits::digits; - } - mpz_clear(t); - return *this; - } - gmp_int& operator = (boost::intmax_t i) - { - bool neg = i < 0; - *this = static_cast(std::abs(i)); - if(neg) - mpz_neg(m_data, m_data); - return *this; - } - gmp_int& operator = (unsigned long i) - { - mpz_set_ui(m_data, i); - return *this; - } - gmp_int& operator = (long i) - { - mpz_set_si(m_data, i); - return *this; - } - gmp_int& operator = (double d) - { - mpz_set_d(m_data, d); - return *this; - } - gmp_int& operator = (long double a) - { - using std::frexp; - using std::ldexp; - using std::floor; - - if (a == 0) { - mpz_set_si(m_data, 0); - return *this; - } - - if (a == 1) { - mpz_set_si(m_data, 1); - return *this; - } - - BOOST_ASSERT(!(boost::math::isinf)(a)); - BOOST_ASSERT(!(boost::math::isnan)(a)); - - int e; - long double f, term; - mpz_init_set_ui(m_data, 0u); - - f = frexp(a, &e); - - static const int shift = std::numeric_limits::digits - 1; - - while(f) - { - // extract int sized bits from f: - f = ldexp(f, shift); - term = floor(f); - e -= shift; - mpz_mul_2exp(m_data, m_data, shift); - if(term > 0) - mpz_add_ui(m_data, m_data, static_cast(term)); - else - mpz_sub_ui(m_data, m_data, static_cast(-term)); - f -= term; - } - if(e > 0) - mpz_mul_2exp(m_data, m_data, e); - else if(e < 0) - mpz_div_2exp(m_data, m_data, -e); - return *this; - } - gmp_int& operator = (const char* s) - { - mpz_set_str(m_data, s, 10); - return *this; - } - void swap(gmp_int& o) - { - mpz_swap(m_data, o.m_data); - } - std::string str(unsigned /*digits*/, bool /*scientific*/)const - { - void *(*alloc_func_ptr) (size_t); - void *(*realloc_func_ptr) (void *, size_t, size_t); - void (*free_func_ptr) (void *, size_t); - const char* ps = mpz_get_str (0, 10, m_data); - std::string s = ps; - mp_get_memory_functions(&alloc_func_ptr, &realloc_func_ptr, &free_func_ptr); - (*free_func_ptr)((void*)ps, std::strlen(ps) + 1); - return s; - } - ~gmp_int() - { - mpz_clear(m_data); - } - void negate() - { - mpz_neg(m_data, m_data); - } - int compare(const gmp_int& o)const - { - return mpz_cmp(m_data, o.m_data); - } - int compare(long i)const - { - return mpz_cmp_si(m_data, i); - } - int compare(unsigned long i)const - { - return mpz_cmp_ui(m_data, i); - } - template - int compare(V v)const - { - gmp_int d; - d = v; - return compare(d); - } - mpz_t& data() { return m_data; } - const mpz_t& data()const { return m_data; } -protected: - mpz_t m_data; -}; - -inline void add(gmp_int& t, const gmp_int& o) -{ - mpz_add(t.data(), t.data(), o.data()); -} -inline void subtract(gmp_int& t, const gmp_int& o) -{ - mpz_sub(t.data(), t.data(), o.data()); -} -inline void multiply(gmp_int& t, const gmp_int& o) -{ - mpz_mul(t.data(), t.data(), o.data()); -} -inline void divide(gmp_int& t, const gmp_int& o) -{ - mpz_div(t.data(), t.data(), o.data()); -} -inline void modulus(gmp_int& t, const gmp_int& o) -{ - bool neg = mpz_sgn(t.data()) < 0; - bool neg2 = mpz_sgn(o.data()) < 0; - mpz_mod(t.data(), t.data(), o.data()); - if(neg) - { - if(!neg2) - t.negate(); - mpz_add(t.data(), t.data(), o.data()); - if(!neg2) - t.negate(); - } -} -inline void add(gmp_int& t, unsigned long i) -{ - mpz_add_ui(t.data(), t.data(), i); -} -inline void subtract(gmp_int& t, unsigned long i) -{ - mpz_sub_ui(t.data(), t.data(), i); -} -inline void multiply(gmp_int& t, unsigned long i) -{ - mpz_mul_ui(t.data(), t.data(), i); -} -inline void modulus(gmp_int& t, unsigned long i) -{ - bool neg = mpz_sgn(t.data()) < 0; - mpz_mod_ui(t.data(), t.data(), i); - if(neg) - { - t.negate(); - mpz_add_ui(t.data(), t.data(), i); - t.negate(); - } -} -inline void divide(gmp_int& t, unsigned long i) -{ - mpz_div_ui(t.data(), t.data(), i); -} -inline void add(gmp_int& t, long i) -{ - if(i > 0) - mpz_add_ui(t.data(), t.data(), i); - else - mpz_sub_ui(t.data(), t.data(), -i); -} -inline void subtract(gmp_int& t, long i) -{ - if(i > 0) - mpz_sub_ui(t.data(), t.data(), i); - else - mpz_add_ui(t.data(), t.data(), -i); -} -inline void multiply(gmp_int& t, long i) -{ - mpz_mul_ui(t.data(), t.data(), std::abs(i)); - if(i < 0) - mpz_neg(t.data(), t.data()); -} -inline void modulus(gmp_int& t, long i) -{ - bool neg = mpz_sgn(t.data()) < 0; - bool neg2 = i < 0; - mpz_mod_ui(t.data(), t.data(), std::abs(i)); - if(neg) - { - if(!neg2) - { - t.negate(); - mpz_add_ui(t.data(), t.data(), std::abs(i)); - t.negate(); - } - else - { - mpz_sub_ui(t.data(), t.data(), std::abs(i)); - } - } -} -inline void divide(gmp_int& t, long i) -{ - mpz_div_ui(t.data(), t.data(), std::abs(i)); - if(i < 0) - mpz_neg(t.data(), t.data()); -} -template -inline void left_shift(gmp_int& t, UI i) -{ - mpz_mul_2exp(t.data(), t.data(), static_cast(i)); -} -template -inline void right_shift(gmp_int& t, UI i) -{ - mpz_fdiv_q_2exp(t.data(), t.data(), static_cast(i)); -} -template -inline void left_shift(gmp_int& t, const gmp_int& v, UI i) -{ - mpz_mul_2exp(t.data(), v.data(), static_cast(i)); -} -template -inline void right_shift(gmp_int& t, const gmp_int& v, UI i) -{ - mpz_fdiv_q_2exp(t.data(), v.data(), static_cast(i)); -} - -inline void bitwise_and(gmp_int& result, const gmp_int& v) -{ - mpz_and(result.data(), result.data(), v.data()); -} - -inline void bitwise_or(gmp_int& result, const gmp_int& v) -{ - mpz_ior(result.data(), result.data(), v.data()); -} - -inline void bitwise_xor(gmp_int& result, const gmp_int& v) -{ - mpz_xor(result.data(), result.data(), v.data()); -} - -inline void add(gmp_int& t, const gmp_int& p, const gmp_int& o) -{ - mpz_add(t.data(), p.data(), o.data()); -} -inline void subtract(gmp_int& t, const gmp_int& p, const gmp_int& o) -{ - mpz_sub(t.data(), p.data(), o.data()); -} -inline void multiply(gmp_int& t, const gmp_int& p, const gmp_int& o) -{ - mpz_mul(t.data(), p.data(), o.data()); -} -inline void divide(gmp_int& t, const gmp_int& p, const gmp_int& o) -{ - mpz_div(t.data(), p.data(), o.data()); -} -inline void modulus(gmp_int& t, const gmp_int& p, const gmp_int& o) -{ - bool neg = mpz_sgn(p.data()) < 0; - bool neg2 = mpz_sgn(o.data()) < 0; - mpz_mod(t.data(), p.data(), o.data()); - if(neg) - { - if(!neg2) - t.negate(); - mpz_add(t.data(), t.data(), o.data()); - if(!neg2) - t.negate(); - } -} -inline void add(gmp_int& t, const gmp_int& p, unsigned long i) -{ - mpz_add_ui(t.data(), p.data(), i); -} -inline void subtract(gmp_int& t, const gmp_int& p, unsigned long i) -{ - mpz_sub_ui(t.data(), p.data(), i); -} -inline void multiply(gmp_int& t, const gmp_int& p, unsigned long i) -{ - mpz_mul_ui(t.data(), p.data(), i); -} -inline void modulus(gmp_int& t, const gmp_int& p, unsigned long i) -{ - bool neg = mpz_sgn(p.data()) < 0; - mpz_mod_ui(t.data(), p.data(), i); - if(neg) - { - t.negate(); - mpz_add_ui(t.data(), t.data(), i); - t.negate(); - } -} -inline void divide(gmp_int& t, const gmp_int& p, unsigned long i) -{ - mpz_div_ui(t.data(), p.data(), i); -} -inline void add(gmp_int& t, const gmp_int& p, long i) -{ - if(i > 0) - mpz_add_ui(t.data(), p.data(), i); - else - mpz_sub_ui(t.data(), p.data(), -i); -} -inline void subtract(gmp_int& t, const gmp_int& p, long i) -{ - if(i > 0) - mpz_sub_ui(t.data(), p.data(), i); - else - mpz_add_ui(t.data(), p.data(), -i); -} -inline void multiply(gmp_int& t, const gmp_int& p, long i) -{ - mpz_mul_ui(t.data(), p.data(), std::abs(i)); - if(i < 0) - mpz_neg(t.data(), t.data()); -} -inline void modulus(gmp_int& t, const gmp_int& p, long i) -{ - bool neg = mpz_sgn(p.data()) < 0; - bool neg2 = i < 0; - mpz_mod_ui(t.data(), p.data(), std::abs(i)); - if(neg) - { - if(!neg2) - { - t.negate(); - mpz_add_ui(t.data(), t.data(), std::abs(i)); - t.negate(); - } - else - { - mpz_sub_ui(t.data(), t.data(), std::abs(i)); - } - } -} -inline void divide(gmp_int& t, const gmp_int& p, long i) -{ - mpz_div_ui(t.data(), p.data(), std::abs(i)); - if(i < 0) - mpz_neg(t.data(), t.data()); -} - -inline void bitwise_and(gmp_int& result, const gmp_int& u, const gmp_int& v) -{ - mpz_and(result.data(), u.data(), v.data()); -} - -inline void bitwise_or(gmp_int& result, const gmp_int& u, const gmp_int& v) -{ - mpz_ior(result.data(), u.data(), v.data()); -} - -inline void bitwise_xor(gmp_int& result, const gmp_int& u, const gmp_int& v) -{ - mpz_xor(result.data(), u.data(), v.data()); -} - -inline void complement(gmp_int& result, const gmp_int& u) -{ - mpz_com(result.data(), u.data()); -} - -inline bool is_zero(const gmp_int& val) -{ - return mpz_sgn(val.data()) == 0; -} -inline int get_sign(const gmp_int& val) -{ - return mpz_sgn(val.data()); -} -inline void convert_to(unsigned long* result, const gmp_int& val) -{ - *result = mpz_get_ui(val.data()); -} -inline void convert_to(long* result, const gmp_int& val) -{ - *result = mpz_get_si(val.data()); -} -inline void convert_to(double* result, const gmp_int& val) -{ - *result = mpz_get_d(val.data()); -} - -inline void eval_abs(gmp_int& result, const gmp_int& val) -{ - mpz_abs(result.data(), val.data()); -} - -struct gmp_rational; -void add(gmp_rational& t, const gmp_rational& o); - -struct gmp_rational -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - gmp_rational() - { - mpq_init(this->m_data); - } - gmp_rational(const gmp_rational& o) - { - mpq_init(m_data); - mpq_set(m_data, o.m_data); - } - gmp_rational& operator = (const gmp_rational& o) - { - mpq_set(m_data, o.m_data); - return *this; - } - gmp_rational& operator = (boost::uintmax_t i) - { - boost::uintmax_t mask = ((1uLL << std::numeric_limits::digits) - 1); - unsigned shift = 0; - mpq_t t; - mpq_init(m_data); - mpq_init(t); - while(i) - { - mpq_set_ui(t, static_cast(i & mask), 1); - if(shift) - mpq_mul_2exp(t, t, shift); - mpq_add(m_data, m_data, t); - shift += std::numeric_limits::digits; - i >>= std::numeric_limits::digits; - } - mpq_clear(t); - return *this; - } - gmp_rational& operator = (boost::intmax_t i) - { - bool neg = i < 0; - *this = static_cast(std::abs(i)); - if(neg) - mpq_neg(m_data, m_data); - return *this; - } - gmp_rational& operator = (unsigned long i) - { - mpq_set_ui(m_data, i, 1); - return *this; - } - gmp_rational& operator = (long i) - { - mpq_set_si(m_data, i, 1); - return *this; - } - gmp_rational& operator = (double d) - { - mpq_set_d(m_data, d); - return *this; - } - gmp_rational& operator = (long double a) - { - using std::frexp; - using std::ldexp; - using std::floor; - using big_num_default_ops::add; - using big_num_default_ops::subtract; - - if (a == 0) { - mpq_set_si(m_data, 0, 1); - return *this; - } - - if (a == 1) { - mpq_set_si(m_data, 1, 1); - return *this; - } - - BOOST_ASSERT(!(boost::math::isinf)(a)); - BOOST_ASSERT(!(boost::math::isnan)(a)); - - int e; - long double f, term; - mpq_init(m_data); - mpq_set_ui(m_data, 0u, 1); - gmp_rational t; - - f = frexp(a, &e); - - static const int shift = std::numeric_limits::digits - 1; - - while(f) - { - // extract int sized bits from f: - f = ldexp(f, shift); - term = floor(f); - e -= shift; - mpq_mul_2exp(m_data, m_data, shift); - t = static_cast(term); - add(*this, t); - f -= term; - } - if(e > 0) - mpq_mul_2exp(m_data, m_data, e); - else if(e < 0) - mpq_div_2exp(m_data, m_data, -e); - return *this; - } - gmp_rational& operator = (const char* s) - { - mpq_set_str(m_data, s, 10); - return *this; - } - void swap(gmp_rational& o) - { - mpq_swap(m_data, o.m_data); - } - std::string str(unsigned /*digits*/, bool /*scientific*/)const - { - void *(*alloc_func_ptr) (size_t); - void *(*realloc_func_ptr) (void *, size_t, size_t); - void (*free_func_ptr) (void *, size_t); - const char* ps = mpq_get_str (0, 10, m_data); - std::string s = ps; - mp_get_memory_functions(&alloc_func_ptr, &realloc_func_ptr, &free_func_ptr); - (*free_func_ptr)((void*)ps, std::strlen(ps) + 1); - return s; - } - ~gmp_rational() - { - mpq_clear(m_data); - } - void negate() - { - mpq_neg(m_data, m_data); - } - int compare(const gmp_rational& o)const - { - return mpq_cmp(m_data, o.m_data); - } - template - int compare(V v)const - { - gmp_rational d; - d = v; - return compare(d); - } - int compare(unsigned long v) - { - return mpq_cmp_ui(m_data, v, 1); - } - int compare(long v) - { - return mpq_cmp_si(m_data, v, 1); - } - mpq_t& data() { return m_data; } - const mpq_t& data()const { return m_data; } -protected: - mpq_t m_data; -}; - -inline void add(gmp_rational& t, const gmp_rational& o) -{ - mpq_add(t.data(), t.data(), o.data()); -} -inline void subtract(gmp_rational& t, const gmp_rational& o) -{ - mpq_sub(t.data(), t.data(), o.data()); -} -inline void multiply(gmp_rational& t, const gmp_rational& o) -{ - mpq_mul(t.data(), t.data(), o.data()); -} -inline void divide(gmp_rational& t, const gmp_rational& o) -{ - mpq_div(t.data(), t.data(), o.data()); -} -inline void add(gmp_rational& t, const gmp_rational& p, const gmp_rational& o) -{ - mpq_add(t.data(), p.data(), o.data()); -} -inline void subtract(gmp_rational& t, const gmp_rational& p, const gmp_rational& o) -{ - mpq_sub(t.data(), p.data(), o.data()); -} -inline void multiply(gmp_rational& t, const gmp_rational& p, const gmp_rational& o) -{ - mpq_mul(t.data(), p.data(), o.data()); -} -inline void divide(gmp_rational& t, const gmp_rational& p, const gmp_rational& o) -{ - mpq_div(t.data(), p.data(), o.data()); -} - -inline bool is_zero(const gmp_rational& val) -{ - return mpq_sgn(val.data()) == 0; -} -inline int get_sign(const gmp_rational& val) -{ - return mpq_sgn(val.data()); -} -inline void convert_to(double* result, const gmp_rational& val) -{ - *result = mpq_get_d(val.data()); -} - -inline void convert_to(long* result, const gmp_rational& val) -{ - double r; - convert_to(&r, val); - *result = r; -} - -inline void convert_to(unsigned long* result, const gmp_rational& val) -{ - double r; - convert_to(&r, val); - *result = r; -} - -inline void eval_abs(gmp_rational& result, const gmp_rational& val) -{ - mpq_abs(result.data(), val.data()); -} - -template<> -struct number_category : public mpl::int_{}; -template<> -struct number_category : public mpl::int_{}; - -typedef big_number > mpf_real_50; -typedef big_number > mpf_real_100; -typedef big_number > mpf_real_500; -typedef big_number > mpf_real_1000; -typedef big_number > mpf_real; -typedef big_number mpz_int; -typedef big_number mpq_rational; - -}} // namespaces - -namespace std{ - -#ifdef BOOST_NO_NOEXCEPT -# define noexcept -#endif - -// -// numeric_limits [partial] specializations for the types declared in this header: -// -template -class numeric_limits > > -{ - typedef boost::math::big_number > number_type; -public: - BOOST_STATIC_CONSTEXPR bool is_specialized = true; - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpf_div_2exp(value.second.backend().data(), value.second.backend().data(), LONG_MAX); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpf_mul_2exp(value.second.backend().data(), value.second.backend().data(), LONG_MAX - 1); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept - { - return -(max)(); - } - BOOST_STATIC_CONSTEXPR int digits = static_cast(((Digits10 + 1) * 1000L) / 301L); - BOOST_STATIC_CONSTEXPR int digits10 = Digits10; - // Is this really correct??? - BOOST_STATIC_CONSTEXPR int max_digits10 = Digits10 + 1; - BOOST_STATIC_CONSTEXPR bool is_signed = true; - BOOST_STATIC_CONSTEXPR bool is_integer = false; - BOOST_STATIC_CONSTEXPR bool is_exact = false; - BOOST_STATIC_CONSTEXPR int radix = 2; - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpf_div_2exp(value.second.backend().data(), value.second.backend().data(), std::numeric_limits::digits - 1); - } - return value.second; - } - // What value should this be???? - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept - { - // returns epsilon/2 - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpf_div_2exp(value.second.backend().data(), value.second.backend().data(), digits); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR long min_exponent = LONG_MIN; - BOOST_STATIC_CONSTEXPR long min_exponent10 = (LONG_MIN / 1000) * 301L; - BOOST_STATIC_CONSTEXPR long max_exponent = LONG_MAX; - BOOST_STATIC_CONSTEXPR long max_exponent10 = (LONG_MAX / 1000) * 301L; - BOOST_STATIC_CONSTEXPR bool has_infinity = false; - BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false; - BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; - BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; - BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR bool is_iec559 = false; - BOOST_STATIC_CONSTEXPR bool is_bounded = true; - BOOST_STATIC_CONSTEXPR bool is_modulo = false; - BOOST_STATIC_CONSTEXPR bool traps = true; - BOOST_STATIC_CONSTEXPR bool tinyness_before = false; - BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest; - -private: - struct data_initializer - { - data_initializer() - { - std::numeric_limits > >::epsilon(); - std::numeric_limits > >::round_error(); - (std::numeric_limits > >::min)(); - (std::numeric_limits > >::max)(); - } - void do_nothing()const{} - }; - static const data_initializer initializer; -}; - -template -const typename numeric_limits > >::data_initializer numeric_limits > >::initializer; - -template<> -class numeric_limits > > -{ - typedef boost::math::big_number > number_type; -public: - BOOST_STATIC_CONSTEXPR bool is_specialized = false; - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR int digits = 0; - BOOST_STATIC_CONSTEXPR int digits10 = 0; - BOOST_STATIC_CONSTEXPR int max_digits10 = 0; - BOOST_STATIC_CONSTEXPR bool is_signed = false; - BOOST_STATIC_CONSTEXPR bool is_integer = false; - BOOST_STATIC_CONSTEXPR bool is_exact = false; - BOOST_STATIC_CONSTEXPR int radix = 0; - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR int min_exponent = 0; - BOOST_STATIC_CONSTEXPR int min_exponent10 = 0; - BOOST_STATIC_CONSTEXPR int max_exponent = 0; - BOOST_STATIC_CONSTEXPR int max_exponent10 = 0; - BOOST_STATIC_CONSTEXPR bool has_infinity = false; - BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false; - BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; - BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; - BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR bool is_iec559 = false; - BOOST_STATIC_CONSTEXPR bool is_bounded = false; - BOOST_STATIC_CONSTEXPR bool is_modulo = false; - BOOST_STATIC_CONSTEXPR bool traps = false; - BOOST_STATIC_CONSTEXPR bool tinyness_before = false; - BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero; -}; - -template<> -class numeric_limits -{ - typedef boost::math::mpz_int number_type; -public: - BOOST_STATIC_CONSTEXPR bool is_specialized = true; - // - // Largest and smallest numbers are bounded only by available memory, set - // to zero: - // - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept - { - return number_type(); - } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept - { - return number_type(); - } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept { return (min)(); } - // Digits are unbounded, use zero for now: - BOOST_STATIC_CONSTEXPR int digits = 0; - BOOST_STATIC_CONSTEXPR int digits10 = 0; - BOOST_STATIC_CONSTEXPR int max_digits10 = 0; - BOOST_STATIC_CONSTEXPR bool is_signed = true; - BOOST_STATIC_CONSTEXPR bool is_integer = true; - BOOST_STATIC_CONSTEXPR bool is_exact = true; - BOOST_STATIC_CONSTEXPR int radix = 2; - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR int min_exponent = 0; - BOOST_STATIC_CONSTEXPR int min_exponent10 = 0; - BOOST_STATIC_CONSTEXPR int max_exponent = 0; - BOOST_STATIC_CONSTEXPR int max_exponent10 = 0; - BOOST_STATIC_CONSTEXPR bool has_infinity = false; - BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false; - BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; - BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; - BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return number_type(); } - BOOST_STATIC_CONSTEXPR bool is_iec559 = false; - BOOST_STATIC_CONSTEXPR bool is_bounded = false; - BOOST_STATIC_CONSTEXPR bool is_modulo = false; - BOOST_STATIC_CONSTEXPR bool traps = false; - BOOST_STATIC_CONSTEXPR bool tinyness_before = false; - BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero; -}; - -#ifdef BOOST_NO_NOEXCEPT -# undef noexcept -#endif - -} // namespace std - -#endif diff --git a/include/boost/math/big_number/mpfr.hpp b/include/boost/math/big_number/mpfr.hpp deleted file mode 100644 index 31165841..00000000 --- a/include/boost/math/big_number/mpfr.hpp +++ /dev/null @@ -1,952 +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_0.txt) - -#ifndef BOOST_MATH_BN_MPFR_HPP -#define BOOST_MATH_BN_MPFR_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost{ namespace math{ - -template -struct mpfr_real_backend; - -namespace detail{ - -long get_default_precision() { return 50; } - -template -struct mpfr_real_imp -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - mpfr_real_imp(){} - - mpfr_real_imp(const mpfr_real_imp& o) - { - mpfr_init2(m_data, (((digits10 ? digits10 : get_default_precision()) + 1) * 1000L) / 301L); - mpfr_set(m_data, o.m_data, GMP_RNDN); - } -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_imp(mpfr_real_imp&& o) - { - m_data[0] = o.m_data[0]; - o.m_data[0]._mpfr_d = 0; - } -#endif - mpfr_real_imp& operator = (const mpfr_real_imp& o) - { - mpfr_set(m_data, o.m_data, GMP_RNDN); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_imp& operator = (mpfr_real_imp&& o) - { - mpfr_swap(m_data, o.m_data); - return *this; - } -#endif - mpfr_real_imp& operator = (boost::uintmax_t i) - { - boost::uintmax_t mask = ((1uLL << std::numeric_limits::digits) - 1); - unsigned shift = 0; - mpfr_t t; - mpfr_init2(t, (std::max)(static_cast(std::numeric_limits::digits), static_cast(((digits10 + 1) * 1000L) / 301L))); - mpfr_set_ui(m_data, 0, GMP_RNDN); - while(i) - { - mpfr_set_ui(t, static_cast(i & mask), GMP_RNDN); - if(shift) - mpfr_mul_2exp(t, t, shift, GMP_RNDN); - mpfr_add(m_data, m_data, t, GMP_RNDN); - shift += std::numeric_limits::digits; - i >>= std::numeric_limits::digits; - } - mpfr_clear(t); - return *this; - } - mpfr_real_imp& operator = (boost::intmax_t i) - { - bool neg = i < 0; - *this = static_cast(std::abs(i)); - if(neg) - mpfr_neg(m_data, m_data, GMP_RNDN); - return *this; - } - mpfr_real_imp& operator = (unsigned long i) - { - mpfr_set_ui(m_data, i, GMP_RNDN); - return *this; - } - mpfr_real_imp& operator = (long i) - { - mpfr_set_si(m_data, i, GMP_RNDN); - return *this; - } - mpfr_real_imp& operator = (double d) - { - mpfr_set_d(m_data, d, GMP_RNDN); - return *this; - } - mpfr_real_imp& operator = (long double a) - { - using std::frexp; - using std::ldexp; - using std::floor; - - if (a == 0) { - mpfr_set_si(m_data, 0, GMP_RNDN); - return *this; - } - - if (a == 1) { - mpfr_set_si(m_data, 1, GMP_RNDN); - return *this; - } - - BOOST_ASSERT(!(boost::math::isinf)(a)); - BOOST_ASSERT(!(boost::math::isnan)(a)); - - int e; - long double f, term; - mpfr_init_set_ui(m_data, 0u, GMP_RNDN); - - f = frexp(a, &e); - - static const int shift = std::numeric_limits::digits - 1; - - while(f) - { - // extract int sized bits from f: - f = ldexp(f, shift); - term = floor(f); - e -= shift; - mpfr_mul_2exp(m_data, m_data, shift, GMP_RNDN); - if(term > 0) - mpfr_add_ui(m_data, m_data, static_cast(term), GMP_RNDN); - else - mpfr_sub_ui(m_data, m_data, static_cast(-term), GMP_RNDN); - f -= term; - } - if(e > 0) - mpfr_mul_2exp(m_data, m_data, e, GMP_RNDN); - else if(e < 0) - mpfr_div_2exp(m_data, m_data, -e, GMP_RNDN); - return *this; - } - mpfr_real_imp& operator = (const char* s) - { - mpfr_set_str(m_data, s, 10, GMP_RNDN); - return *this; - } - void swap(mpfr_real_imp& o) - { - mpfr_swap(m_data, o.m_data); - } - std::string str(unsigned digits, bool scientific)const - { - std::string result; - mp_exp_t e; - char* ps = mpfr_get_str (0, &e, 10, digits, m_data, GMP_RNDN); - std::ptrdiff_t sl = std::strlen(ps); - unsigned chars = sl; - if(sl == 0) - return "0"; - while(ps[chars-1] == '0') - --chars; - if(*ps == '-') - --chars; // number of digits excluding sign. - if(chars == 0) - return "0"; - if(!scientific - && (chars <= std::numeric_limits::digits10 + 1) - && (e >= (int)chars) - && (chars <= std::numeric_limits::digits10 + 1)) - { - result.assign(ps, (*ps == '-' ? chars+1 : chars)); - result.append(e-chars, '0'); - } - else - { - result = ps; - if(ps[0] == '-') - result.insert(2, 1, '.'); - else - result.insert(1, 1, '.'); - --e; - if(e) - result += "e" + lexical_cast(e); - } - mpfr_free_str(ps); - return result; - } - ~mpfr_real_imp() - { - if(m_data[0]._mpfr_d) - mpfr_clear(m_data); - } - void negate() - { - mpfr_neg(m_data, m_data, GMP_RNDN); - } - int compare(const mpfr_real_backend& o)const - { - return mpfr_cmp(m_data, o.m_data); - } - int compare(long i)const - { - return mpfr_cmp_si(m_data, i); - } - int compare(unsigned long i)const - { - return mpfr_cmp_ui(m_data, i); - } - template - int compare(V v)const - { - mpfr_real_backend d; - d = v; - return compare(d); - } - mpfr_t& data() { return m_data; } - const mpfr_t& data()const { return m_data; } -protected: - mpfr_t m_data; - static unsigned& get_default_precision() - { - static unsigned val = 50; - return val; - } -}; - -} // namespace detail - -template -struct mpfr_real_backend : public detail::mpfr_real_imp -{ - mpfr_real_backend() - { - mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - } - mpfr_real_backend(const mpfr_real_backend& o) : detail::mpfr_real_imp(o) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_backend(mpfr_real_backend&& o) : detail::mpfr_real_imp(o) {} -#endif - mpfr_real_backend& operator=(const mpfr_real_backend& o) - { - *static_cast*>(this) = static_cast const&>(o); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_backend& operator=(mpfr_real_backend&& o) - { - *static_cast*>(this) = static_cast&&>(o); - return *this; - } -#endif - template - mpfr_real_backend& operator=(const V& v) - { - *static_cast*>(this) = v; - return *this; - } -}; - -template <> -struct mpfr_real_backend<0> : public detail::mpfr_real_imp<0> -{ - mpfr_real_backend() - { - mpfr_init2(this->m_data, ((get_default_precision() + 1) * 1000L) / 301L); - } - mpfr_real_backend(unsigned digits10) - { - mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - } - mpfr_real_backend(const mpfr_real_backend& o) : detail::mpfr_real_imp<0>(o) {} -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_backend(mpfr_real_backend&& o) : detail::mpfr_real_imp<0>(o) {} -#endif - mpfr_real_backend(const mpfr_real_backend& o, unsigned digits10) - { - mpfr_init2(this->m_data, ((digits10 + 1) * 1000L) / 301L); - *this = o; - } - - mpfr_real_backend& operator=(const mpfr_real_backend& o) - { - *static_cast*>(this) = static_cast const&>(o); - return *this; - } -#ifndef BOOST_NO_RVALUE_REFERENCES - mpfr_real_backend& operator=(mpfr_real_backend&& o) - { - *static_cast*>(this) = static_cast &&>(o); - return *this; - } -#endif - template - mpfr_real_backend& operator=(const V& v) - { - *static_cast*>(this) = v; - return *this; - } - static unsigned default_precision() - { - return get_default_precision(); - } - static void default_precision(unsigned v) - { - get_default_precision() = v; - } - unsigned precision()const - { - return mpfr_get_prec(this->m_data) * 301L / 1000 - 1; - } - void precision(unsigned digits10) - { - mpfr_set_prec(this->m_data, (digits10 + 1) * 1000L / 301); - } -}; - -template -inline void add(mpfr_real_backend& result, const mpfr_real_backend& o) -{ - mpfr_add(result.data(), result.data(), o.data(), GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& result, const mpfr_real_backend& o) -{ - mpfr_sub(result.data(), result.data(), o.data(), GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& result, const mpfr_real_backend& o) -{ - mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& result, const mpfr_real_backend& o) -{ - mpfr_div(result.data(), result.data(), o.data(), GMP_RNDN); -} -template -inline void add(mpfr_real_backend& result, unsigned long i) -{ - mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& result, unsigned long i) -{ - mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& result, unsigned long i) -{ - mpfr_mul_ui(result.data(), result.data(), i, GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& result, unsigned long i) -{ - mpfr_div_ui(result.data(), result.data(), i, GMP_RNDN); -} -template -inline void add(mpfr_real_backend& result, long i) -{ - if(i > 0) - mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN); - else - mpfr_sub_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& result, long i) -{ - if(i > 0) - mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN); - else - mpfr_add_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& result, long i) -{ - mpfr_mul_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); - if(i < 0) - mpfr_neg(result.data(), result.data(), GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& result, long i) -{ - mpfr_div_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); - if(i < 0) - mpfr_neg(result.data(), result.data(), GMP_RNDN); -} -// -// Specialised 3 arg versions of the basic operators: -// -template -inline void add(mpfr_real_backend& a, const mpfr_real_backend& x, const mpfr_real_backend& y) -{ - mpfr_add(a.data(), x.data(), y.data(), GMP_RNDN); -} -template -inline void add(mpfr_real_backend& a, const mpfr_real_backend& x, unsigned long y) -{ - mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void add(mpfr_real_backend& a, const mpfr_real_backend& x, long y) -{ - if(y < 0) - mpfr_sub_ui(a.data(), x.data(), -y, GMP_RNDN); - else - mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void add(mpfr_real_backend& a, unsigned long x, const mpfr_real_backend& y) -{ - mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN); -} -template -inline void add(mpfr_real_backend& a, long x, const mpfr_real_backend& y) -{ - if(x < 0) - { - mpfr_ui_sub(a.data(), -x, y.data(), GMP_RNDN); - mpfr_neg(a.data(), a.data(), GMP_RNDN); - } - else - mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& a, const mpfr_real_backend& x, const mpfr_real_backend& y) -{ - mpfr_sub(a.data(), x.data(), y.data(), GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& a, const mpfr_real_backend& x, unsigned long y) -{ - mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& a, const mpfr_real_backend& x, long y) -{ - if(y < 0) - mpfr_add_ui(a.data(), x.data(), -y, GMP_RNDN); - else - mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& a, unsigned long x, const mpfr_real_backend& y) -{ - mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN); -} -template -inline void subtract(mpfr_real_backend& a, long x, const mpfr_real_backend& y) -{ - if(x < 0) - { - mpfr_add_ui(a.data(), y.data(), -x, GMP_RNDN); - mpfr_neg(a.data(), a.data(), GMP_RNDN); - } - else - mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN); -} - -template -inline void multiply(mpfr_real_backend& a, const mpfr_real_backend& x, const mpfr_real_backend& y) -{ - mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& a, const mpfr_real_backend& x, unsigned long y) -{ - mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& a, const mpfr_real_backend& x, long y) -{ - if(y < 0) - { - mpfr_mul_ui(a.data(), x.data(), -y, GMP_RNDN); - a.negate(); - } - else - mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& a, unsigned long x, const mpfr_real_backend& y) -{ - mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN); -} -template -inline void multiply(mpfr_real_backend& a, long x, const mpfr_real_backend& y) -{ - if(x < 0) - { - mpfr_mul_ui(a.data(), y.data(), -x, GMP_RNDN); - mpfr_neg(a.data(), a.data(), GMP_RNDN); - } - else - mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN); -} - -template -inline void divide(mpfr_real_backend& a, const mpfr_real_backend& x, const mpfr_real_backend& y) -{ - mpfr_div(a.data(), x.data(), y.data(), GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& a, const mpfr_real_backend& x, unsigned long y) -{ - mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& a, const mpfr_real_backend& x, long y) -{ - if(y < 0) - { - mpfr_div_ui(a.data(), x.data(), -y, GMP_RNDN); - a.negate(); - } - else - mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& a, unsigned long x, const mpfr_real_backend& y) -{ - mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN); -} -template -inline void divide(mpfr_real_backend& a, long x, const mpfr_real_backend& y) -{ - if(x < 0) - { - mpfr_ui_div(a.data(), -x, y.data(), GMP_RNDN); - mpfr_neg(a.data(), a.data(), GMP_RNDN); - } - else - mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN); -} - -template -inline bool is_zero(const mpfr_real_backend& val) -{ - return 0 != mpfr_zero_p(val.data()); -} -template -inline int get_sign(const mpfr_real_backend& val) -{ - return mpfr_sgn(val.data()); -} - -template -inline void convert_to(unsigned long* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_ui(val.data(), GMP_RNDN); -} -template -inline void convert_to(long* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_si(val.data(), GMP_RNDN); -} -#ifdef _MPFR_H_HAVE_INTMAX_T -template -inline void convert_to(boost::uintmax_t* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_uj(val.data(), GMP_RNDN); -} -template -inline void convert_to(boost::intmax_t* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_sj(val.data(), GMP_RNDN); -} -#endif -template -inline void convert_to(double* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_d(val.data(), GMP_RNDN); -} -template -inline void convert_to(long double* result, const mpfr_real_backend& val) -{ - *result = mpfr_get_ld(val.data(), GMP_RNDN); -} - -// -// Native non-member operations: -// -template -inline void eval_sqrt(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_sqrt(result.data(), val.data(), GMP_RNDN); -} - -template -inline void eval_abs(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_abs(result.data(), val.data(), GMP_RNDN); -} - -template -inline void eval_fabs(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_abs(result.data(), val.data(), GMP_RNDN); -} -template -inline void eval_ceil(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_ceil(result.data(), val.data()); -} -template -inline void eval_floor(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_floor(result.data(), val.data()); -} -template -inline void eval_trunc(mpfr_real_backend& result, const mpfr_real_backend& val) -{ - mpfr_trunc(result.data(), val.data()); -} -template -inline void eval_ldexp(mpfr_real_backend& result, const mpfr_real_backend& val, long e) -{ - if(e > 0) - mpfr_mul_2exp(result.data(), val.data(), e, GMP_RNDN); - else if(e < 0) - mpfr_div_2exp(result.data(), val.data(), -e, GMP_RNDN); -} -template -inline void eval_frexp(mpfr_real_backend& result, const mpfr_real_backend& val, int* e) -{ - long v; - mpfr_get_d_2exp(&v, val.data(), GMP_RNDN); - *e = v; - eval_ldexp(result, val, -v); -} -template -inline void eval_frexp(mpfr_real_backend& result, const mpfr_real_backend& val, long* e) -{ - mpfr_get_d_2exp(e, val.data(), GMP_RNDN); - return eval_ldexp(result, val, -*e); -} - -template -inline int eval_fpclassify(const mpfr_real_backend& val) -{ - return mpfr_inf_p(val.data()) ? FP_INFINITE : mpfr_nan_p(val.data()) ? FP_NAN : mpfr_zero_p(val.data()) ? FP_ZERO : FP_NORMAL; -} - -template -inline void eval_pow(mpfr_real_backend& result, const mpfr_real_backend& b, const mpfr_real_backend& e) -{ - mpfr_pow(result.data(), b.data(), e.data(), GMP_RNDN); -} - -template -inline typename enable_if, mpl::bool_ > >::type eval_pow(mpfr_real_backend& result, const mpfr_real_backend& b, const Integer& e) -{ - mpfr_pow_si(result.data(), b.data(), e, GMP_RNDN); -} - -template -inline typename enable_if, mpl::bool_ > >::type eval_pow(mpfr_real_backend& result, const mpfr_real_backend& b, const Integer& e) -{ - mpfr_pow_ui(result.data(), b.data(), e, GMP_RNDN); -} - -template -inline void eval_exp(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_exp(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_log(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_log(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_sin(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_sin(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_cos(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_cos(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_tan(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_tan(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_asin(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_asin(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_acos(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_acos(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_atan(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_atan(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_sinh(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_sinh(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_cosh(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_cosh(result.data(), arg.data(), GMP_RNDN); -} - -template -inline void eval_tanh(mpfr_real_backend& result, const mpfr_real_backend& arg) -{ - mpfr_tanh(result.data(), arg.data(), GMP_RNDN); -} - -typedef big_number > mpfr_real_50; -typedef big_number > mpfr_real_100; -typedef big_number > mpfr_real_500; -typedef big_number > mpfr_real_1000; -typedef big_number > mpfr_real; - -namespace lanczos{ - -template -struct lanczos >, Policy> -{ - typedef typename mpl::if_c< - Digits10 <= 36, - lanczos22UDT, - typename mpl::if_c< - Digits10 <= 50, - lanczos31UDT, - typename mpl::if_c< - Digits10 <= 110, - lanczos61UDT, - undefined_lanczos - >::type - >::type - >::type type; -}; - -} // namespace lanczos - - -}} // namespaces - -namespace std{ - -#ifdef BOOST_NO_NOEXCEPT -# define noexcept -#endif - -// -// numeric_limits [partial] specializations for the types declared in this header: -// -template -class numeric_limits > > -{ - typedef boost::math::big_number > number_type; -public: - BOOST_STATIC_CONSTEXPR bool is_specialized = true; - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 0.5; - mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), -mpfr_get_emin(), GMP_RNDN); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 0.5; - mpfr_mul_2exp(value.second.backend().data(), value.second.backend().data(), mpfr_get_emax(), GMP_RNDN); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept - { - return -(max)(); - } - BOOST_STATIC_CONSTEXPR int digits = static_cast(((Digits10 + 1) * 1000L) / 301L); - BOOST_STATIC_CONSTEXPR int digits10 = Digits10; - // Is this really correct??? - BOOST_STATIC_CONSTEXPR int max_digits10 = Digits10 + 1; - BOOST_STATIC_CONSTEXPR bool is_signed = true; - BOOST_STATIC_CONSTEXPR bool is_integer = false; - BOOST_STATIC_CONSTEXPR bool is_exact = false; - BOOST_STATIC_CONSTEXPR int radix = 2; - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept - { - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), std::numeric_limits::digits - 1, GMP_RNDN); - } - return value.second; - } - // What value should this be???? - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept - { - // returns epsilon/2 - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), digits, GMP_RNDN); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR long min_exponent = MPFR_EMIN_DEFAULT; - BOOST_STATIC_CONSTEXPR long min_exponent10 = (MPFR_EMIN_DEFAULT / 1000) * 301L; - BOOST_STATIC_CONSTEXPR long max_exponent = MPFR_EMAX_DEFAULT; - BOOST_STATIC_CONSTEXPR long max_exponent10 = (MPFR_EMAX_DEFAULT / 1000) * 301L; - BOOST_STATIC_CONSTEXPR bool has_infinity = true; - BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true; - BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; - BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; - BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept - { - // returns epsilon/2 - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpfr_set_inf(value.second.backend().data(), 1); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept - { - // returns epsilon/2 - initializer.do_nothing(); - static std::pair value; - if(!value.first) - { - value.first = true; - value.second = 1; - mpfr_set_nan(value.second.backend().data()); - } - return value.second; - } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept - { - return number_type(0); - } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR bool is_iec559 = false; - BOOST_STATIC_CONSTEXPR bool is_bounded = true; - BOOST_STATIC_CONSTEXPR bool is_modulo = false; - BOOST_STATIC_CONSTEXPR bool traps = true; - BOOST_STATIC_CONSTEXPR bool tinyness_before = false; - BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest; - -private: - struct data_initializer - { - data_initializer() - { - std::numeric_limits > >::epsilon(); - std::numeric_limits > >::round_error(); - (std::numeric_limits > >::min)(); - (std::numeric_limits > >::max)(); - std::numeric_limits > >::infinity(); - std::numeric_limits > >::quiet_NaN(); - } - void do_nothing()const{} - }; - static const data_initializer initializer; -}; - -template -const typename numeric_limits > >::data_initializer numeric_limits > >::initializer; - -template<> -class numeric_limits > > -{ - typedef boost::math::big_number > number_type; -public: - BOOST_STATIC_CONSTEXPR bool is_specialized = false; - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR int digits = 0; - BOOST_STATIC_CONSTEXPR int digits10 = 0; - BOOST_STATIC_CONSTEXPR int max_digits10 = 0; - BOOST_STATIC_CONSTEXPR bool is_signed = false; - BOOST_STATIC_CONSTEXPR bool is_integer = false; - BOOST_STATIC_CONSTEXPR bool is_exact = false; - BOOST_STATIC_CONSTEXPR int radix = 0; - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR int min_exponent = 0; - BOOST_STATIC_CONSTEXPR int min_exponent10 = 0; - BOOST_STATIC_CONSTEXPR int max_exponent = 0; - BOOST_STATIC_CONSTEXPR int max_exponent10 = 0; - BOOST_STATIC_CONSTEXPR bool has_infinity = false; - BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false; - BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false; - BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent; - BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false; - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return number_type(0); } - BOOST_STATIC_CONSTEXPR bool is_iec559 = false; - BOOST_STATIC_CONSTEXPR bool is_bounded = false; - BOOST_STATIC_CONSTEXPR bool is_modulo = false; - BOOST_STATIC_CONSTEXPR bool traps = false; - BOOST_STATIC_CONSTEXPR bool tinyness_before = false; - BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero; -}; - -#ifdef noexcept -#undef noexcept -#endif - -} // namespace std -#endif diff --git a/include/boost/math/concepts/big_number_architypes.hpp b/include/boost/math/concepts/big_number_architypes.hpp deleted file mode 100644 index 26a7a4b6..00000000 --- a/include/boost/math/concepts/big_number_architypes.hpp +++ /dev/null @@ -1,293 +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_ - -#ifndef BOOST_MATH_CONCEPTS_ER_HPP -#define BOOST_MATH_CONCEPTS_ER_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace boost{ -namespace math{ -namespace concepts{ - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable:4244) -#endif - -struct big_number_backend_real_architype -{ - typedef mpl::list signed_types; - typedef mpl::list unsigned_types; - typedef mpl::list real_types; - - big_number_backend_real_architype() - { - std::cout << "Default construct" << std::endl; - } - big_number_backend_real_architype(const big_number_backend_real_architype& o) - { - std::cout << "Copy construct" << std::endl; - m_value = o.m_value; - } - big_number_backend_real_architype& operator = (const big_number_backend_real_architype& o) - { - m_value = o.m_value; - std::cout << "Assignment (" << m_value << ")" << std::endl; - return *this; - } - big_number_backend_real_architype& operator = (boost::uintmax_t i) - { - m_value = i; - std::cout << "UInt Assignment (" << i << ")" << std::endl; - return *this; - } - big_number_backend_real_architype& operator = (boost::intmax_t i) - { - m_value = i; - std::cout << "Int Assignment (" << i << ")" << std::endl; - return *this; - } - big_number_backend_real_architype& operator = (long double d) - { - m_value = d; - std::cout << "long double Assignment (" << d << ")" << std::endl; - return *this; - } - big_number_backend_real_architype& operator = (const char* s) - { - m_value = boost::lexical_cast(s); - std::cout << "const char* Assignment (" << s << ")" << std::endl; - return *this; - } - void swap(big_number_backend_real_architype& o) - { - std::cout << "Swapping (" << m_value << " with " << o.m_value << ")" << std::endl; - std::swap(m_value, o.m_value); - } - std::string str(unsigned digits, bool scientific)const - { - std::stringstream ss; - if(scientific) - ss.setf(ss.scientific); - if(digits) - ss.precision(digits); - else - ss.precision(std::numeric_limits::digits10 + 2); - boost::intmax_t i = m_value; - boost::uintmax_t u = m_value; - if(!scientific && m_value == i) - ss << i; - else if(!scientific && m_value == u) - ss << u; - else - ss << m_value; - std::string s = ss.str(); - std::cout << "Converting to string (" << s << ")" << std::endl; - return s; - } - void negate() - { - std::cout << "Negating (" << m_value << ")" << std::endl; - m_value = -m_value; - } - int compare(const big_number_backend_real_architype& o)const - { - std::cout << "Comparison" << std::endl; - return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0); - } - int compare(boost::intmax_t i)const - { - std::cout << "Comparison with int" << std::endl; - return m_value > i ? 1 : (m_value < i ? -1 : 0); - } - int compare(boost::uintmax_t i)const - { - std::cout << "Comparison with unsigned" << std::endl; - return m_value > i ? 1 : (m_value < i ? -1 : 0); - } - int compare(long double d)const - { - std::cout << "Comparison with long double" << std::endl; - return m_value > d ? 1 : (m_value < d ? -1 : 0); - } - long double m_value; -}; - -inline void add(big_number_backend_real_architype& result, const big_number_backend_real_architype& o) -{ - std::cout << "Addition (" << result.m_value << " += " << o.m_value << ")" << std::endl; - result.m_value += o.m_value; -} -inline void subtract(big_number_backend_real_architype& result, const big_number_backend_real_architype& o) -{ - std::cout << "Subtraction (" << result.m_value << " -= " << o.m_value << ")" << std::endl; - result.m_value -= o.m_value; -} -inline void multiply(big_number_backend_real_architype& result, const big_number_backend_real_architype& o) -{ - std::cout << "Multiplication (" << result.m_value << " *= " << o.m_value << ")" << std::endl; - result.m_value *= o.m_value; -} -inline void divide(big_number_backend_real_architype& result, const big_number_backend_real_architype& o) -{ - std::cout << "Division (" << result.m_value << " /= " << o.m_value << ")" << std::endl; - result.m_value /= o.m_value; -} - -inline void eval_frexp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg, int* exp) -{ - result = std::frexp(arg.m_value, exp); -} - -inline void eval_ldexp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg, int exp) -{ - result = std::ldexp(arg.m_value, exp); -} - -inline void eval_floor(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::floor(arg.m_value); -} - -inline void eval_ceil(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::ceil(arg.m_value); -} - -inline void eval_trunc(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = boost::math::trunc(arg.m_value); -} - -inline void eval_sqrt(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::sqrt(arg.m_value); -} - -inline void eval_abs(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::abs(arg.m_value); -} - -inline void eval_fabs(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::fabs(arg.m_value); -} - -inline int eval_fpclassify(const big_number_backend_real_architype& arg) -{ - return boost::math::fpclassify(arg.m_value); -} - -inline void eval_pow(big_number_backend_real_architype& result, const big_number_backend_real_architype& b, const big_number_backend_real_architype& e) -{ - result = std::pow(b.m_value, e.m_value); -} - -inline void eval_pow(big_number_backend_real_architype& result, const big_number_backend_real_architype& b, int e) -{ - result = std::pow(b.m_value, e); -} - -inline void eval_exp(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::exp(arg.m_value); -} - -inline void eval_log(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::log(arg.m_value); -} - -inline void eval_sin(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::sin(arg.m_value); -} - -inline void eval_cos(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::cos(arg.m_value); -} - -inline void eval_tan(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::tan(arg.m_value); -} - -inline void eval_asin(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::asin(arg.m_value); -} - -inline void eval_acos(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::acos(arg.m_value); -} - -inline void eval_atan(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::atan(arg.m_value); -} - -inline void eval_sinh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::sinh(arg.m_value); -} - -inline void eval_cosh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::cosh(arg.m_value); -} - -inline void eval_tanh(big_number_backend_real_architype& result, const big_number_backend_real_architype& arg) -{ - result = std::tanh(arg.m_value); -} - -typedef boost::math::big_number big_number_real_architype; - -}}} // namespaces - -namespace std{ - -#ifdef BOOST_NO_NOEXCEPT -# define noexcept -#endif - -template <> -class numeric_limits : public std::numeric_limits -{ - typedef std::numeric_limits base_type; - typedef boost::math::concepts::big_number_real_architype number_type; -public: - BOOST_STATIC_CONSTEXPR number_type (min)() noexcept { return (base_type::min)(); } - BOOST_STATIC_CONSTEXPR number_type (max)() noexcept { return (base_type::max)(); } - BOOST_STATIC_CONSTEXPR number_type lowest() noexcept { return -(max)(); } - BOOST_STATIC_CONSTEXPR number_type epsilon() noexcept { return base_type::epsilon(); } - BOOST_STATIC_CONSTEXPR number_type round_error() noexcept { return epsilon() / 2; } - BOOST_STATIC_CONSTEXPR number_type infinity() noexcept { return base_type::infinity(); } - BOOST_STATIC_CONSTEXPR number_type quiet_NaN() noexcept { return base_type::quiet_NaN(); } - BOOST_STATIC_CONSTEXPR number_type signaling_NaN() noexcept { return base_type::signaling_NaN(); } - BOOST_STATIC_CONSTEXPR number_type denorm_min() noexcept { return base_type::denorm_min(); } -}; - -#ifdef BOOST_NO_NOEXCEPT -# undef noexcept -#endif - -} - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - -#endif