diff --git a/doc/multiprecision.qbk b/doc/multiprecision.qbk index 3c18dd73..677a5336 100644 --- a/doc/multiprecision.qbk +++ b/doc/multiprecision.qbk @@ -621,13 +621,13 @@ So for example, given an integer backend type `MyIntegerBackend`, the use would // swap: void swap(mp_number& other); // Sign: - bool is_zero()const; + bool eval_is_zero()const; int sign()const; // string conversion: std::string str()const; // Generic conversion mechanism template - T convert_to()const; + T eval_convert_to()const; // precision control: static unsigned default_precision(); static void default_precision(unsigned digits10); @@ -801,7 +801,7 @@ This operator also enables the use of `mp_number` with any of the following oper Swaps `*this` with `other`. - bool is_zero()const; + bool eval_is_zero()const; Returns `true` is `*this` is zero, otherwise `false`. @@ -816,7 +816,7 @@ Returns the number formatted as a string, with at least /precision/ digits, and if /scientific/ is true. template - T convert_to()const; + T eval_convert_to()const; Provides a generic conversion mechanism to convert `*this` to type `T`. Type `T` may be any arithmetic type. Optionally other types may also be supported by specific `Backend` types. @@ -1043,18 +1043,18 @@ of type B2. [[`cb.compare(a)`][`int`][Compares `cb` and `a`, returns a value less than zero if `cb < a`, a value greater than zero if `cb > a` and zero if `cb == a`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`add(b, cb)`][`void`][Adds `cb` to `b`.]] -[[`subtract(b, cb)`][`void`][Subtracts `cb` from `b`.]] -[[`multiply(b, cb)`][`void`][Multiplies `b` by `cb`.]] -[[`divide(b, cb)`][`void`][Divides `b` by `cb`.]] -[[`modulus(b, cb)`][`void`][Computes `b %= cb`, only required when `B` is an integer type.]] -[[`bitwise_and(b, cb)`][`void`][Computes `b &= cb`, only required when `B` is an integer type.]] -[[`bitwise_or(b, cb)`][`void`][Computes `b |= cb`, only required when `B` is an integer type.]] -[[`bitwise_xor(b, cb)`][`void`][Computes `b ^= cb`, only required when `B` is an integer type.]] -[[`complement(b, cb)`][`void`][Computes the ones-complement of `cb` and stores the result in `b`, only required when `B` is an integer type.]] -[[`left_shift(b, ui)`][`void`][Computes `b <<= ui`, only required when `B` is an integer type.]] -[[`right_shift(b, ui)`][`void`][Computes `b >>= ui`, only required when `B` is an integer type.]] -[[`convert_to(pa, cb)`][`void`][Converts `cb` to the type of `*pa` and store the result in `*pa`. Type `B` shall support +[[`eval_add(b, cb)`][`void`][Adds `cb` to `b`.]] +[[`eval_subtract(b, cb)`][`void`][Subtracts `cb` from `b`.]] +[[`eval_multiply(b, cb)`][`void`][Multiplies `b` by `cb`.]] +[[`eval_divide(b, cb)`][`void`][Divides `b` by `cb`.]] +[[`eval_modulus(b, cb)`][`void`][Computes `b %= cb`, only required when `B` is an integer type.]] +[[`eval_bitwise_and(b, cb)`][`void`][Computes `b &= cb`, only required when `B` is an integer type.]] +[[`eval_bitwise_or(b, cb)`][`void`][Computes `b |= cb`, only required when `B` is an integer type.]] +[[`eval_bitwise_xor(b, cb)`][`void`][Computes `b ^= cb`, only required when `B` is an integer type.]] +[[`eval_complement(b, cb)`][`void`][Computes the ones-complement of `cb` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_left_shift(b, ui)`][`void`][Computes `b <<= ui`, only required when `B` is an integer type.]] +[[`eval_right_shift(b, ui)`][`void`][Computes `b >>= ui`, only required when `B` is an integer type.]] +[[`eval_convert_to(pa, cb)`][`void`][Converts `cb` to the type of `*pa` and store the result in `*pa`. Type `B` shall support conversion to at least types `std::intmax_t`, `std::uintmax_t` and `long long`. Conversion to other arithmetic types can then be synthesised using other operations. Conversions to other types are entirely optional.]] @@ -1075,68 +1075,68 @@ of type B2. Only applies to rational and complex number types.]] [[`assign_components(b, b2, b2)`][`void`][Assigns to `b` the two components in the following arguments. Only applies to rational and complex number types.]] -[[`add(b, a)`][`void`][Adds `a` to `b`. The type of `a` shall be listed in one of the type lists +[[`eval_add(b, a)`][`void`][Adds `a` to `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`subtract(b, a)`][`void`][Subtracts `a` from `b`. The type of `a` shall be listed in one of the type lists +[[`eval_subtract(b, a)`][`void`][Subtracts `a` from `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`multiply(b, a)`][`void`][Multiplies `b` by `a`. The type of `a` shall be listed in one of the type lists +[[`eval_multiply(b, a)`][`void`][Multiplies `b` by `a`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`divide(b, a)`][`void`][Divides `b` by `a`. The type of `a` shall be listed in one of the type lists +[[`eval_divide(b, a)`][`void`][Divides `b` by `a`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`modulus(b, a)`][`void`][Computes `b %= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_modulus(b, a)`][`void`][Computes `b %= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_and(b, a)`][`void`][Computes `b &= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_and(b, a)`][`void`][Computes `b &= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_or(b, a)`][`void`][Computes `b |= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_or(b, a)`][`void`][Computes `b |= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_xor(b, a)`][`void`][Computes `b ^= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_xor(b, a)`][`void`][Computes `b ^= cb`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`add(b, cb, cb2)`][`void`][Add `cb` to `cb2` and stores the result in `b`.]] -[[`subtract(b, cb, cb2)`][`void`][Subtracts `cb2` from `cb` and stores the result in `b`.]] -[[`multiply(b, cb, cb2)`][`void`][Multiplies `cb` by `cb2` and stores the result in `b`.]] -[[`divide(b, cb, cb2)`][`void`][Divides `cb` by `cb2` and stores the result in `b`.]] -[[`add(b, cb, a)`][`void`][Add `cb` to `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_add(b, cb, cb2)`][`void`][Add `cb` to `cb2` and stores the result in `b`.]] +[[`eval_subtract(b, cb, cb2)`][`void`][Subtracts `cb2` from `cb` and stores the result in `b`.]] +[[`eval_multiply(b, cb, cb2)`][`void`][Multiplies `cb` by `cb2` and stores the result in `b`.]] +[[`eval_divide(b, cb, cb2)`][`void`][Divides `cb` by `cb2` and stores the result in `b`.]] +[[`eval_add(b, cb, a)`][`void`][Add `cb` to `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`subtract(b, cb, a)`][`void`][Subtracts `a` from `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_subtract(b, cb, a)`][`void`][Subtracts `a` from `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`multiply(b, cb, a)`][`void`][Multiplies `cb` by `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_multiply(b, cb, a)`][`void`][Multiplies `cb` by `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`divide(b, cb, a)`][`void`][Divides `cb` by `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_divide(b, cb, a)`][`void`][Divides `cb` by `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`modulus(b, cb, cb2)`][`void`][Computes `cb % cb2` and stores the result in `b`, only required when `B` is an integer type.]] -[[`bitwise_and(b, cb, cb2)`][`void`][Computes `cb & cb2` and stores the result in `b`, only required when `B` is an integer type.]] -[[`bitwise_or(b, cb, cb2)`][`void`][Computes `cb | cb2` and stores the result in `b`, only required when `B` is an integer type.]] -[[`bitwise_xor(b, cb, cb2)`][`void`][Computes `cb ^ cb2` and stores the result in `b`, only required when `B` is an integer type.]] -[[`add(b, a, cb)`][`void`][Add `a` to `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_modulus(b, cb, cb2)`][`void`][Computes `cb % cb2` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_bitwise_and(b, cb, cb2)`][`void`][Computes `cb & cb2` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_bitwise_or(b, cb, cb2)`][`void`][Computes `cb | cb2` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_bitwise_xor(b, cb, cb2)`][`void`][Computes `cb ^ cb2` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_add(b, a, cb)`][`void`][Add `a` to `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`subtract(b, a, cb)`][`void`][Subtracts `cb` from `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_subtract(b, a, cb)`][`void`][Subtracts `cb` from `a` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`multiply(b, a, cb)`][`void`][Multiplies `a` by `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_multiply(b, a, cb)`][`void`][Multiplies `a` by `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`divide(b, a, cb)`][`void`][Divides `a` by `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists +[[`eval_divide(b, a, cb)`][`void`][Divides `a` by `cb` and stores the result in `b`. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`modulus(b, cb, a)`][`void`][Computes `cb % a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_modulus(b, cb, a)`][`void`][Computes `cb % a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_and(b, cb, a)`][`void`][Computes `cb & a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_and(b, cb, a)`][`void`][Computes `cb & a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_or(b, cb, a)`][`void`][Computes `cb | a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_or(b, cb, a)`][`void`][Computes `cb | a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_xor(b, cb, a)`][`void`][Computes `cb ^ a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_xor(b, cb, a)`][`void`][Computes `cb ^ a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`modulus(b, a, cb)`][`void`][Computes `cb % a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_modulus(b, a, cb)`][`void`][Computes `cb % a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_and(b, a, cb)`][`void`][Computes `cb & a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_and(b, a, cb)`][`void`][Computes `cb & a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_or(b, a, cb)`][`void`][Computes `cb | a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_or(b, a, cb)`][`void`][Computes `cb | a` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`bitwise_xor(b, a, cb)`][`void`][Computes `a ^ cb` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists +[[`eval_bitwise_xor(b, a, cb)`][`void`][Computes `a ^ cb` and stores the result in `b`, only required when `B` is an integer type. The type of `a` shall be listed in one of the type lists `B::signed_types`, `B::unsigned_types` or `B::float_types`.]] -[[`left_shift(b, cb, ui)`][`void`][Computes `cb << ui` and stores the result in `b`, only required when `B` is an integer type.]] -[[`right_shift(b, cb, ui)`][`void`][Computes `cb >> ui` and stores the result in `b`, only required when `B` is an integer type.]] -[[`increment(b)`][void][Increments the value of `b` by one.]] -[[`decrement(b)`][void][Decrements the value of `b` by one.]] -[[`is_zero(cb)`][`bool`][Returns `true` if `cb` is zero, otherwise `false`]] -[[`get_sign(cb)`][`int`][Returns a value < zero if `cb` is negative, a value > zero if `cb` is positive, and zero if `cb` is zero.]] +[[`eval_left_shift(b, cb, ui)`][`void`][Computes `cb << ui` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_right_shift(b, cb, ui)`][`void`][Computes `cb >> ui` and stores the result in `b`, only required when `B` is an integer type.]] +[[`eval_increment(b)`][void][Increments the value of `b` by one.]] +[[`eval_decrement(b)`][void][Decrements the value of `b` by one.]] +[[`eval_is_zero(cb)`][`bool`][Returns `true` if `cb` is zero, otherwise `false`]] +[[`eval_get_sign(cb)`][`int`][Returns a value < zero if `cb` is negative, a value > zero if `cb` is positive, and zero if `cb` is zero.]] [[`eval_abs(b, cb)`][`void`][Set `b` to the absolute value of `cb`.]] [[`eval_fabs(b, cb)`][`void`][Set `b` to the absolute value of `cb`.]] [[`eval_fpclassify(cb)`][`int`][Returns one of the same values returned by `std::fpclassify`. Only required when `B` is an floating-point type.]] diff --git a/include/boost/multiprecision/arithmetic_backend.hpp b/include/boost/multiprecision/arithmetic_backend.hpp index 8225bd0e..5d9111b2 100644 --- a/include/boost/multiprecision/arithmetic_backend.hpp +++ b/include/boost/multiprecision/arithmetic_backend.hpp @@ -15,6 +15,7 @@ namespace boost{ namespace multiprecision{ +namespace backends{ template struct arithmetic_backend @@ -97,26 +98,30 @@ private: }; template -inline void add(arithmetic_backend& result, const arithmetic_backend& o) +inline void eval_add(arithmetic_backend& result, const arithmetic_backend& o) { result.data() += o.data(); } template -inline void subtract(arithmetic_backend& result, const arithmetic_backend& o) +inline void eval_subtract(arithmetic_backend& result, const arithmetic_backend& o) { result.data() -= o.data(); } template -inline void multiply(arithmetic_backend& result, const arithmetic_backend& o) +inline void eval_multiply(arithmetic_backend& result, const arithmetic_backend& o) { result.data() *= o.data(); } template -inline void divide(arithmetic_backend& result, const arithmetic_backend& o) +inline void eval_divide(arithmetic_backend& result, const arithmetic_backend& o) { result.data() /= o.data(); } +} // namespace backends + +using boost::multiprecision::backends::arithmetic_backend; + }} // namespaces diff --git a/include/boost/multiprecision/concepts/mp_number_architypes.hpp b/include/boost/multiprecision/concepts/mp_number_architypes.hpp index 61de59c7..72e97842 100644 --- a/include/boost/multiprecision/concepts/mp_number_architypes.hpp +++ b/include/boost/multiprecision/concepts/mp_number_architypes.hpp @@ -122,36 +122,36 @@ struct mp_number_backend_float_architype long double m_value; }; -inline void add(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) +inline void eval_add(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) { std::cout << "Addition (" << result.m_value << " += " << o.m_value << ")" << std::endl; result.m_value += o.m_value; } -inline void subtract(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) +inline void eval_subtract(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) { std::cout << "Subtraction (" << result.m_value << " -= " << o.m_value << ")" << std::endl; result.m_value -= o.m_value; } -inline void multiply(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) +inline void eval_multiply(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) { std::cout << "Multiplication (" << result.m_value << " *= " << o.m_value << ")" << std::endl; result.m_value *= o.m_value; } -inline void divide(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) +inline void eval_divide(mp_number_backend_float_architype& result, const mp_number_backend_float_architype& o) { std::cout << "Division (" << result.m_value << " /= " << o.m_value << ")" << std::endl; result.m_value /= o.m_value; } -inline void convert_to(unsigned long long* result, const mp_number_backend_float_architype& val) +inline void eval_convert_to(unsigned long long* result, const mp_number_backend_float_architype& val) { *result = static_cast(val.m_value); } -inline void convert_to(long long* result, const mp_number_backend_float_architype& val) +inline void eval_convert_to(long long* result, const mp_number_backend_float_architype& val) { *result = static_cast(val.m_value); } -inline void convert_to(long double* result, mp_number_backend_float_architype& val) +inline void eval_convert_to(long double* result, mp_number_backend_float_architype& val) { *result = val.m_value; } diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp index dfe947ae..a77dcc3b 100644 --- a/include/boost/multiprecision/cpp_dec_float.hpp +++ b/include/boost/multiprecision/cpp_dec_float.hpp @@ -24,6 +24,7 @@ namespace boost{ namespace multiprecision{ +namespace backends{ template class cpp_dec_float @@ -2535,49 +2536,49 @@ cpp_dec_float cpp_dec_float::pow2(const long long p) template -inline void add(cpp_dec_float& result, const cpp_dec_float& o) +inline void eval_add(cpp_dec_float& result, const cpp_dec_float& o) { result += o; } template -inline void subtract(cpp_dec_float& result, const cpp_dec_float& o) +inline void eval_subtract(cpp_dec_float& result, const cpp_dec_float& o) { result -= o; } template -inline void multiply(cpp_dec_float& result, const cpp_dec_float& o) +inline void eval_multiply(cpp_dec_float& result, const cpp_dec_float& o) { result *= o; } template -inline void divide(cpp_dec_float& result, const cpp_dec_float& o) +inline void eval_divide(cpp_dec_float& result, const cpp_dec_float& o) { result /= o; } template -inline void add(cpp_dec_float& result, const unsigned long long& o) +inline void eval_add(cpp_dec_float& result, const unsigned long long& o) { result.add_unsigned_long_long(o); } template -inline void subtract(cpp_dec_float& result, const unsigned long long& o) +inline void eval_subtract(cpp_dec_float& result, const unsigned long long& o) { result.sub_unsigned_long_long(o); } template -inline void multiply(cpp_dec_float& result, const unsigned long long& o) +inline void eval_multiply(cpp_dec_float& result, const unsigned long long& o) { result.mul_unsigned_long_long(o); } template -inline void divide(cpp_dec_float& result, const unsigned long long& o) +inline void eval_divide(cpp_dec_float& result, const unsigned long long& o) { result.div_unsigned_long_long(o); } template -inline void add(cpp_dec_float& result, long long o) +inline void eval_add(cpp_dec_float& result, long long o) { if(o < 0) result.sub_unsigned_long_long(-o); @@ -2585,7 +2586,7 @@ inline void add(cpp_dec_float& result, long long o) result.add_unsigned_long_long(o); } template -inline void subtract(cpp_dec_float& result, long long o) +inline void eval_subtract(cpp_dec_float& result, long long o) { if(o < 0) result.add_unsigned_long_long(-o); @@ -2593,7 +2594,7 @@ inline void subtract(cpp_dec_float& result, long long o) result.sub_unsigned_long_long(o); } template -inline void multiply(cpp_dec_float& result, long long o) +inline void eval_multiply(cpp_dec_float& result, long long o) { if(o < 0) { @@ -2604,7 +2605,7 @@ inline void multiply(cpp_dec_float& result, long long o) result.mul_unsigned_long_long(o); } template -inline void divide(cpp_dec_float& result, long long o) +inline void eval_divide(cpp_dec_float& result, long long o) { if(o < 0) { @@ -2616,17 +2617,17 @@ inline void divide(cpp_dec_float& result, long long o) } template -inline void convert_to(unsigned long long* result, const cpp_dec_float& val) +inline void eval_convert_to(unsigned long long* result, const cpp_dec_float& val) { *result = val.extract_unsigned_long_long(); } template -inline void convert_to(long long* result, const cpp_dec_float& val) +inline void eval_convert_to(long long* result, const cpp_dec_float& val) { *result = val.extract_signed_long_long(); } template -inline void convert_to(long double* result, cpp_dec_float& val) +inline void eval_convert_to(long double* result, cpp_dec_float& val) { *result = val.extract_long_double(); } @@ -2799,16 +2800,20 @@ inline void eval_frexp(cpp_dec_float& result, const cpp_dec_float -inline bool is_zero(const cpp_dec_float& val) +inline bool eval_is_zero(const cpp_dec_float& val) { return val.iszero(); } template -inline int get_sign(const cpp_dec_float& val) +inline int eval_get_sign(const cpp_dec_float& val) { return val.iszero() ? 0 : val.isneg() ? -1 : 1; } +} // namespace backends + +using boost::multiprecision::backends::cpp_dec_float; + typedef mp_number > cpp_dec_float_50; typedef mp_number > cpp_dec_float_100; diff --git a/include/boost/multiprecision/cpp_int.hpp b/include/boost/multiprecision/cpp_int.hpp index a6f38a98..65f5eb3b 100644 --- a/include/boost/multiprecision/cpp_int.hpp +++ b/include/boost/multiprecision/cpp_int.hpp @@ -18,6 +18,7 @@ namespace boost{ namespace multiprecision{ +namespace backends{ template > struct cpp_int_backend; @@ -338,7 +339,7 @@ public: for(i = 0; i < internal_limb_count; ++i) m_data[i] = ~m_data[i]; normalize(); - increment(static_cast& >(*this)); + eval_increment(static_cast& >(*this)); } bool isneg()const { @@ -451,8 +452,8 @@ public: cpp_int_backend& operator = (long double a) { - using default_ops::add; - using default_ops::subtract; + using default_ops::eval_add; + using default_ops::eval_subtract; using std::frexp; using std::ldexp; using std::floor; @@ -482,23 +483,23 @@ public: f = ldexp(f, shift); term = floor(f); e -= shift; - left_shift(*this, shift); + eval_left_shift(*this, shift); if(term > 0) - add(*this, static_cast(term)); + eval_add(*this, static_cast(term)); else - subtract(*this, static_cast(-term)); + eval_subtract(*this, static_cast(-term)); f -= term; } if(e > 0) - left_shift(*this, e); + eval_left_shift(*this, e); else if(e < 0) - right_shift(*this, -e); + eval_right_shift(*this, -e); return *this; } cpp_int_backend& operator = (const char* s) { - using default_ops::multiply; - using default_ops::add; + using default_ops::eval_multiply; + using default_ops::eval_add; std::size_t n = s ? std::strlen(s) : 0; *this = static_cast(0u); unsigned radix = 10; @@ -557,7 +558,7 @@ public: break; } } - left_shift(*this, block_shift); + eval_left_shift(*this, block_shift); this->limbs()[0] |= block; } } @@ -584,8 +585,8 @@ public: break; } } - multiply(*this, block_mult); - add(*this, block); + eval_multiply(*this, block_mult); + eval_add(*this, block); } } } @@ -623,7 +624,7 @@ public: if(c > '9') c += 'A' - '9' - 1; result[pos--] = c; - right_shift(t, shift); + eval_right_shift(t, shift); } if(Bits % shift) { @@ -666,7 +667,7 @@ public: { cpp_int_backend block10; block10 = max_block_10; - while(get_sign(t) != 0) + while(eval_get_sign(t) != 0) { cpp_int_backend t2; divide_unsigned_helper(t2, t, block10, r); @@ -732,9 +733,9 @@ public: template -inline void add(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_add(cpp_int_backend& result, const cpp_int_backend& o) { - add(result, result, o); + eval_add(result, result, o); } template inline void add_unsigned(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) @@ -795,7 +796,7 @@ inline void add_unsigned(cpp_int_backend& result, co result.sign(a.sign()); } template -inline void add(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) +inline void eval_add(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { if(a.sign() != b.sign()) { @@ -829,7 +830,7 @@ inline void add_unsigned(cpp_int_backend& result, co result.normalize(); } template -inline void add(cpp_int_backend& result, const limb_type& o) +inline void eval_add(cpp_int_backend& result, const limb_type& o) { if(result.sign()) { @@ -839,12 +840,12 @@ inline void add(cpp_int_backend& result, const limb_ add_unsigned(result, o); } template -inline void add(cpp_int_backend& result, const signed_limb_type& o) +inline void eval_add(cpp_int_backend& result, const signed_limb_type& o) { if(o < 0) - subtract(result, static_cast(-o)); + eval_subtract(result, static_cast(-o)); else if(o > 0) - add(result, static_cast(o)); + eval_add(result, static_cast(o)); } template @@ -877,7 +878,7 @@ inline void subtract_unsigned(cpp_int_backend& resul } } template -inline void subtract(cpp_int_backend& result, const limb_type& o) +inline void eval_subtract(cpp_int_backend& result, const limb_type& o) { if(result.sign()) add_unsigned(result, o); @@ -885,18 +886,18 @@ inline void subtract(cpp_int_backend& result, const subtract_unsigned(result, o); } template -inline void subtract(cpp_int_backend& result, const signed_limb_type& o) +inline void eval_subtract(cpp_int_backend& result, const signed_limb_type& o) { if(o) { if(o < 0) - add(result, static_cast(-o)); + eval_add(result, static_cast(-o)); else - subtract(result, static_cast(o)); + eval_subtract(result, static_cast(o)); } } template -inline void increment(cpp_int_backend& result) +inline void eval_increment(cpp_int_backend& result) { static const limb_type one = 1; if(!result.sign() && (result.limbs()[0] < cpp_int_backend::max_limb_value)) @@ -904,10 +905,10 @@ inline void increment(cpp_int_backend& result) else if(result.sign() && result.limbs()[0]) --result.limbs()[0]; else - add(result, one); + eval_add(result, one); } template -inline void decrement(cpp_int_backend& result) +inline void eval_decrement(cpp_int_backend& result) { static const limb_type one = 1; if(!result.sign() && result.limbs()[0]) @@ -915,12 +916,12 @@ inline void decrement(cpp_int_backend& result) else if(result.sign() && (result.limbs()[0] < cpp_int_backend::max_limb_value)) ++result.limbs()[0]; else - subtract(result, one); + eval_subtract(result, one); } template -inline void subtract(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_subtract(cpp_int_backend& result, const cpp_int_backend& o) { - subtract(result, result, o); + eval_subtract(result, result, o); } template inline void subtract_unsigned(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) @@ -996,7 +997,7 @@ inline void subtract_unsigned(cpp_int_backend& resul result.negate(); } template -inline void subtract(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) +inline void eval_subtract(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { if(a.sign() != b.sign()) { @@ -1006,7 +1007,7 @@ inline void subtract(cpp_int_backend& result, const subtract_unsigned(result, a, b); } template -inline void multiply(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) +inline void eval_multiply(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { // Very simple long multiplication, only usable for small numbers of limb_type's // but that's the typical use case for this type anyway: @@ -1028,7 +1029,7 @@ inline void multiply(cpp_int_backend& result, const { limb_type l = *pa; result = b; - multiply(result, l); + eval_multiply(result, l); } result.sign(s); return; @@ -1038,7 +1039,7 @@ inline void multiply(cpp_int_backend& result, const limb_type l = *pb; bool s = b.sign() != a.sign(); result = a; - multiply(result, l); + eval_multiply(result, l); result.sign(s); return; } @@ -1046,13 +1047,13 @@ inline void multiply(cpp_int_backend& result, const if(&result == &a) { cpp_int_backend t(a); - multiply(result, t, b); + eval_multiply(result, t, b); return; } if(&result == &b) { cpp_int_backend t(b); - multiply(result, a, t); + eval_multiply(result, a, t); return; } @@ -1063,7 +1064,7 @@ inline void multiply(cpp_int_backend& result, const std::memset(pr, 0, result.size() * sizeof(limb_type)); for(unsigned i = 0; i < as; ++i) { - unsigned inner_limit = (std::min)(result.size() - i, b.size()); + unsigned inner_limit = cpp_int_backend::variable ? bs : (std::min)(result.size() - i, bs); for(unsigned j = 0; j < inner_limit; ++j) { BOOST_ASSERT(i+j < result.size()); @@ -1083,12 +1084,12 @@ inline void multiply(cpp_int_backend& result, const result.sign(a.sign() != b.sign()); } template -inline void multiply(cpp_int_backend& result, const cpp_int_backend& a) +inline void eval_multiply(cpp_int_backend& result, const cpp_int_backend& a) { - multiply(result, result, a); + eval_multiply(result, result, a); } template -inline void multiply(cpp_int_backend& result, cpp_int_backend& a, const limb_type& val) +inline void eval_multiply(cpp_int_backend& result, cpp_int_backend& a, const limb_type& val) { if(!val) { @@ -1117,25 +1118,25 @@ inline void multiply(cpp_int_backend& result, cpp_in result.normalize(); } template -inline void multiply(cpp_int_backend& result, const limb_type& val) +inline void eval_multiply(cpp_int_backend& result, const limb_type& val) { - multiply(result, result, val); + eval_multiply(result, result, val); } template -inline void multiply(cpp_int_backend& result, cpp_int_backend& a, const signed_limb_type& val) +inline void eval_multiply(cpp_int_backend& result, cpp_int_backend& a, const signed_limb_type& val) { if(val > 0) - multiply(result, a, static_cast(val)); + eval_multiply(result, a, static_cast(val)); else { - multiply(result, a, static_cast(-val)); + eval_multiply(result, a, static_cast(-val)); result.negate(); } } template -inline void multiply(cpp_int_backend& result, const signed_limb_type& val) +inline void eval_multiply(cpp_int_backend& result, const signed_limb_type& val) { - multiply(result, result, val); + eval_multiply(result, result, val); } template void divide_unsigned_helper(cpp_int_backend& result, const cpp_int_backend& x, const cpp_int_backend& y, cpp_int_backend& r) @@ -1172,7 +1173,7 @@ void divide_unsigned_helper(cpp_int_backend& result, */ - using default_ops::subtract; + using default_ops::eval_subtract; if(&result == &r) { @@ -1306,7 +1307,7 @@ void divide_unsigned_helper(cpp_int_backend& result, t.limbs()[shift] = guess; for(unsigned i = 0; i < shift; ++i) t.limbs()[i] = 0; - subtract(result, t); + eval_subtract(result, t); } } else if(cpp_int_backend::max_limb_value - pr[shift] > guess) @@ -1317,7 +1318,7 @@ void divide_unsigned_helper(cpp_int_backend& result, t.limbs()[shift] = guess; for(unsigned i = 0; i < shift; ++i) t.limbs()[i] = 0; - add(result, t); + eval_add(result, t); } // // Calculate guess * y, we use a fused mutiply-shift O(N) for this @@ -1346,7 +1347,7 @@ void divide_unsigned_helper(cpp_int_backend& result, // // Update r: // - subtract(r, t); + eval_subtract(r, t); if(r.isneg()) { r.negate(); @@ -1376,15 +1377,15 @@ void divide_unsigned_helper(cpp_int_backend& result, // // We now just have to normalise the result: // - if(r_neg && get_sign(r)) + if(r_neg && eval_get_sign(r)) { // We have one too many in the result: - decrement(result); + eval_decrement(result); r.negate(); if(y.sign()) - subtract(r, y); + eval_subtract(r, y); else - add(r, y); + eval_add(r, y); } BOOST_ASSERT(r.compare_unsigned(y) < 0); // remainder must be less than the divisor or our code has failed @@ -1410,7 +1411,7 @@ void divide_unsigned_helper(cpp_int_backend& result, // As above, but simplified for integer divisor: - using default_ops::subtract; + using default_ops::eval_subtract; if(y == 0) { @@ -1514,20 +1515,20 @@ void divide_unsigned_helper(cpp_int_backend& result, } template -inline void divide(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) +inline void eval_divide(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { cpp_int_backend r; divide_unsigned_helper(result, a, b, r); result.sign(a.sign() != b.sign()); } template -inline void divide(cpp_int_backend& result, const cpp_int_backend& a, limb_type& b) +inline void eval_divide(cpp_int_backend& result, const cpp_int_backend& a, limb_type& b) { cpp_int_backend r; divide_unsigned_helper(result, a, b, r); } template -inline void divide(cpp_int_backend& result, const cpp_int_backend& a, signed_limb_type& b) +inline void eval_divide(cpp_int_backend& result, const cpp_int_backend& a, signed_limb_type& b) { cpp_int_backend r; divide_unsigned_helper(result, a, std::abs(b), r); @@ -1535,65 +1536,65 @@ inline void divide(cpp_int_backend& result, const cp result.negate(); } template -inline void divide(cpp_int_backend& result, const cpp_int_backend& b) +inline void eval_divide(cpp_int_backend& result, const cpp_int_backend& b) { // There is no in place divide: cpp_int_backend a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void divide(cpp_int_backend& result, limb_type b) +inline void eval_divide(cpp_int_backend& result, limb_type b) { // There is no in place divide: cpp_int_backend a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void divide(cpp_int_backend& result, signed_limb_type b) +inline void eval_divide(cpp_int_backend& result, signed_limb_type b) { // There is no in place divide: cpp_int_backend a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void modulus(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) +inline void eval_modulus(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { cpp_int_backend r; divide_unsigned_helper(r, a, b, result); result.sign(a.sign()); } template -inline void modulus(cpp_int_backend& result, const cpp_int_backend& a, limb_type b) +inline void eval_modulus(cpp_int_backend& result, const cpp_int_backend& a, limb_type b) { cpp_int_backend r; divide_unsigned_helper(r, a, b, result); } template -inline void modulus(cpp_int_backend& result, const cpp_int_backend& a, signed_limb_type b) +inline void eval_modulus(cpp_int_backend& result, const cpp_int_backend& a, signed_limb_type b) { cpp_int_backend r; divide_unsigned_helper(r, a, static_cast(std::abs(b)), result); } template -inline void modulus(cpp_int_backend& result, const cpp_int_backend& b) +inline void eval_modulus(cpp_int_backend& result, const cpp_int_backend& b) { // There is no in place divide: cpp_int_backend a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template -inline void modulus(cpp_int_backend& result, limb_type b) +inline void eval_modulus(cpp_int_backend& result, limb_type b) { // There is no in place divide: cpp_int_backend a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template -inline void modulus(cpp_int_backend& result, signed_limb_type b) +inline void eval_modulus(cpp_int_backend& result, signed_limb_type b) { // There is no in place divide: cpp_int_backend a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template void bitwise_op(cpp_int_backend& result, const cpp_int_backend& o, Op op) @@ -1726,20 +1727,20 @@ struct bit_or{ limb_type operator()(limb_type a, limb_type b)const{ return a | b struct bit_xor{ limb_type operator()(limb_type a, limb_type b)const{ return a ^ b; } }; template -inline void bitwise_and(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_bitwise_and(cpp_int_backend& result, const cpp_int_backend& o) { bitwise_op(result, o, bit_and()); } #if 0 template -inline void bitwise_and(cpp_int_backend& result, limb_type o) +inline void eval_bitwise_and(cpp_int_backend& result, limb_type o) { result.data()[cpp_int_backend::limb_count - 1] &= o; for(typename cpp_int_backend::data_type::size_type i = 0; i < cpp_int_backend::limb_count - 1; ++i) result.data()[i] = 0; } template -inline void bitwise_and(cpp_int_backend& result, signed_limb_type o) +inline void eval_bitwise_and(cpp_int_backend& result, signed_limb_type o) { result.data()[cpp_int_backend::limb_count - 1] &= o; limb_type mask = o < 0 ? cpp_int_backend::max_limb_value : 0; @@ -1747,35 +1748,35 @@ inline void bitwise_and(cpp_int_backend& result, sig result.data()[i] &= mask; } template -inline void bitwise_or(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_bitwise_or(cpp_int_backend& result, const cpp_int_backend& o) { for(typename cpp_int_backend::data_type::size_type i = 0; i < cpp_int_backend::limb_count; ++i) result.data()[i] |= o.data()[i]; } template -inline void bitwise_or(cpp_int_backend& result, limb_type o) +inline void eval_bitwise_or(cpp_int_backend& result, limb_type o) { result.data()[cpp_int_backend::limb_count - 1] |= o; } #endif template -inline void bitwise_or(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_bitwise_or(cpp_int_backend& result, const cpp_int_backend& o) { bitwise_op(result, o, bit_or()); } template -inline void bitwise_xor(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_bitwise_xor(cpp_int_backend& result, const cpp_int_backend& o) { bitwise_op(result, o, bit_xor()); } #if 0 template -inline void bitwise_xor(cpp_int_backend& result, limb_type o) +inline void eval_bitwise_xor(cpp_int_backend& result, limb_type o) { result.data()[cpp_int_backend::limb_count - 1] ^= o; } template -inline void bitwise_xor(cpp_int_backend& result, signed_limb_type o) +inline void eval_bitwise_xor(cpp_int_backend& result, signed_limb_type o) { result.data()[cpp_int_backend::limb_count - 1] ^= o; limb_type mask = o < 0 ? cpp_int_backend::max_limb_value : 0; @@ -1784,15 +1785,15 @@ inline void bitwise_xor(cpp_int_backend& result, sig } #endif template -inline void complement(cpp_int_backend& result, const cpp_int_backend& o) +inline void eval_complement(cpp_int_backend& result, const cpp_int_backend& o) { // Increment and negate: result = o; - increment(result); + eval_increment(result); result.negate(); } template -inline void left_shift(cpp_int_backend& result, double_limb_type s) +inline void eval_left_shift(cpp_int_backend& result, double_limb_type s) { if(!s) return; @@ -1868,7 +1869,7 @@ inline void left_shift(cpp_int_backend& result, double_li } } template -inline void left_shift(cpp_int_backend& result, double_limb_type s) +inline void eval_left_shift(cpp_int_backend& result, double_limb_type s) { if(!s) return; @@ -1925,7 +1926,7 @@ inline void left_shift(cpp_int_backend& result, doub } } template -inline void right_shift(cpp_int_backend& result, double_limb_type s) +inline void eval_right_shift(cpp_int_backend& result, double_limb_type s) { if(!s) return; @@ -1979,7 +1980,7 @@ inline Integer negate_integer(Integer i, const mpl::false_&) } template -inline typename enable_if, void>::type convert_to(R* result, const cpp_int_backend& backend) +inline typename enable_if, void>::type eval_convert_to(R* result, const cpp_int_backend& backend) { *result = static_cast(backend.limbs()[0]); unsigned shift = cpp_int_backend::limb_bits; @@ -1997,7 +1998,7 @@ inline typename enable_if, void>::type convert_to(R* result, cons } template -inline typename enable_if, void>::type convert_to(R* result, const cpp_int_backend& backend) +inline typename enable_if, void>::type eval_convert_to(R* result, const cpp_int_backend& backend) { typename cpp_int_backend::const_limb_pointer p = backend.limbs(); unsigned shift = cpp_int_backend::limb_bits; @@ -2012,24 +2013,23 @@ inline typename enable_if, void>::type convert_to(R* result } template -inline bool is_zero(const cpp_int_backend& val) +inline bool eval_is_zero(const cpp_int_backend& val) { return (val.size() == 1) && (val.limbs()[0] == 0); } template -inline int get_sign(const cpp_int_backend& val) +inline int eval_get_sign(const cpp_int_backend& val) { - return is_zero(val) ? 0 : val.sign() ? -1 : 1; + return eval_is_zero(val) ? 0 : val.sign() ? -1 : 1; } -namespace detail{ // // Get the location of the least-significant-bit: // template inline unsigned get_lsb(const cpp_int_backend& a) { - BOOST_ASSERT(get_sign(a) != 0); + BOOST_ASSERT(eval_get_sign(a) != 0); unsigned result = 0; // @@ -2051,8 +2051,6 @@ inline unsigned get_lsb(const cpp_int_backend& a) return result + index * cpp_int_backend::limb_bits; } -} - template inline void eval_gcd(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { @@ -2060,7 +2058,7 @@ inline void eval_gcd(cpp_int_backend& result, const cpp_int_backend u(a), v(b); - int s = get_sign(u); + int s = eval_get_sign(u); /* GCD(0,x) := x */ if(s < 0) @@ -2072,7 +2070,7 @@ inline void eval_gcd(cpp_int_backend& result, const result = v; return; } - s = get_sign(v); + s = eval_get_sign(v); if(s < 0) { v.negate(); @@ -2086,11 +2084,11 @@ inline void eval_gcd(cpp_int_backend& result, const /* Let shift := lg K, where K is the greatest power of 2 dividing both u and v. */ - unsigned us = detail::get_lsb(u); - unsigned vs = detail::get_lsb(v); + unsigned us = get_lsb(u); + unsigned vs = get_lsb(v); shift = (std::min)(us, vs); - right_shift(u, us); - right_shift(v, vs); + eval_right_shift(u, us); + eval_right_shift(v, vs); do { @@ -2098,19 +2096,19 @@ inline void eval_gcd(cpp_int_backend& result, const Let u = min(u, v), v = diff(u, v)/2. */ if(u.compare(v) > 0) u.swap(v); - subtract(v, u); + eval_subtract(v, u); // Termination condition tries not to do a full compare if possible: - if(!v.limbs()[0] && is_zero(v)) + if(!v.limbs()[0] && eval_is_zero(v)) break; - vs = detail::get_lsb(v); - right_shift(v, vs); + vs = get_lsb(v); + eval_right_shift(v, vs); BOOST_ASSERT((v.limbs()[0] & 1)); BOOST_ASSERT((u.limbs()[0] & 1)); } while(true); result = u; - left_shift(result, shift); + eval_left_shift(result, shift); } template @@ -2119,19 +2117,23 @@ inline void eval_lcm(cpp_int_backend& result, const cpp_int_backend t; eval_gcd(t, a, b); - if(is_zero(t)) + if(eval_is_zero(t)) { result = static_cast(0); } else { - divide(result, a, t); - multiply(result, b); + eval_divide(result, a, t); + eval_multiply(result, b); } - if(get_sign(result) < 0) + if(eval_get_sign(result) < 0) result.negate(); } +} // namespace backends; + +using boost::multiprecision::backends::cpp_int_backend; + template struct number_category > : public mpl::int_{}; diff --git a/include/boost/multiprecision/detail/default_ops.hpp b/include/boost/multiprecision/detail/default_ops.hpp index 4f098147..6a7dfc67 100644 --- a/include/boost/multiprecision/detail/default_ops.hpp +++ b/include/boost/multiprecision/detail/default_ops.hpp @@ -32,76 +32,76 @@ namespace boost{ namespace multiprecision{ namespace default_ops{ // template inline typename enable_if, is_convertible, is_same > >::type - add(T& result, V const& v) + eval_add(T& result, V const& v) { T t; t = v; - add(result, t); + eval_add(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - subtract(T& result, V const& v) + eval_subtract(T& result, V const& v) { T t; t = v; - subtract(result, t); + eval_subtract(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - multiply(T& result, V const& v) + eval_multiply(T& result, V const& v) { T t; t = v; - multiply(result, t); + eval_multiply(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - divide(T& result, V const& v) + eval_divide(T& result, V const& v) { T t; t = v; - divide(result, t); + eval_divide(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - modulus(T& result, V const& v) + eval_modulus(T& result, V const& v) { T t; t = v; - modulus(result, t); + eval_modulus(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - bitwise_and(T& result, V const& v) + eval_bitwise_and(T& result, V const& v) { T t; t = v; - bitwise_and(result, t); + eval_bitwise_and(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - bitwise_or(T& result, V const& v) + eval_bitwise_or(T& result, V const& v) { T t; t = v; - bitwise_or(result, t); + eval_bitwise_or(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - bitwise_xor(T& result, V const& v) + eval_bitwise_xor(T& result, V const& v) { T t; t = v; - bitwise_xor(result, t); + eval_bitwise_xor(result, t); } template inline typename enable_if, is_convertible, is_same > >::type - complement(T& result, V const& v) + eval_complement(T& result, V const& v) { T t; t = v; - complement(result, t); + eval_complement(result, t); } template @@ -115,196 +115,196 @@ inline bool is_same_object(const T& u, const U&v) // 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) +inline void eval_add(T& t, const U& u, const V& v) { if(is_same_object(t, v)) { - add(t, u); + eval_add(t, u); } else if(is_same_object(t, u)) { - add(t, v); + eval_add(t, v); } else { t = u; - add(t, v); + eval_add(t, v); } } template -inline typename disable_if >::type add(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_add(T& t, const U& a, const T& b) { - return add(t, b, a); + return eval_add(t, b, a); } template -inline void subtract(T& t, const U& u, const V& v) +inline void eval_subtract(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - subtract(t, v); + eval_subtract(t, v); else if(is_same_object(t, v)) { - subtract(t, u); + eval_subtract(t, u); t.negate(); } else { t = u; - subtract(t, v); + eval_subtract(t, v); } } template -inline typename disable_if >::type subtract(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_subtract(T& t, const U& a, const T& b) { - subtract(t, b, a); + eval_subtract(t, b, a); t.negate(); } template -inline void multiply(T& t, const U& u, const V& v) +inline void eval_multiply(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - multiply(t, v); + eval_multiply(t, v); else if(is_same_object(t, v)) - multiply(t, u); + eval_multiply(t, u); else { t = u; - multiply(t, v); + eval_multiply(t, v); } } template -inline typename disable_if >::type multiply(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_multiply(T& t, const U& a, const T& b) { - multiply(t, b, a); + eval_multiply(t, b, a); } template -inline void divide(T& t, const U& u, const V& v) +inline void eval_divide(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - divide(t, v); + eval_divide(t, v); else if(is_same_object(t, v)) { T temp = t; - divide(temp, u, v); + eval_divide(temp, u, v); temp.swap(t); } else { t = u; - divide(t, v); + eval_divide(t, v); } } template -inline void modulus(T& t, const U& u, const V& v) +inline void eval_modulus(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - modulus(t, v); + eval_modulus(t, v); else if(is_same_object(t, v)) { T temp; - modulus(temp, u, v); + eval_modulus(temp, u, v); temp.swap(t); } else { t = u; - modulus(t, v); + eval_modulus(t, v); } } template -inline void bitwise_and(T& t, const U& u, const V& v) +inline void eval_bitwise_and(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - bitwise_and(t, v); + eval_bitwise_and(t, v); else if(is_same_object(t, v)) - bitwise_and(t, u); + eval_bitwise_and(t, u); else { t = u; - bitwise_and(t, v); + eval_bitwise_and(t, v); } } template -inline typename disable_if >::type bitwise_and(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_bitwise_and(T& t, const U& a, const T& b) { - bitwise_and(t, b, a); + eval_bitwise_and(t, b, a); } template -inline void bitwise_or(T& t, const U& u, const V& v) +inline void eval_bitwise_or(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - bitwise_or(t, v); + eval_bitwise_or(t, v); else if(is_same_object(t, v)) - bitwise_or(t, u); + eval_bitwise_or(t, u); else { t = u; - bitwise_or(t, v); + eval_bitwise_or(t, v); } } template -inline typename disable_if >::type bitwise_or(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_bitwise_or(T& t, const U& a, const T& b) { - bitwise_or(t, b, a); + eval_bitwise_or(t, b, a); } template -inline void bitwise_xor(T& t, const U& u, const V& v) +inline void eval_bitwise_xor(T& t, const U& u, const V& v) { if(is_same_object(t, u)) - bitwise_xor(t, v); + eval_bitwise_xor(t, v); else if(is_same_object(t, v)) - bitwise_xor(t, u); + eval_bitwise_xor(t, u); else { t = u; - bitwise_xor(t, v); + eval_bitwise_xor(t, v); } } template -inline typename disable_if >::type bitwise_xor(T& t, const U& a, const T& b) +inline typename disable_if >::type eval_bitwise_xor(T& t, const U& a, const T& b) { - bitwise_xor(t, b, a); + eval_bitwise_xor(t, b, a); } template -inline void increment(T& val) +inline void eval_increment(T& val) { typedef typename mpl::front::type ui_type; - add(val, static_cast(1u)); + eval_add(val, static_cast(1u)); } template -inline void decrement(T& val) +inline void eval_decrement(T& val) { typedef typename mpl::front::type ui_type; - subtract(val, static_cast(1u)); + eval_subtract(val, static_cast(1u)); } template -inline void left_shift(T& result, const T& arg, const V val) +inline void eval_left_shift(T& result, const T& arg, const V val) { result = arg; - left_shift(result, val); + eval_left_shift(result, val); } template -inline void right_shift(T& result, const T& arg, const V val) +inline void eval_right_shift(T& result, const T& arg, const V val) { result = arg; - right_shift(result, val); + eval_right_shift(result, val); } template -inline bool is_zero(const T& val) +inline bool eval_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) +inline int eval_get_sign(const T& val) { typedef typename mpl::front::type ui_type; return val.compare(static_cast(0)); @@ -316,7 +316,7 @@ inline void assign_components_imp(T& result, const V& v1, const V& v2, const mpl result = v1; T t; t = v2; - divide(result, t); + eval_divide(result, t); } template @@ -367,11 +367,11 @@ struct calculate_next_larger_type }; template -inline void convert_to(R* result, const B& backend) +inline void eval_convert_to(R* result, const B& backend) { typedef typename calculate_next_larger_type::type next_type; next_type n; - convert_to(&n, backend); + eval_convert_to(&n, backend); if(std::numeric_limits::is_specialized && (n > (std::numeric_limits::max)())) { *result = (std::numeric_limits::max)(); @@ -381,7 +381,7 @@ inline void convert_to(R* result, const B& backend) } template -inline void convert_to(terminal* result, const B& backend) +inline void eval_convert_to(terminal* result, const B& backend) { // // We ran out of types to try for the convertion, try @@ -417,7 +417,7 @@ template inline int eval_fpclassify(const Backend& arg) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_floating_point, "The fpclassify function is only valid for floating point types."); - return is_zero(arg) ? FP_ZERO : FP_NORMAL; + return eval_is_zero(arg) ? FP_ZERO : FP_NORMAL; } template @@ -432,13 +432,13 @@ inline void eval_fmod(T& result, const T& a, const T& b) return; } T n; - divide(result, a, b); - if(get_sign(a) < 0) + eval_divide(result, a, b); + if(eval_get_sign(a) < 0) eval_ceil(n, result); else eval_floor(n, result); - multiply(n, b); - subtract(result, a, n); + eval_multiply(n, b); + eval_subtract(result, a, n); } template inline void eval_trunc(T& result, const T& a) @@ -450,7 +450,7 @@ inline void eval_trunc(T& result, const T& a) result = boost::math::policies::raise_rounding_error("boost::multiprecision::trunc<%1%>(%1%)", 0, mp_number(a), 0, boost::math::policies::policy<>()).backend(); return; } - if(get_sign(a) < 0) + if(eval_get_sign(a) < 0) eval_ceil(result, a); else eval_floor(result, a); @@ -467,14 +467,14 @@ inline void eval_round(T& result, const T& a) result = boost::math::policies::raise_rounding_error("boost::multiprecision::round<%1%>(%1%)", 0, mp_number(a), 0, boost::math::policies::policy<>()).backend(); return; } - if(get_sign(a) < 0) + if(eval_get_sign(a) < 0) { - subtract(result, a, fp_type(0.5f)); + eval_subtract(result, a, fp_type(0.5f)); eval_ceil(result, result); } else { - add(result, a, fp_type(0.5f)); + eval_add(result, a, fp_type(0.5f)); eval_floor(result, result); } } diff --git a/include/boost/multiprecision/detail/functions/constants.hpp b/include/boost/multiprecision/detail/functions/constants.hpp index dab1e2c3..677ed49d 100644 --- a/include/boost/multiprecision/detail/functions/constants.hpp +++ b/include/boost/multiprecision/detail/functions/constants.hpp @@ -28,21 +28,21 @@ void calc_log2(T& num, unsigned digits) for(ui_type n = 6; n < limit; ++n) { temp = static_cast(2); - multiply(temp, ui_type(2 * n)); - multiply(temp, ui_type(2 * n + 1)); - multiply(num, temp); - multiply(denom, temp); + eval_multiply(temp, ui_type(2 * n)); + eval_multiply(temp, ui_type(2 * n + 1)); + eval_multiply(num, temp); + eval_multiply(denom, temp); sign = -sign; - multiply(next_term, n); - multiply(temp, next_term, next_term); - multiply(temp, sign); - add(num, temp); + eval_multiply(next_term, n); + eval_multiply(temp, next_term, next_term); + eval_multiply(temp, sign); + eval_add(num, temp); } - multiply(denom, ui_type(4)); - multiply(num, ui_type(3)); + eval_multiply(denom, ui_type(4)); + eval_multiply(num, ui_type(3)); INSTRUMENT_BACKEND(denom); INSTRUMENT_BACKEND(num); - divide(num, denom); + eval_divide(num, denom); INSTRUMENT_BACKEND(num); } @@ -60,12 +60,12 @@ void calc_e(T& result, unsigned digits) denom = ui_type(1); ui_type i = 2; do{ - multiply(denom, i); - multiply(result, i); - add(result, ui_type(1)); + eval_multiply(denom, i); + eval_multiply(result, i); + eval_add(result, ui_type(1)); ++i; }while(denom.compare(lim) <= 0); - divide(result, denom); + eval_divide(result, denom); } template @@ -91,16 +91,16 @@ void calc_pi(T& result, unsigned digits) do { - add(result, A, B); + eval_add(result, A, B); eval_ldexp(result, result, -2); eval_sqrt(b, B); - add(a, b); + eval_add(a, b); eval_ldexp(a, a, -1); - multiply(A, a, a); - subtract(B, A, result); + eval_multiply(A, a, a); + eval_subtract(B, A, result); eval_ldexp(B, B, 1); - subtract(result, A, B); - bool neg = get_sign(result) < 0; + eval_subtract(result, A, B); + bool neg = eval_get_sign(result) < 0; if(neg) result.negate(); if(result.compare(lim) <= 0) @@ -108,13 +108,13 @@ void calc_pi(T& result, unsigned digits) if(neg) result.negate(); eval_ldexp(result, result, k - 1); - subtract(D, result); + eval_subtract(D, result); ++k; eval_ldexp(lim, lim, 1); } while(true); - divide(result, B, D); + eval_divide(result, B, D); } template diff --git a/include/boost/multiprecision/detail/functions/pow.hpp b/include/boost/multiprecision/detail/functions/pow.hpp index 23ee1895..f9f2e37b 100644 --- a/include/boost/multiprecision/detail/functions/pow.hpp +++ b/include/boost/multiprecision/detail/functions/pow.hpp @@ -35,7 +35,7 @@ inline void pow_imp(T& result, const T& t, const U& p, const mpl::true_&) temp = static_cast(1); T denom; pow_imp(denom, t, -p, mpl::true_()); - divide(result, temp, denom); + eval_divide(result, temp, denom); return; } @@ -48,15 +48,15 @@ inline void pow_imp(T& result, const T& t, const U& p, const mpl::true_&) result = t; break; case 2: - multiply(result, t, t); + eval_multiply(result, t, t); break; case 3: - multiply(result, t, t); - multiply(result, t); + eval_multiply(result, t, t); + eval_multiply(result, t); break; case 4: - multiply(result, t, t); - multiply(result, result); + eval_multiply(result, t, t); + eval_multiply(result, result); break; default: { @@ -65,7 +65,7 @@ inline void pow_imp(T& result, const T& t, const U& p, const mpl::true_&) for(n = static_cast(1); n <= static_cast(p / static_cast(2)); n *= static_cast(2)) { - multiply(result, result); + eval_multiply(result, result); } const U p_minus_n = static_cast(p - n); @@ -75,7 +75,7 @@ inline void pow_imp(T& result, const T& t, const U& p, const mpl::true_&) { T temp; pow_imp(temp, t, p_minus_n, mpl::true_()); - multiply(result, temp); + eval_multiply(result, temp); } } } @@ -106,11 +106,11 @@ void hyp0F0(T& H0F0, const T& x) T x_pow_n_div_n_fact(x); - add(H0F0, x_pow_n_div_n_fact, ui_type(1)); + eval_add(H0F0, x_pow_n_div_n_fact, ui_type(1)); T lim; eval_ldexp(lim, H0F0, 1 - tol); - if(get_sign(lim) < 0) + if(eval_get_sign(lim) < 0) lim.negate(); ui_type n; @@ -118,10 +118,10 @@ void hyp0F0(T& H0F0, const T& x) // Series expansion of hyperg_0f0(; ; x). for(n = 2; n < 300; ++n) { - multiply(x_pow_n_div_n_fact, x); - divide(x_pow_n_div_n_fact, n); - add(H0F0, x_pow_n_div_n_fact); - bool neg = get_sign(x_pow_n_div_n_fact) < 0; + eval_multiply(x_pow_n_div_n_fact, x); + eval_divide(x_pow_n_div_n_fact, n); + eval_add(H0F0, x_pow_n_div_n_fact); + bool neg = eval_get_sign(x_pow_n_div_n_fact) < 0; if(neg) x_pow_n_div_n_fact.negate(); if(lim.compare(x_pow_n_div_n_fact) > 0) @@ -154,11 +154,11 @@ void hyp1F0(T& H1F0, const T& a, const T& x) T pochham_a (a); T ap (a); - multiply(H1F0, pochham_a, x_pow_n_div_n_fact); - add(H1F0, si_type(1)); + eval_multiply(H1F0, pochham_a, x_pow_n_div_n_fact); + eval_add(H1F0, si_type(1)); T lim; eval_ldexp(lim, H1F0, 1 - boost::multiprecision::detail::digits2 >::value); - if(get_sign(lim) < 0) + if(eval_get_sign(lim) < 0) lim.negate(); si_type n; @@ -167,13 +167,13 @@ void hyp1F0(T& H1F0, const T& a, const T& x) // Series expansion of hyperg_1f0(a; ; x). for(n = 2; n < boost::multiprecision::detail::digits2 >::value + 10; n++) { - multiply(x_pow_n_div_n_fact, x); - divide(x_pow_n_div_n_fact, n); - increment(ap); - multiply(pochham_a, ap); - multiply(term, pochham_a, x_pow_n_div_n_fact); - add(H1F0, term); - if(get_sign(term) < 0) + eval_multiply(x_pow_n_div_n_fact, x); + eval_divide(x_pow_n_div_n_fact, n); + eval_increment(ap); + eval_multiply(pochham_a, ap); + eval_multiply(term, pochham_a, x_pow_n_div_n_fact); + eval_add(H1F0, term); + if(eval_get_sign(term) < 0) term.negate(); if(lim.compare(term) >= 0) break; @@ -201,7 +201,7 @@ void eval_exp(T& result, const T& x) // Handle special arguments. int type = eval_fpclassify(x); - bool isneg = get_sign(x) < 0; + bool isneg = eval_get_sign(x) < 0; if(type == FP_NAN) { result = std::numeric_limits >::quiet_NaN().backend(); @@ -250,21 +250,21 @@ void eval_exp(T& result, const T& x) exp_series = xx; result = si_type(1); if(isneg) - subtract(result, exp_series); + eval_subtract(result, exp_series); else - add(result, exp_series); - multiply(exp_series, xx); - divide(exp_series, ui_type(k)); - add(result, exp_series); + eval_add(result, exp_series); + eval_multiply(exp_series, xx); + eval_divide(exp_series, ui_type(k)); + eval_add(result, exp_series); while(exp_series.compare(lim) > 0) { ++k; - multiply(exp_series, xx); - divide(exp_series, ui_type(k)); + eval_multiply(exp_series, xx); + eval_divide(exp_series, ui_type(k)); if(isneg && (k&1)) - subtract(result, exp_series); + eval_subtract(result, exp_series); else - add(result, exp_series); + eval_add(result, exp_series); } return; } @@ -272,7 +272,7 @@ void eval_exp(T& result, const T& x) // Check for pure-integer arguments which can be either signed or unsigned. long long ll; eval_trunc(exp_series, x); - convert_to(&ll, exp_series); + eval_convert_to(&ll, exp_series); if(x.compare(ll) == 0) { detail::pow_imp(result, get_constant_e(), ll, mpl::true_()); @@ -293,23 +293,23 @@ void eval_exp(T& result, const T& x) if(b_scale) { - divide(result, xx, get_constant_ln2()); + eval_divide(result, xx, get_constant_ln2()); exp_type n; - convert_to(&n, result); + eval_convert_to(&n, result); // The scaling is 2^11 = 2048. static const si_type p2 = static_cast(si_type(1) << 11); - multiply(exp_series, get_constant_ln2(), static_cast(n)); - subtract(exp_series, xx); - divide(exp_series, p2); + eval_multiply(exp_series, get_constant_ln2(), static_cast(n)); + eval_subtract(exp_series, xx); + eval_divide(exp_series, p2); exp_series.negate(); hyp0F0(result, exp_series); detail::pow_imp(exp_series, result, p2, mpl::true_()); result = ui_type(1); eval_ldexp(result, result, n); - multiply(exp_series, result); + eval_multiply(exp_series, result); } else { @@ -317,7 +317,7 @@ void eval_exp(T& result, const T& x) } if(isneg) - divide(result, ui_type(1), exp_series); + eval_divide(result, ui_type(1), exp_series); else result = exp_series; } @@ -358,9 +358,9 @@ void eval_log(T& result, const T& arg) --e; } - multiply(result, get_constant_ln2(), canonical_exp_type(e)); + eval_multiply(result, get_constant_ln2(), canonical_exp_type(e)); INSTRUMENT_BACKEND(result); - subtract(t, ui_type(1)); /* -0.3 <= t <= 0.3 */ + eval_subtract(t, ui_type(1)); /* -0.3 <= t <= 0.3 */ if(!alternate) t.negate(); /* 0 <= t <= 0.33333 */ T pow = t; @@ -368,12 +368,12 @@ void eval_log(T& result, const T& arg) T t2; if(alternate) - add(result, t); + eval_add(result, t); else - subtract(result, t); + eval_subtract(result, t); - multiply(lim, result, std::numeric_limits >::epsilon().backend()); - if(get_sign(lim) < 0) + eval_multiply(lim, result, std::numeric_limits >::epsilon().backend()); + if(eval_get_sign(lim) < 0) lim.negate(); INSTRUMENT_BACKEND(lim); @@ -381,13 +381,13 @@ void eval_log(T& result, const T& arg) do { ++k; - multiply(pow, t); - divide(t2, pow, k); + eval_multiply(pow, t); + eval_divide(t2, pow, k); INSTRUMENT_BACKEND(t2); if(alternate && ((k & 1) != 0)) - add(result, t2); + eval_add(result, t2); else - subtract(result, t2); + eval_subtract(result, t2); INSTRUMENT_BACKEND(result); }while(lim.compare(t2) < 0); } @@ -415,7 +415,7 @@ void eval_log10(T& result, const T& arg) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_floating_point, "The fabs function is only valid for floating point types."); eval_log(result, arg); - divide(result, get_constant_log10()); + eval_divide(result, get_constant_log10()); } template @@ -457,35 +457,35 @@ inline void eval_pow(T& result, const T& x, const T& a) default: ; } - if(get_sign(a) == 0) + if(eval_get_sign(a) == 0) { result = si_type(1); return; } long long an; - convert_to(&an, a); + eval_convert_to(&an, a); const bool bo_a_isint = a.compare(an) == 0; - if((get_sign(x) < 0) && !bo_a_isint) + if((eval_get_sign(x) < 0) && !bo_a_isint) { result = std::numeric_limits >::quiet_NaN().backend(); } T t; T da(a); - subtract(da, an); + eval_subtract(da, an); if(a.compare(si_type(-1)) < 0) { t = a; t.negate(); eval_pow(da, x, t); - divide(result, si_type(1), da); + eval_divide(result, si_type(1), da); return; } - subtract(da, a, an); + eval_subtract(da, a, an); if(bo_a_isint) { @@ -493,13 +493,13 @@ inline void eval_pow(T& result, const T& x, const T& a) return; } - if((get_sign(x) > 0) && (x.compare(fp_type(0.5)) >= 0) && (x.compare(fp_type(0.9)) < 0)) + if((eval_get_sign(x) > 0) && (x.compare(fp_type(0.5)) >= 0) && (x.compare(fp_type(0.9)) < 0)) { if(a.compare(fp_type(1e-5f)) <= 0) { // Series expansion for small a. eval_log(t, x); - multiply(t, a); + eval_multiply(t, a); hyp0F0(result, t); return; } @@ -511,17 +511,17 @@ inline void eval_pow(T& result, const T& x, const T& a) { da.negate(); t = si_type(1); - subtract(t, x); + eval_subtract(t, x); hyp1F0(result, da, t); detail::pow_imp(t, x, an, mpl::true_()); - multiply(result, t); + eval_multiply(result, t); } else { da = a; da.negate(); t = si_type(1); - subtract(t, x); + eval_subtract(t, x); hyp1F0(result, da, t); } } @@ -533,15 +533,15 @@ inline void eval_pow(T& result, const T& x, const T& a) if(an) { eval_log(t, x); - multiply(t, da); + eval_multiply(t, da); eval_exp(result, t); detail::pow_imp(t, x, an, mpl::true_()); - multiply(result, t); + eval_multiply(result, t); } else { eval_log(t, x); - multiply(t, a); + eval_multiply(t, a); eval_exp(result, t); } } @@ -553,12 +553,12 @@ namespace detail{ void small_sinh_series(T x, T& result) { typedef typename boost::multiprecision::detail::canonical::type ui_type; - bool neg = get_sign(x) < 0; + bool neg = eval_get_sign(x) < 0; if(neg) x.negate(); T p(x); T mult(x); - multiply(mult, x); + eval_multiply(mult, x); result = x; ui_type k = 1; @@ -567,10 +567,10 @@ namespace detail{ do { - multiply(p, mult); - divide(p, ++k); - divide(p, ++k); - add(result, p); + eval_multiply(p, mult); + eval_divide(p, ++k); + eval_divide(p, ++k); + eval_add(result, p); }while(p.compare(lim) >= 0); if(neg) result.negate(); @@ -605,12 +605,12 @@ namespace detail{ T e_px, e_mx; - bool small_sinh = get_sign(x) < 0 ? e_px.compare(fp_type(-0.5)) > 0 : e_px.compare(fp_type(0.5)) < 0; + bool small_sinh = eval_get_sign(x) < 0 ? e_px.compare(fp_type(-0.5)) > 0 : e_px.compare(fp_type(0.5)) < 0; if(p_cosh || !small_sinh) { eval_exp(e_px, x); - divide(e_mx, ui_type(1), e_px); + eval_divide(e_mx, ui_type(1), e_px); if(p_sinh) { @@ -620,14 +620,14 @@ namespace detail{ } else { - subtract(*p_sinh, e_px, e_mx); - divide(*p_sinh, ui_type(2)); + eval_subtract(*p_sinh, e_px, e_mx); + eval_divide(*p_sinh, ui_type(2)); } } if(p_cosh) { - add(*p_cosh, e_px, e_mx); - divide(*p_cosh, ui_type(2)); + eval_add(*p_cosh, e_px, e_mx); + eval_divide(*p_cosh, ui_type(2)); } } else @@ -658,6 +658,6 @@ inline void eval_tanh(T& result, const T& x) BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_floating_point, "The tanh function is only valid for floating point types."); T c; detail::sinhcosh(x, &result, &c); - divide(result, c); + eval_divide(result, c); } diff --git a/include/boost/multiprecision/detail/functions/trig.hpp b/include/boost/multiprecision/detail/functions/trig.hpp index 58c24cd4..dbe134fd 100644 --- a/include/boost/multiprecision/detail/functions/trig.hpp +++ b/include/boost/multiprecision/detail/functions/trig.hpp @@ -29,31 +29,31 @@ void hyp0F1(T& result, const T& b, const T& x) T pochham_b (b); T bp (b); - divide(result, x_pow_n_div_n_fact, pochham_b); - add(result, ui_type(1)); + eval_divide(result, x_pow_n_div_n_fact, pochham_b); + eval_add(result, ui_type(1)); si_type n; T tol; tol = ui_type(1); eval_ldexp(tol, tol, 1 - boost::multiprecision::detail::digits2 >::value); - multiply(tol, result); - if(get_sign(tol) < 0) + eval_multiply(tol, result); + if(eval_get_sign(tol) < 0) tol.negate(); T term; // Series expansion of hyperg_0f1(; b; x). for(n = 2; n < 300; ++n) { - multiply(x_pow_n_div_n_fact, x); - divide(x_pow_n_div_n_fact, n); - increment(bp); - multiply(pochham_b, bp); + eval_multiply(x_pow_n_div_n_fact, x); + eval_divide(x_pow_n_div_n_fact, n); + eval_increment(bp); + eval_multiply(pochham_b, bp); - divide(term, x_pow_n_div_n_fact, pochham_b); - add(result, term); + eval_divide(term, x_pow_n_div_n_fact, pochham_b); + eval_add(result, term); - bool neg_term = get_sign(term) < 0; + bool neg_term = eval_get_sign(term) < 0; if(neg_term) term.negate(); if(term.compare(tol) <= 0) @@ -103,7 +103,7 @@ void eval_sin(T& result, const T& x) // The argument xx will be reduced to 0 <= xx <= pi/2. bool b_negate_sin = false; - if(get_sign(x) < 0) + if(eval_get_sign(x) < 0) { xx.negate(); b_negate_sin = !b_negate_sin; @@ -113,13 +113,13 @@ void eval_sin(T& result, const T& x) // Remove even multiples of pi. if(xx.compare(get_constant_pi()) > 0) { - divide(n_pi, xx, get_constant_pi()); + eval_divide(n_pi, xx, get_constant_pi()); eval_trunc(n_pi, n_pi); t = ui_type(2); eval_fmod(t, n_pi, t); - const bool b_n_pi_is_even = get_sign(t) == 0; - multiply(n_pi, get_constant_pi()); - subtract(xx, n_pi); + const bool b_n_pi_is_even = eval_get_sign(t) == 0; + eval_multiply(n_pi, get_constant_pi()); + eval_subtract(xx, n_pi); BOOST_MATH_INSTRUMENT_CODE(xx.str(0, std::ios_base::scientific)); BOOST_MATH_INSTRUMENT_CODE(n_pi.str(0, std::ios_base::scientific)); @@ -135,13 +135,13 @@ void eval_sin(T& result, const T& x) eval_ldexp(t, get_constant_pi(), -1); if(xx.compare(t) > 0) { - subtract(xx, get_constant_pi(), xx); + eval_subtract(xx, get_constant_pi(), xx); BOOST_MATH_INSTRUMENT_CODE(xx.str(0, std::ios_base::scientific)); } - subtract(t, xx); - const bool b_zero = get_sign(xx) == 0; - const bool b_pi_half = get_sign(t) == 0; + eval_subtract(t, xx); + const bool b_zero = eval_get_sign(xx) == 0; + const bool b_pi_half = eval_get_sign(t) == 0; // Check if the reduced argument is very close to 0 or pi/2. const bool b_near_zero = xx.compare(fp_type(1e-1)) < 0; @@ -157,18 +157,18 @@ void eval_sin(T& result, const T& x) } else if(b_near_zero) { - multiply(t, xx, xx); - divide(t, si_type(-4)); + eval_multiply(t, xx, xx); + eval_divide(t, si_type(-4)); T t2; t2 = fp_type(1.5); hyp0F1(result, t2, t); BOOST_MATH_INSTRUMENT_CODE(result.str(0, std::ios_base::scientific)); - multiply(result, xx); + eval_multiply(result, xx); } else if(b_near_pi_half) { - multiply(t, t); - divide(t, si_type(-4)); + eval_multiply(t, t); + eval_divide(t, si_type(-4)); T t2; t2 = fp_type(0.5); hyp0F1(result, t2, t); @@ -184,26 +184,26 @@ void eval_sin(T& result, const T& x) static const si_type n_scale = 9; static const si_type n_three_pow_scale = static_cast(19683L); - divide(xx, n_three_pow_scale); + eval_divide(xx, n_three_pow_scale); // Now with small arguments, we are ready for a series expansion. - multiply(t, xx, xx); - divide(t, si_type(-4)); + eval_multiply(t, xx, xx); + eval_divide(t, si_type(-4)); T t2; t2 = fp_type(1.5); hyp0F1(result, t2, t); BOOST_MATH_INSTRUMENT_CODE(result.str(0, std::ios_base::scientific)); - multiply(result, xx); + eval_multiply(result, xx); // Convert back using multiple angle identity. for(boost::int32_t k = static_cast(0); k < n_scale; k++) { // Rescale the cosine value using the multiple angle identity. - multiply(t2, result, ui_type(3)); - multiply(t, result, result); - multiply(t, result); - multiply(t, ui_type(4)); - subtract(result, t2, t); + eval_multiply(t2, result, ui_type(3)); + eval_multiply(t, result, result); + eval_multiply(t, result); + eval_multiply(t, ui_type(4)); + eval_subtract(result, t2, t); } } @@ -249,7 +249,7 @@ void eval_cos(T& result, const T& x) // The argument xx will be reduced to 0 <= xx <= pi/2. bool b_negate_cos = false; - if(get_sign(x) < 0) + if(eval_get_sign(x) < 0) { xx.negate(); } @@ -258,18 +258,18 @@ void eval_cos(T& result, const T& x) // Remove even multiples of pi. if(xx.compare(get_constant_pi()) > 0) { - divide(t, xx, get_constant_pi()); + eval_divide(t, xx, get_constant_pi()); eval_trunc(n_pi, t); BOOST_MATH_INSTRUMENT_CODE(n_pi.str(0, std::ios_base::scientific)); - multiply(t, n_pi, get_constant_pi()); + eval_multiply(t, n_pi, get_constant_pi()); BOOST_MATH_INSTRUMENT_CODE(t.str(0, std::ios_base::scientific)); - subtract(xx, t); + eval_subtract(xx, t); BOOST_MATH_INSTRUMENT_CODE(xx.str(0, std::ios_base::scientific)); // Adjust signs if the multiple of pi is not even. t = ui_type(2); eval_fmod(t, n_pi, t); - const bool b_n_pi_is_even = get_sign(t) == 0; + const bool b_n_pi_is_even = eval_get_sign(t) == 0; if(!b_n_pi_is_even) { @@ -282,17 +282,17 @@ void eval_cos(T& result, const T& x) int com = xx.compare(t); if(com > 0) { - subtract(xx, get_constant_pi(), xx); + eval_subtract(xx, get_constant_pi(), xx); b_negate_cos = !b_negate_cos; BOOST_MATH_INSTRUMENT_CODE(xx.str(0, std::ios_base::scientific)); } - const bool b_zero = get_sign(xx) == 0; + const bool b_zero = eval_get_sign(xx) == 0; const bool b_pi_half = com == 0; // Check if the reduced argument is very close to 0 or pi/2. const bool b_near_zero = xx.compare(fp_type(1e-4)) < 0; - subtract(t, xx); + eval_subtract(t, xx); const bool b_near_pi_half = t.compare(fp_type(1e-4)) < 0; if(b_zero) @@ -305,8 +305,8 @@ void eval_cos(T& result, const T& x) } else if(b_near_zero) { - multiply(t, xx, xx); - divide(t, si_type(-4)); + eval_multiply(t, xx, xx); + eval_divide(t, si_type(-4)); n_pi = fp_type(0.5f); hyp0F1(result, n_pi, t); BOOST_MATH_INSTRUMENT_CODE(result.str(0, std::ios_base::scientific)); @@ -314,11 +314,11 @@ void eval_cos(T& result, const T& x) else if(b_near_pi_half) { T t2(t); - multiply(t, t); - divide(t, si_type(-4)); + eval_multiply(t, t); + eval_divide(t, si_type(-4)); n_pi = fp_type(1.5f); hyp0F1(result, n_pi, t); - multiply(result, t2); + eval_multiply(result, t2); BOOST_MATH_INSTRUMENT_CODE(result.str(0, std::ios_base::scientific)); } else @@ -330,10 +330,10 @@ void eval_cos(T& result, const T& x) static const ui_type n_scale = 9; static const ui_type n_three_pow_scale = 19683; - divide(xx, n_three_pow_scale); + eval_divide(xx, n_three_pow_scale); - multiply(t, xx, xx); - divide(t, si_type(-4)); + eval_multiply(t, xx, xx); + eval_divide(t, si_type(-4)); n_pi = fp_type(0.5f); // Now with small arguments, we are ready for a series expansion. @@ -343,11 +343,11 @@ void eval_cos(T& result, const T& x) // Convert back using multiple angle identity. for(ui_type k = 0; k < n_scale; k++) { - multiply(t, result, result); - multiply(t, result); - multiply(t, ui_type(4)); - multiply(result, si_type(-3)); - add(result, t); + eval_multiply(t, result, result); + eval_multiply(t, result); + eval_multiply(t, ui_type(4)); + eval_multiply(result, si_type(-3)); + eval_add(result, t); } } if(b_negate_cos) @@ -361,7 +361,7 @@ void eval_tan(T& result, const T& x) T t; eval_sin(result, x); eval_cos(t, x); - divide(result, t); + eval_divide(result, t); } template @@ -385,15 +385,15 @@ void hyp2F1(T& result, const T& a, const T& b, const T& c, const T& x) T bp (b); T cp (c); - multiply(result, pochham_a, pochham_b); - divide(result, pochham_c); - multiply(result, x_pow_n_div_n_fact); - add(result, ui_type(1)); + eval_multiply(result, pochham_a, pochham_b); + eval_divide(result, pochham_c); + eval_multiply(result, x_pow_n_div_n_fact); + eval_add(result, ui_type(1)); T lim; eval_ldexp(lim, result, 1 - boost::multiprecision::detail::digits2 >::value); - if(get_sign(lim) < 0) + if(eval_get_sign(lim) < 0) lim.negate(); ui_type n; @@ -402,22 +402,22 @@ void hyp2F1(T& result, const T& a, const T& b, const T& c, const T& x) // Series expansion of hyperg_2f1(a, b; c; x). for(n = 2; n < 300; ++n) { - multiply(x_pow_n_div_n_fact, x); - divide(x_pow_n_div_n_fact, n); + eval_multiply(x_pow_n_div_n_fact, x); + eval_divide(x_pow_n_div_n_fact, n); - increment(ap); - multiply(pochham_a, ap); - increment(bp); - multiply(pochham_b, bp); - increment(cp); - multiply(pochham_c, cp); + eval_increment(ap); + eval_multiply(pochham_a, ap); + eval_increment(bp); + eval_multiply(pochham_b, bp); + eval_increment(cp); + eval_multiply(pochham_c, cp); - multiply(term, pochham_a, pochham_b); - divide(term, pochham_c); - multiply(term, x_pow_n_div_n_fact); - add(result, term); + eval_multiply(term, pochham_a, pochham_b); + eval_divide(term, pochham_c); + eval_multiply(term, x_pow_n_div_n_fact); + eval_add(result, term); - if(get_sign(term) < 0) + if(eval_get_sign(term) < 0) term.negate(); if(lim.compare(term) >= 0) break; @@ -455,7 +455,7 @@ void eval_asin(T& result, const T& x) default: ; } - const bool b_neg = get_sign(x) < 0; + const bool b_neg = eval_get_sign(x) < 0; T xx(x); if(b_neg) @@ -479,29 +479,29 @@ void eval_asin(T& result, const T& x) if(xx.compare(fp_type(1e-4)) < 0) { // http://functions.wolfram.com/ElementaryFunctions/ArcSin/26/01/01/ - multiply(xx, xx); + eval_multiply(xx, xx); T t1, t2; t1 = fp_type(0.5f); t2 = fp_type(1.5f); hyp2F1(result, t1, t1, t2, xx); - multiply(result, x); + eval_multiply(result, x); return; } else if(xx.compare(fp_type(1 - 1e-4f)) > 0) { T dx1; T t1, t2; - subtract(dx1, ui_type(1), xx); + eval_subtract(dx1, ui_type(1), xx); t1 = fp_type(0.5f); t2 = fp_type(1.5f); eval_ldexp(dx1, dx1, -1); hyp2F1(result, t1, t1, t2, dx1); eval_ldexp(dx1, dx1, 2); eval_sqrt(t1, dx1); - multiply(result, t1); + eval_multiply(result, t1); eval_ldexp(t1, get_constant_pi(), -1); result.negate(); - add(result, t1); + eval_add(result, t1); if(b_neg) result.negate(); return; @@ -509,7 +509,7 @@ void eval_asin(T& result, const T& x) // Get initial estimate using standard math function asin. double dd; - convert_to(&dd, xx); + eval_convert_to(&dd, xx); result = fp_type(std::asin(dd)); @@ -519,15 +519,15 @@ void eval_asin(T& result, const T& x) T s, c; eval_sin(s, result); eval_cos(c, result); - subtract(s, xx); - divide(s, c); - subtract(result, s); + eval_subtract(s, xx); + eval_divide(s, c); + eval_subtract(result, s); T lim; eval_ldexp(lim, result, 1 - boost::multiprecision::detail::digits2 >::value); - if(get_sign(s) < 0) + if(eval_get_sign(s) < 0) s.negate(); - if(get_sign(lim) < 0) + if(eval_get_sign(lim) < 0) lim.negate(); if(lim.compare(s) >= 0) break; @@ -564,7 +564,7 @@ inline void eval_acos(T& result, const T& x) } else if(c == 0) { - if(get_sign(x) < 0) + if(eval_get_sign(x) < 0) result = get_constant_pi(); else result = ui_type(0); @@ -574,7 +574,7 @@ inline void eval_acos(T& result, const T& x) eval_asin(result, x); T t; eval_ldexp(t, get_constant_pi(), -1); - subtract(result, t); + eval_subtract(result, t); result.negate(); } @@ -597,7 +597,7 @@ void eval_atan(T& result, const T& x) result = ui_type(0); return; case FP_INFINITE: - if(get_sign(x) < 0) + if(eval_get_sign(x) < 0) { eval_ldexp(result, get_constant_pi(), -1); result.negate(); @@ -608,7 +608,7 @@ void eval_atan(T& result, const T& x) default: ; } - const bool b_neg = get_sign(x) < 0; + const bool b_neg = eval_get_sign(x) < 0; T xx(x); if(b_neg) @@ -620,10 +620,10 @@ void eval_atan(T& result, const T& x) t1 = ui_type(1); t2 = fp_type(0.5f); t3 = fp_type(1.5f); - multiply(xx, xx); + eval_multiply(xx, xx); xx.negate(); hyp2F1(result, t1, t2, t3, xx); - multiply(result, x); + eval_multiply(result, x); return; } @@ -633,14 +633,14 @@ void eval_atan(T& result, const T& x) t1 = fp_type(0.5f); t2 = ui_type(1u); t3 = fp_type(1.5f); - multiply(xx, xx); - divide(xx, si_type(-1), xx); + eval_multiply(xx, xx); + eval_divide(xx, si_type(-1), xx); hyp2F1(result, t1, t2, t3, xx); - divide(result, x); + eval_divide(result, x); if(!b_neg) result.negate(); eval_ldexp(t1, get_constant_pi(), -1); - add(result, t1); + eval_add(result, t1); if(b_neg) result.negate(); return; @@ -649,7 +649,7 @@ void eval_atan(T& result, const T& x) // Get initial estimate using standard math function atan. fp_type d; - convert_to(&d, xx); + eval_convert_to(&d, xx); result = fp_type(std::atan(d)); // Newton-Raphson iteration @@ -660,10 +660,10 @@ void eval_atan(T& result, const T& x) { eval_sin(s, result); eval_cos(c, result); - multiply(t, xx, c); - subtract(t, s); - multiply(s, t, c); - add(result, s); + eval_multiply(t, xx, c); + eval_subtract(t, s); + eval_multiply(s, t, c); + eval_add(result, s); } if(b_neg) result.negate(); @@ -699,7 +699,7 @@ void eval_atan2(T& result, const T& y, const T& x) return; case FP_ZERO: { - int c = get_sign(x); + int c = eval_get_sign(x); if(c < 0) result = get_constant_pi(); else if(c >= 0) @@ -715,7 +715,7 @@ void eval_atan2(T& result, const T& y, const T& x) else { eval_ldexp(result, get_constant_pi(), -1); - if(get_sign(y) < 0) + if(eval_get_sign(y) < 0) result.negate(); } return; @@ -730,30 +730,30 @@ void eval_atan2(T& result, const T& y, const T& x) case FP_ZERO: { eval_ldexp(result, get_constant_pi(), -1); - if(get_sign(y) < 0) + if(eval_get_sign(y) < 0) result.negate(); return; } case FP_INFINITE: - if(get_sign(x) > 0) + if(eval_get_sign(x) > 0) result = ui_type(0); else result = get_constant_pi(); - if(get_sign(y) < 0) + if(eval_get_sign(y) < 0) result.negate(); return; } T xx; - divide(xx, y, x); - if(get_sign(xx) < 0) + eval_divide(xx, y, x); + if(eval_get_sign(xx) < 0) xx.negate(); eval_atan(result, xx); // Determine quadrant (sign) based on signs of x, y - const bool y_neg = get_sign(y) < 0; - const bool x_neg = get_sign(x) < 0; + const bool y_neg = eval_get_sign(y) < 0; + const bool x_neg = eval_get_sign(x) < 0; if(y_neg != x_neg) result.negate(); @@ -761,9 +761,9 @@ void eval_atan2(T& result, const T& y, const T& x) if(x_neg) { if(y_neg) - subtract(result, get_constant_pi()); + eval_subtract(result, get_constant_pi()); else - add(result, get_constant_pi()); + eval_add(result, get_constant_pi()); } } diff --git a/include/boost/multiprecision/fixed_int.hpp b/include/boost/multiprecision/fixed_int.hpp index 1127079d..85a6d339 100644 --- a/include/boost/multiprecision/fixed_int.hpp +++ b/include/boost/multiprecision/fixed_int.hpp @@ -127,17 +127,17 @@ struct fixed_int f = ldexp(f, shift); term = floor(f); e -= shift; - left_shift(*this, shift); + eval_left_shift(*this, shift); if(term > 0) - add(*this, static_cast(term)); + eval_add(*this, static_cast(term)); else - subtract(*this, static_cast(-term)); + eval_subtract(*this, static_cast(-term)); f -= term; } if(e > 0) - left_shift(*this, e); + eval_left_shift(*this, e); else if(e < 0) - right_shift(*this, -e); + eval_right_shift(*this, -e); data()[0] &= fixed_int::upper_limb_mask; return *this; } @@ -202,7 +202,7 @@ struct fixed_int break; } } - left_shift(*this, block_shift); + eval_left_shift(*this, block_shift); m_value[limb_count - 1] |= block; } } @@ -229,8 +229,8 @@ struct fixed_int break; } } - multiply(*this, block_mult); - add(*this, block); + eval_multiply(*this, block_mult); + eval_add(*this, block); } } } @@ -265,7 +265,7 @@ struct fixed_int if(c > '9') c += 'A' - '9' - 1; result[pos--] = c; - right_shift(t, shift); + eval_right_shift(t, shift); } if(Bits % shift) { @@ -306,7 +306,7 @@ struct fixed_int } else { - while(get_sign(t) != 0) + while(eval_get_sign(t) != 0) { fixed_int t2; divide_unsigned_helper(t2, t, max_block_10, r); @@ -376,12 +376,12 @@ private: }; template -inline void add(fixed_int& result, const fixed_int& o) +inline void eval_add(fixed_int& result, const fixed_int& o) { - add(result, result, o); + eval_add(result, result, o); } template -inline void add(fixed_int& result, const fixed_int& a, const fixed_int& b) +inline void eval_add(fixed_int& result, const fixed_int& a, const fixed_int& b) { // Addition using modular arithmatic. // Nothing fancy, just let uintmax_t take the strain: @@ -395,7 +395,7 @@ inline void add(fixed_int& result, const fixed_int& result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void add(fixed_int& result, const limb_type& o) +inline void eval_add(fixed_int& result, const limb_type& o) { // Addition using modular arithmatic. // Nothing fancy, just let uintmax_t take the strain: @@ -409,15 +409,15 @@ inline void add(fixed_int& result, const limb_type& o) result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void add(fixed_int& result, const signed_limb_type& o) +inline void eval_add(fixed_int& result, const signed_limb_type& o) { if(o < 0) - subtract(result, static_cast(-o)); + eval_subtract(result, static_cast(-o)); else if(o > 0) - add(result, static_cast(o)); + eval_add(result, static_cast(o)); } template -inline void subtract(fixed_int& result, const limb_type& o) +inline void eval_subtract(fixed_int& result, const limb_type& o) { // Subtract using modular arithmatic. // This is the same code as for addition, with the twist that we negate o "on the fly": @@ -434,41 +434,41 @@ inline void subtract(fixed_int& result, const limb_type& o) result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void subtract(fixed_int& result, const signed_limb_type& o) +inline void eval_subtract(fixed_int& result, const signed_limb_type& o) { if(o) { if(o < 0) - add(result, static_cast(-o)); + eval_add(result, static_cast(-o)); else - subtract(result, static_cast(o)); + eval_subtract(result, static_cast(o)); } } template -inline void increment(fixed_int& result) +inline void eval_increment(fixed_int& result) { static const limb_type one = 1; if(result.data().elems[fixed_int::limb_count - 1] < fixed_int::max_limb_value) ++result.data().elems[fixed_int::limb_count - 1]; else - add(result, one); + eval_add(result, one); } template -inline void decrement(fixed_int& result) +inline void eval_decrement(fixed_int& result) { static const limb_type one = 1; if(result.data().elems[fixed_int::limb_count - 1]) --result.data().elems[fixed_int::limb_count - 1]; else - subtract(result, one); + eval_subtract(result, one); } template -inline void subtract(fixed_int& result, const fixed_int& o) +inline void eval_subtract(fixed_int& result, const fixed_int& o) { - subtract(result, result, o); + eval_subtract(result, result, o); } template -inline void subtract(fixed_int& result, const fixed_int& a, const fixed_int& b) +inline void eval_subtract(fixed_int& result, const fixed_int& a, const fixed_int& b) { // Subtract using modular arithmatic. // This is the same code as for addition, with the twist that we negate b "on the fly": @@ -482,20 +482,20 @@ inline void subtract(fixed_int& result, const fixed_int::upper_limb_mask; } template -inline void multiply(fixed_int& result, const fixed_int& a, const fixed_int& b) +inline void eval_multiply(fixed_int& result, const fixed_int& a, const fixed_int& b) { // Very simple long multiplication, only usable for small numbers of limb_type's // but that's the typical use case for this type anyway: if(&result == &a) { fixed_int t(a); - multiply(result, t, b); + eval_multiply(result, t, b); return; } if(&result == &b) { fixed_int t(b); - multiply(result, a, t); + eval_multiply(result, a, t); return; } double_limb_type carry = 0; @@ -515,14 +515,14 @@ inline void multiply(fixed_int& result, const fixed_int::upper_limb_mask; } template -inline void multiply(fixed_int& result, const fixed_int& a) +inline void eval_multiply(fixed_int& result, const fixed_int& a) { // There is no in-place multiply: fixed_int b(result); - multiply(result, b, a); + eval_multiply(result, b, a); } template -inline void multiply(fixed_int& result, const limb_type& a) +inline void eval_multiply(fixed_int& result, const limb_type& a) { double_limb_type carry = 0; for(int i = fixed_int::limb_count - 1; i >= 0; --i) @@ -534,13 +534,13 @@ inline void multiply(fixed_int& result, const limb_type& a) result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void multiply(fixed_int& result, const signed_limb_type& a) +inline void eval_multiply(fixed_int& result, const signed_limb_type& a) { if(a > 0) - multiply(result, static_cast(a)); + eval_multiply(result, static_cast(a)); else { - multiply(result, static_cast(-a)); + eval_multiply(result, static_cast(-a)); result.negate(); } } @@ -580,17 +580,17 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int& result, const fixed_int(1u); - subtract(r, y); + eval_subtract(r, y); return; } @@ -626,18 +626,18 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int::limb_count - 1 - n / fixed_int::limb_bits; limb_type mask = static_cast(1u) << n % fixed_int::limb_bits; fixed_int t(y); - left_shift(t, n); + eval_left_shift(t, n); while(mask_index < fixed_int::limb_count) { int comp = r.compare(t); if(comp >= 0) { result.data()[mask_index] |= mask; - subtract(r, t); + eval_subtract(r, t); if(comp == 0) break; // no remainder left - we have an exact result! } - right_shift(t, 1u); + eval_right_shift(t, 1u); if(0 == (mask >>= 1)) { ++mask_index; @@ -682,7 +682,7 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int& result, const fixed_int::limb_count - 1 - shift] = guess; - subtract(result, t); + eval_subtract(result, t); } } else if(fixed_int::max_limb_value - result.data()[fixed_int::limb_count - 1 - shift] > guess) @@ -821,7 +821,7 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int::limb_count - 1 - shift] = guess; - add(result, t); + eval_add(result, t); } // // Calculate guess * y, we use a fused mutiply-shift O(N) for this @@ -840,7 +840,7 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int::sign_bit_mask) { r.negate(); @@ -857,9 +857,9 @@ void divide_unsigned_helper(fixed_int& result, const fixed_int& result, const fixed_int& result, const fixed_int -inline void divide(fixed_int& result, const fixed_int& a, const fixed_int& b) +inline void eval_divide(fixed_int& result, const fixed_int& a, const fixed_int& b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1003,7 +1003,7 @@ inline void divide(fixed_int& result, const fixed_int -inline void divide(fixed_int& result, const fixed_int& a, limb_type& b) +inline void eval_divide(fixed_int& result, const fixed_int& a, limb_type& b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1019,7 +1019,7 @@ inline void divide(fixed_int& result, const fixed_int -inline void divide(fixed_int& result, const fixed_int& a, signed_limb_type& b) +inline void eval_divide(fixed_int& result, const fixed_int& a, signed_limb_type& b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1049,28 +1049,28 @@ inline void divide(fixed_int& result, const fixed_int -inline void divide(fixed_int& result, const fixed_int& b) +inline void eval_divide(fixed_int& result, const fixed_int& b) { // There is no in place divide: fixed_int a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void divide(fixed_int& result, limb_type b) +inline void eval_divide(fixed_int& result, limb_type b) { // There is no in place divide: fixed_int a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void divide(fixed_int& result, signed_limb_type b) +inline void eval_divide(fixed_int& result, signed_limb_type b) { // There is no in place divide: fixed_int a(result); - divide(result, a, b); + eval_divide(result, a, b); } template -inline void modulus(fixed_int& result, const fixed_int& a, const fixed_int& b) +inline void eval_modulus(fixed_int& result, const fixed_int& a, const fixed_int& b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1103,7 +1103,7 @@ inline void modulus(fixed_int& result, const fixed_int -inline void modulus(fixed_int& result, const fixed_int& a, limb_type b) +inline void eval_modulus(fixed_int& result, const fixed_int& a, limb_type b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1119,7 +1119,7 @@ inline void modulus(fixed_int& result, const fixed_int -inline void modulus(fixed_int& result, const fixed_int& a, signed_limb_type b) +inline void eval_modulus(fixed_int& result, const fixed_int& a, signed_limb_type b) { fixed_int r; if(Signed && (a.data()[0] & fixed_int::sign_bit_mask)) @@ -1149,42 +1149,42 @@ inline void modulus(fixed_int& result, const fixed_int -inline void modulus(fixed_int& result, const fixed_int& b) +inline void eval_modulus(fixed_int& result, const fixed_int& b) { // There is no in place divide: fixed_int a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template -inline void modulus(fixed_int& result, limb_type b) +inline void eval_modulus(fixed_int& result, limb_type b) { // There is no in place divide: fixed_int a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template -inline void modulus(fixed_int& result, signed_limb_type b) +inline void eval_modulus(fixed_int& result, signed_limb_type b) { // There is no in place divide: fixed_int a(result); - modulus(result, a, b); + eval_modulus(result, a, b); } template -inline void bitwise_and(fixed_int& result, const fixed_int& o) +inline void eval_bitwise_and(fixed_int& result, const fixed_int& o) { for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count; ++i) result.data()[i] &= o.data()[i]; } template -inline void bitwise_and(fixed_int& result, limb_type o) +inline void eval_bitwise_and(fixed_int& result, limb_type o) { result.data()[fixed_int::limb_count - 1] &= o; for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count - 1; ++i) result.data()[i] = 0; } template -inline void bitwise_and(fixed_int& result, signed_limb_type o) +inline void eval_bitwise_and(fixed_int& result, signed_limb_type o) { result.data()[fixed_int::limb_count - 1] &= o; limb_type mask = o < 0 ? fixed_int::max_limb_value : 0; @@ -1192,18 +1192,18 @@ inline void bitwise_and(fixed_int& result, signed_limb_type o) result.data()[i] &= mask; } template -inline void bitwise_or(fixed_int& result, const fixed_int& o) +inline void eval_bitwise_or(fixed_int& result, const fixed_int& o) { for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count; ++i) result.data()[i] |= o.data()[i]; } template -inline void bitwise_or(fixed_int& result, limb_type o) +inline void eval_bitwise_or(fixed_int& result, limb_type o) { result.data()[fixed_int::limb_count - 1] |= o; } template -inline void bitwise_or(fixed_int& result, signed_limb_type o) +inline void eval_bitwise_or(fixed_int& result, signed_limb_type o) { result.data()[fixed_int::limb_count - 1] |= o; limb_type mask = o < 0 ? fixed_int::max_limb_value : 0; @@ -1211,19 +1211,19 @@ inline void bitwise_or(fixed_int& result, signed_limb_type o) result.data()[i] |= mask; } template -inline void bitwise_xor(fixed_int& result, const fixed_int& o) +inline void eval_bitwise_xor(fixed_int& result, const fixed_int& o) { for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count; ++i) result.data()[i] ^= o.data()[i]; result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void bitwise_xor(fixed_int& result, limb_type o) +inline void eval_bitwise_xor(fixed_int& result, limb_type o) { result.data()[fixed_int::limb_count - 1] ^= o; } template -inline void bitwise_xor(fixed_int& result, signed_limb_type o) +inline void eval_bitwise_xor(fixed_int& result, signed_limb_type o) { result.data()[fixed_int::limb_count - 1] ^= o; limb_type mask = o < 0 ? fixed_int::max_limb_value : 0; @@ -1231,14 +1231,14 @@ inline void bitwise_xor(fixed_int& result, signed_limb_type o) result.data()[i] ^= mask; } template -inline void complement(fixed_int& result, const fixed_int& o) +inline void eval_complement(fixed_int& result, const fixed_int& o) { for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count; ++i) result.data()[i] = ~o.data()[i]; result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void left_shift(fixed_int& result, double_limb_type s) +inline void eval_left_shift(fixed_int& result, double_limb_type s) { if(!s) return; @@ -1273,7 +1273,7 @@ inline void left_shift(fixed_int& result, double_limb_type s) result.data()[0] &= fixed_int::upper_limb_mask; } template -inline void right_shift(fixed_int& result, double_limb_type s) +inline void eval_right_shift(fixed_int& result, double_limb_type s) { if(!s) return; @@ -1317,22 +1317,22 @@ inline void right_shift(fixed_int& result, double_limb_type s) } template -inline typename enable_if, void>::type convert_to(R* result, const fixed_int& backend, const mpl::true_&) +inline typename enable_if, void>::type eval_convert_to(R* result, const fixed_int& backend, const mpl::true_&) { if(backend.data()[0] & fixed_int::sign_bit_mask) { fixed_int t(backend); t.negate(); - convert_to(result, t, mpl::false_()); + eval_convert_to(result, t, mpl::false_()); *result = -*result; return; } else - convert_to(result, backend, mpl::false_()); + eval_convert_to(result, backend, mpl::false_()); } template -inline typename enable_if, void>::type convert_to(R* result, const fixed_int& backend, const mpl::false_&) +inline typename enable_if, void>::type eval_convert_to(R* result, const fixed_int& backend, const mpl::false_&) { unsigned shift = (fixed_int::limb_count - 1) * fixed_int::limb_bits; *result = static_cast(0); @@ -1344,20 +1344,20 @@ inline typename enable_if, void>::type convert_to(R* result, cons } template -inline typename enable_if, void>::type convert_to(R* result, const fixed_int& backend) +inline typename enable_if, void>::type eval_convert_to(R* result, const fixed_int& backend) { typedef mpl::bool_::is_signed> tag_type; - convert_to(result, backend, tag_type()); + eval_convert_to(result, backend, tag_type()); } template -inline typename enable_if, void>::type convert_to(R* result, const fixed_int& backend) +inline typename enable_if, void>::type eval_convert_to(R* result, const fixed_int& backend) { if(Signed && (backend.data()[0] & fixed_int::sign_bit_mask)) { fixed_int t(backend); t.negate(); - convert_to(result, t); + eval_convert_to(result, t); *result = -*result; return; } @@ -1371,7 +1371,7 @@ inline typename enable_if, void>::type convert_to(R* result } template -inline bool is_zero(const fixed_int& val) +inline bool eval_is_zero(const fixed_int& val) { for(typename fixed_int::data_type::size_type i = 0; i < fixed_int::limb_count; ++i) { @@ -1381,14 +1381,14 @@ inline bool is_zero(const fixed_int& val) return true; } template -inline int get_sign(const fixed_int& val) +inline int eval_get_sign(const fixed_int& val) { - return is_zero(val) ? 0 : 1; + return eval_is_zero(val) ? 0 : 1; } template -inline int get_sign(const fixed_int& val) +inline int eval_get_sign(const fixed_int& val) { - return is_zero(val) ? 0 : val.data()[0] & fixed_int::sign_bit_mask ? -1 : 1; + return eval_is_zero(val) ? 0 : val.data()[0] & fixed_int::sign_bit_mask ? -1 : 1; } namespace detail{ @@ -1398,7 +1398,7 @@ namespace detail{ template inline unsigned get_lsb(const fixed_int& a) { - BOOST_ASSERT(get_sign(a) != 0); + BOOST_ASSERT(eval_get_sign(a) != 0); unsigned result = 0; // @@ -1429,7 +1429,7 @@ inline void eval_gcd(fixed_int& result, const fixed_int u(a), v(b); - int s = get_sign(u); + int s = eval_get_sign(u); /* GCD(0,x) := x */ if(s < 0) @@ -1441,7 +1441,7 @@ inline void eval_gcd(fixed_int& result, const fixed_int& result, const fixed_int& result, const fixed_int 0) u.swap(v); - subtract(v, u); + eval_subtract(v, u); // Termination condition tries not to do a full compare if possible: - if(!v.data()[fixed_int::limb_count - 1] && is_zero(v)) + if(!v.data()[fixed_int::limb_count - 1] && eval_is_zero(v)) break; vs = detail::get_lsb(v); - right_shift(v, vs); + eval_right_shift(v, vs); BOOST_ASSERT((v.data()[fixed_int::limb_count - 1] & 1)); BOOST_ASSERT((u.data()[fixed_int::limb_count - 1] & 1)); } while(true); result = u; - left_shift(result, shift); + eval_left_shift(result, shift); } template @@ -1488,16 +1488,16 @@ inline void eval_lcm(fixed_int& result, const fixed_int t; eval_gcd(t, a, b); - if(is_zero(t)) + if(eval_is_zero(t)) { result = static_cast(0); } else { - divide(result, a, t); - multiply(result, b); + eval_divide(result, a, t); + eval_multiply(result, b); } - if(get_sign(result) < 0) + if(eval_get_sign(result) < 0) result.negate(); } diff --git a/include/boost/multiprecision/gmp.hpp b/include/boost/multiprecision/gmp.hpp index 648d60c5..f2104de9 100644 --- a/include/boost/multiprecision/gmp.hpp +++ b/include/boost/multiprecision/gmp.hpp @@ -16,7 +16,9 @@ #include #include -namespace boost{ namespace multiprecision{ +namespace boost{ +namespace multiprecision{ +namespace backends{ template struct gmp_float; @@ -473,47 +475,47 @@ struct gmp_float<0> : public detail::gmp_float_imp<0> }; template -inline void add(gmp_float& result, const gmp_float& o) +inline void eval_add(gmp_float& result, const gmp_float& o) { mpf_add(result.data(), result.data(), o.data()); } template -inline void subtract(gmp_float& result, const gmp_float& o) +inline void eval_subtract(gmp_float& result, const gmp_float& o) { mpf_sub(result.data(), result.data(), o.data()); } template -inline void multiply(gmp_float& result, const gmp_float& o) +inline void eval_multiply(gmp_float& result, const gmp_float& o) { mpf_mul(result.data(), result.data(), o.data()); } template -inline void divide(gmp_float& result, const gmp_float& o) +inline void eval_divide(gmp_float& result, const gmp_float& o) { mpf_div(result.data(), result.data(), o.data()); } template -inline void add(gmp_float& result, unsigned long i) +inline void eval_add(gmp_float& result, unsigned long i) { mpf_add_ui(result.data(), result.data(), i); } template -inline void subtract(gmp_float& result, unsigned long i) +inline void eval_subtract(gmp_float& result, unsigned long i) { mpf_sub_ui(result.data(), result.data(), i); } template -inline void multiply(gmp_float& result, unsigned long i) +inline void eval_multiply(gmp_float& result, unsigned long i) { mpf_mul_ui(result.data(), result.data(), i); } template -inline void divide(gmp_float& result, unsigned long i) +inline void eval_divide(gmp_float& result, unsigned long i) { mpf_div_ui(result.data(), result.data(), i); } template -inline void add(gmp_float& result, long i) +inline void eval_add(gmp_float& result, long i) { if(i > 0) mpf_add_ui(result.data(), result.data(), i); @@ -521,7 +523,7 @@ inline void add(gmp_float& result, long i) mpf_sub_ui(result.data(), result.data(), std::abs(i)); } template -inline void subtract(gmp_float& result, long i) +inline void eval_subtract(gmp_float& result, long i) { if(i > 0) mpf_sub_ui(result.data(), result.data(), i); @@ -529,14 +531,14 @@ inline void subtract(gmp_float& result, long i) mpf_add_ui(result.data(), result.data(), std::abs(i)); } template -inline void multiply(gmp_float& result, long i) +inline void eval_multiply(gmp_float& 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_float& result, long i) +inline void eval_divide(gmp_float& result, long i) { mpf_div_ui(result.data(), result.data(), std::abs(i)); if(i < 0) @@ -546,17 +548,17 @@ inline void divide(gmp_float& result, long i) // Specialised 3 arg versions of the basic operators: // template -inline void add(gmp_float& a, const gmp_float& x, const gmp_float& y) +inline void eval_add(gmp_float& a, const gmp_float& x, const gmp_float& y) { mpf_add(a.data(), x.data(), y.data()); } template -inline void add(gmp_float& a, const gmp_float& x, unsigned long y) +inline void eval_add(gmp_float& a, const gmp_float& x, unsigned long y) { mpf_add_ui(a.data(), x.data(), y); } template -inline void add(gmp_float& a, const gmp_float& x, long y) +inline void eval_add(gmp_float& a, const gmp_float& x, long y) { if(y < 0) mpf_sub_ui(a.data(), x.data(), -y); @@ -564,12 +566,12 @@ inline void add(gmp_float& a, const gmp_float& x, long y) mpf_add_ui(a.data(), x.data(), y); } template -inline void add(gmp_float& a, unsigned long x, const gmp_float& y) +inline void eval_add(gmp_float& a, unsigned long x, const gmp_float& y) { mpf_add_ui(a.data(), y.data(), x); } template -inline void add(gmp_float& a, long x, const gmp_float& y) +inline void eval_add(gmp_float& a, long x, const gmp_float& y) { if(x < 0) { @@ -580,17 +582,17 @@ inline void add(gmp_float& a, long x, const gmp_float& y) mpf_add_ui(a.data(), y.data(), x); } template -inline void subtract(gmp_float& a, const gmp_float& x, const gmp_float& y) +inline void eval_subtract(gmp_float& a, const gmp_float& x, const gmp_float& y) { mpf_sub(a.data(), x.data(), y.data()); } template -inline void subtract(gmp_float& a, const gmp_float& x, unsigned long y) +inline void eval_subtract(gmp_float& a, const gmp_float& x, unsigned long y) { mpf_sub_ui(a.data(), x.data(), y); } template -inline void subtract(gmp_float& a, const gmp_float& x, long y) +inline void eval_subtract(gmp_float& a, const gmp_float& x, long y) { if(y < 0) mpf_add_ui(a.data(), x.data(), -y); @@ -598,12 +600,12 @@ inline void subtract(gmp_float& a, const gmp_float& x, long mpf_sub_ui(a.data(), x.data(), y); } template -inline void subtract(gmp_float& a, unsigned long x, const gmp_float& y) +inline void eval_subtract(gmp_float& a, unsigned long x, const gmp_float& y) { mpf_ui_sub(a.data(), x, y.data()); } template -inline void subtract(gmp_float& a, long x, const gmp_float& y) +inline void eval_subtract(gmp_float& a, long x, const gmp_float& y) { if(x < 0) { @@ -615,17 +617,17 @@ inline void subtract(gmp_float& a, long x, const gmp_float& } template -inline void multiply(gmp_float& a, const gmp_float& x, const gmp_float& y) +inline void eval_multiply(gmp_float& a, const gmp_float& x, const gmp_float& y) { mpf_mul(a.data(), x.data(), y.data()); } template -inline void multiply(gmp_float& a, const gmp_float& x, unsigned long y) +inline void eval_multiply(gmp_float& a, const gmp_float& x, unsigned long y) { mpf_mul_ui(a.data(), x.data(), y); } template -inline void multiply(gmp_float& a, const gmp_float& x, long y) +inline void eval_multiply(gmp_float& a, const gmp_float& x, long y) { if(y < 0) { @@ -636,12 +638,12 @@ inline void multiply(gmp_float& a, const gmp_float& x, long mpf_mul_ui(a.data(), x.data(), y); } template -inline void multiply(gmp_float& a, unsigned long x, const gmp_float& y) +inline void eval_multiply(gmp_float& a, unsigned long x, const gmp_float& y) { mpf_mul_ui(a.data(), y.data(), x); } template -inline void multiply(gmp_float& a, long x, const gmp_float& y) +inline void eval_multiply(gmp_float& a, long x, const gmp_float& y) { if(x < 0) { @@ -653,17 +655,17 @@ inline void multiply(gmp_float& a, long x, const gmp_float& } template -inline void divide(gmp_float& a, const gmp_float& x, const gmp_float& y) +inline void eval_divide(gmp_float& a, const gmp_float& x, const gmp_float& y) { mpf_div(a.data(), x.data(), y.data()); } template -inline void divide(gmp_float& a, const gmp_float& x, unsigned long y) +inline void eval_divide(gmp_float& a, const gmp_float& x, unsigned long y) { mpf_div_ui(a.data(), x.data(), y); } template -inline void divide(gmp_float& a, const gmp_float& x, long y) +inline void eval_divide(gmp_float& a, const gmp_float& x, long y) { if(y < 0) { @@ -674,12 +676,12 @@ inline void divide(gmp_float& a, const gmp_float& x, long y) mpf_div_ui(a.data(), x.data(), y); } template -inline void divide(gmp_float& a, unsigned long x, const gmp_float& y) +inline void eval_divide(gmp_float& a, unsigned long x, const gmp_float& y) { mpf_ui_div(a.data(), x, y.data()); } template -inline void divide(gmp_float& a, long x, const gmp_float& y) +inline void eval_divide(gmp_float& a, long x, const gmp_float& y) { if(x < 0) { @@ -691,18 +693,18 @@ inline void divide(gmp_float& a, long x, const gmp_float& y) } template -inline bool is_zero(const gmp_float& val) +inline bool eval_is_zero(const gmp_float& val) { return mpf_sgn(val.data()) == 0; } template -inline int get_sign(const gmp_float& val) +inline int eval_get_sign(const gmp_float& val) { return mpf_sgn(val.data()); } template -inline void convert_to(unsigned long* result, const gmp_float& val) +inline void eval_convert_to(unsigned long* result, const gmp_float& val) { if(0 == mpf_fits_ulong_p(val.data())) *result = (std::numeric_limits::max)(); @@ -710,7 +712,7 @@ inline void convert_to(unsigned long* result, const gmp_float& val) *result = mpf_get_ui(val.data()); } template -inline void convert_to(long* result, const gmp_float& val) +inline void eval_convert_to(long* result, const gmp_float& val) { if(0 == mpf_fits_slong_p(val.data())) { @@ -721,16 +723,16 @@ inline void convert_to(long* result, const gmp_float& val) *result = mpf_get_si(val.data()); } template -inline void convert_to(double* result, const gmp_float& val) +inline void eval_convert_to(double* result, const gmp_float& val) { *result = mpf_get_d(val.data()); } #ifdef BOOST_HAS_LONG_LONG template -inline void convert_to(long long* result, const gmp_float& val) +inline void eval_convert_to(long long* result, const gmp_float& val) { gmp_float t(val); - if(get_sign(t) < 0) + if(eval_get_sign(t) < 0) t.negate(); long digits = std::numeric_limits::digits - std::numeric_limits::digits; @@ -740,7 +742,7 @@ inline void convert_to(long long* result, const gmp_float& val) if(!mpf_fits_slong_p(t.data())) { - if(get_sign(val) < 0) + if(eval_get_sign(val) < 0) *result = (std::numeric_limits::min)(); else *result = (std::numeric_limits::max)(); @@ -758,11 +760,11 @@ inline void convert_to(long long* result, const gmp_float& val) l >>= -digits; *result |= l; } - if(get_sign(val) < 0) + if(eval_get_sign(val) < 0) *result = -*result; } template -inline void convert_to(unsigned long long* result, const gmp_float& val) +inline void eval_convert_to(unsigned long long* result, const gmp_float& val) { gmp_float t(val); @@ -1094,23 +1096,23 @@ protected: mpz_t m_data; }; -inline void add(gmp_int& t, const gmp_int& o) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_modulus(gmp_int& t, const gmp_int& o) { bool neg = mpz_sgn(t.data()) < 0; bool neg2 = mpz_sgn(o.data()) < 0; @@ -1124,19 +1126,19 @@ inline void modulus(gmp_int& t, const gmp_int& o) t.negate(); } } -inline void add(gmp_int& t, unsigned long i) +inline void eval_add(gmp_int& t, unsigned long i) { mpz_add_ui(t.data(), t.data(), i); } -inline void subtract(gmp_int& t, unsigned long i) +inline void eval_subtract(gmp_int& t, unsigned long i) { mpz_sub_ui(t.data(), t.data(), i); } -inline void multiply(gmp_int& t, unsigned long i) +inline void eval_multiply(gmp_int& t, unsigned long i) { mpz_mul_ui(t.data(), t.data(), i); } -inline void modulus(gmp_int& t, unsigned long i) +inline void eval_modulus(gmp_int& t, unsigned long i) { bool neg = mpz_sgn(t.data()) < 0; mpz_mod_ui(t.data(), t.data(), i); @@ -1147,31 +1149,31 @@ inline void modulus(gmp_int& t, unsigned long i) t.negate(); } } -inline void divide(gmp_int& t, unsigned long i) +inline void eval_divide(gmp_int& t, unsigned long i) { mpz_div_ui(t.data(), t.data(), i); } -inline void add(gmp_int& t, long i) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_modulus(gmp_int& t, long i) { bool neg = mpz_sgn(t.data()) < 0; bool neg2 = i < 0; @@ -1190,65 +1192,65 @@ inline void modulus(gmp_int& t, long i) } } } -inline void divide(gmp_int& t, long i) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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; @@ -1262,19 +1264,19 @@ inline void modulus(gmp_int& t, const gmp_int& p, const gmp_int& o) t.negate(); } } -inline void add(gmp_int& t, const gmp_int& p, unsigned long i) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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); @@ -1285,31 +1287,31 @@ inline void modulus(gmp_int& t, const gmp_int& p, unsigned long i) t.negate(); } } -inline void divide(gmp_int& t, const gmp_int& p, unsigned long i) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_modulus(gmp_int& t, const gmp_int& p, long i) { bool neg = mpz_sgn(p.data()) < 0; bool neg2 = i < 0; @@ -1328,42 +1330,42 @@ inline void modulus(gmp_int& t, const gmp_int& p, long i) } } } -inline void divide(gmp_int& t, const gmp_int& p, long i) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_complement(gmp_int& result, const gmp_int& u) { mpz_com(result.data(), u.data()); } -inline bool is_zero(const gmp_int& val) +inline bool eval_is_zero(const gmp_int& val) { return mpz_sgn(val.data()) == 0; } -inline int get_sign(const gmp_int& val) +inline int eval_get_sign(const gmp_int& val) { return mpz_sgn(val.data()); } -inline void convert_to(unsigned long* result, const gmp_int& val) +inline void eval_convert_to(unsigned long* result, const gmp_int& val) { if(0 == mpz_fits_ulong_p(val.data())) { @@ -1372,7 +1374,7 @@ inline void convert_to(unsigned long* result, const gmp_int& val) else *result = mpz_get_ui(val.data()); } -inline void convert_to(long* result, const gmp_int& val) +inline void eval_convert_to(long* result, const gmp_int& val) { if(0 == mpz_fits_slong_p(val.data())) { @@ -1382,7 +1384,7 @@ inline void convert_to(long* result, const gmp_int& val) else *result = mpz_get_si(val.data()); } -inline void convert_to(double* result, const gmp_int& val) +inline void eval_convert_to(double* result, const gmp_int& val) { *result = mpz_get_d(val.data()); } @@ -1418,7 +1420,7 @@ inline void eval_lcm(gmp_int& result, const gmp_int& a, const long b) } struct gmp_rational; -void add(gmp_rational& t, const gmp_rational& o); +void eval_add(gmp_rational& t, const gmp_rational& o); struct gmp_rational { @@ -1503,8 +1505,8 @@ struct gmp_rational using std::frexp; using std::ldexp; using std::floor; - using default_ops::add; - using default_ops::subtract; + using default_ops::eval_add; + using default_ops::eval_subtract; if (a == 0) { mpq_set_si(m_data, 0, 1); @@ -1537,7 +1539,7 @@ struct gmp_rational e -= shift; mpq_mul_2exp(m_data, m_data, shift); t = static_cast(term); - add(*this, t); + eval_add(*this, t); f -= term; } if(e > 0) @@ -1628,69 +1630,63 @@ inline mp_number denominator(const mp_number& val) return result; } -template <> -struct component_type > -{ - typedef mp_number type; -}; - -inline void add(gmp_rational& t, const gmp_rational& o) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline void eval_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) +inline bool eval_is_zero(const gmp_rational& val) { return mpq_sgn(val.data()) == 0; } -inline int get_sign(const gmp_rational& val) +inline int eval_get_sign(const gmp_rational& val) { return mpq_sgn(val.data()); } -inline void convert_to(double* result, const gmp_rational& val) +inline void eval_convert_to(double* result, const gmp_rational& val) { *result = mpq_get_d(val.data()); } -inline void convert_to(long* result, const gmp_rational& val) +inline void eval_convert_to(long* result, const gmp_rational& val) { double r; - convert_to(&r, val); + eval_convert_to(&r, val); *result = static_cast(r); } -inline void convert_to(unsigned long* result, const gmp_rational& val) +inline void eval_convert_to(unsigned long* result, const gmp_rational& val) { double r; - convert_to(&r, val); + eval_convert_to(&r, val); *result = static_cast(r); } @@ -1788,6 +1784,17 @@ inline gmp_int& gmp_int::operator=(const gmp_rational& o) return *this; } +} //namespace backends + +using boost::multiprecision::backends::gmp_int; +using boost::multiprecision::backends::gmp_rational; +using boost::multiprecision::backends::gmp_float; + +template <> +struct component_type > +{ + typedef mp_number type; +}; template<> struct number_category : public mpl::int_{}; diff --git a/include/boost/multiprecision/mp_number.hpp b/include/boost/multiprecision/mp_number.hpp index bb48f629..22e18403 100644 --- a/include/boost/multiprecision/mp_number.hpp +++ b/include/boost/multiprecision/mp_number.hpp @@ -150,8 +150,8 @@ public: typename enable_if, mp_number& >::type operator+=(const V& v) { - using default_ops::add; - add(m_backend, canonical_value(v)); + using default_ops::eval_add; + eval_add(m_backend, canonical_value(v)); return *this; } @@ -181,8 +181,8 @@ public: typename enable_if, mp_number& >::type operator-=(const V& v) { - using default_ops::subtract; - subtract(m_backend, canonical_value(v)); + using default_ops::eval_subtract; + eval_subtract(m_backend, canonical_value(v)); return *this; } @@ -214,8 +214,8 @@ public: typename enable_if, mp_number& >::type operator*=(const V& v) { - using default_ops::multiply; - multiply(m_backend, canonical_value(v)); + using default_ops::eval_multiply; + eval_multiply(m_backend, canonical_value(v)); return *this; } @@ -246,8 +246,8 @@ public: operator%=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The modulus operation is only valid for integer types"); - using default_ops::modulus; - modulus(m_backend, canonical_value(v)); + using default_ops::eval_modulus; + eval_modulus(m_backend, canonical_value(v)); return *this; } @@ -261,31 +261,31 @@ public: // mp_number& operator++() { - using default_ops::increment; - increment(m_backend); + using default_ops::eval_increment; + eval_increment(m_backend); return *this; } mp_number& operator--() { - using default_ops::decrement; - decrement(m_backend); + using default_ops::eval_decrement; + eval_decrement(m_backend); return *this; } mp_number operator++(int) { - using default_ops::increment; + using default_ops::eval_increment; self_type temp(*this); - increment(m_backend); + eval_increment(m_backend); return temp; } mp_number operator--(int) { - using default_ops::decrement; + using default_ops::eval_decrement; self_type temp(*this); - decrement(m_backend); + eval_decrement(m_backend); return temp; } @@ -294,7 +294,7 @@ public: { 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)); + eval_left_shift(m_backend, canonical_value(val)); return *this; } @@ -303,7 +303,7 @@ public: { 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)); + eval_right_shift(m_backend, canonical_value(val)); return *this; } @@ -333,8 +333,8 @@ public: typename enable_if, mp_number& >::type operator/=(const V& v) { - using default_ops::divide; - divide(m_backend, canonical_value(v)); + using default_ops::eval_divide; + eval_divide(m_backend, canonical_value(v)); return *this; } @@ -368,8 +368,8 @@ public: operator&=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise & operation is only valid for integer types"); - using default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(v)); + using default_ops::eval_bitwise_and; + eval_bitwise_and(m_backend, canonical_value(v)); return *this; } @@ -403,8 +403,8 @@ public: operator|=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise | operation is only valid for integer types"); - using default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(v)); + using default_ops::eval_bitwise_or; + eval_bitwise_or(m_backend, canonical_value(v)); return *this; } @@ -436,8 +436,8 @@ public: operator^=(const V& v) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ^ operation is only valid for integer types"); - using default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(v)); + using default_ops::eval_bitwise_xor; + eval_bitwise_xor(m_backend, canonical_value(v)); return *this; } // @@ -462,13 +462,13 @@ public: // bool is_zero()const { - using default_ops::is_zero; - return is_zero(m_backend); + using default_ops::eval_is_zero; + return eval_is_zero(m_backend); } int sign()const { - using default_ops::get_sign; - return get_sign(m_backend); + using default_ops::eval_get_sign; + return eval_get_sign(m_backend); } // // String conversion functions: @@ -480,9 +480,9 @@ public: template T convert_to()const { - using default_ops::convert_to; + using default_ops::eval_convert_to; T result; - convert_to(&result, m_backend); + eval_convert_to(&result, m_backend); return result; } // @@ -514,9 +514,9 @@ public: template typename enable_if, int>::type compare(const V& o)const { - using default_ops::get_sign; + using default_ops::eval_get_sign; if(o == 0) - return get_sign(m_backend); + return eval_get_sign(m_backend); return m_backend.compare(canonical_value(o)); } Backend& backend() @@ -554,36 +554,36 @@ private: template void do_assign(const Exp& e, const detail::add_immediates&) { - using default_ops::add; - add(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_add; + eval_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 default_ops::add; - add(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_add; + eval_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 default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_subtract; + eval_subtract(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template void do_assign(const Exp& e, const detail::multiply_immediates&) { - using default_ops::multiply; - multiply(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_multiply; + eval_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 default_ops::divide; - divide(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_divide; + eval_divide(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template @@ -768,8 +768,8 @@ private: 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 default_ops::modulus; - modulus(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_modulus; + eval_modulus(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template @@ -813,8 +813,8 @@ private: 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 default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_bitwise_and; + eval_bitwise_and(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template @@ -858,8 +858,8 @@ private: 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 default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_bitwise_or; + eval_bitwise_or(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template @@ -903,8 +903,8 @@ private: 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 default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); + using default_ops::eval_bitwise_xor; + eval_bitwise_xor(m_backend, canonical_value(e.left().value()), canonical_value(e.right().value())); } template void do_assign(const Exp& e, const detail::terminal&) @@ -952,51 +952,51 @@ private: void do_assign(const Exp& e, const detail::bitwise_complement&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ~ operation is only valid for integer types"); - using default_ops::complement; + using default_ops::eval_complement; self_type temp(e.left()); - complement(m_backend, temp.backend()); + eval_complement(m_backend, temp.backend()); } template void do_assign(const Exp& e, const detail::complement_immediates&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ~ operation is only valid for integer types"); - using default_ops::complement; - complement(m_backend, canonical_value(e.left().value())); + using default_ops::eval_complement; + eval_complement(m_backend, canonical_value(e.left().value())); } template void do_assign_right_shift(const Exp& e, const Val& val, const detail::terminal&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The right shift operation is only valid for integer types"); - using default_ops::right_shift; - right_shift(m_backend, canonical_value(e.value()), val); + using default_ops::eval_right_shift; + eval_right_shift(m_backend, canonical_value(e.value()), val); } template void do_assign_left_shift(const Exp& e, const Val& val, const detail::terminal&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The left shift operation is only valid for integer types"); - using default_ops::left_shift; - left_shift(m_backend, canonical_value(e.value()), val); + using default_ops::eval_left_shift; + eval_left_shift(m_backend, canonical_value(e.value()), val); } template void do_assign_right_shift(const Exp& e, const Val& val, const Tag&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The right shift operation is only valid for integer types"); - using default_ops::right_shift; + using default_ops::eval_right_shift; self_type temp(e); - right_shift(m_backend, temp.backend(), val); + eval_right_shift(m_backend, temp.backend(), val); } template void do_assign_left_shift(const Exp& e, const Val& val, const Tag&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The left shift operation is only valid for integer types"); - using default_ops::left_shift; + using default_ops::eval_left_shift; self_type temp(e); - left_shift(m_backend, temp.backend(), val); + eval_left_shift(m_backend, temp.backend(), val); } template @@ -1059,8 +1059,8 @@ private: template void do_add(const Exp& e, const detail::terminal&) { - using default_ops::add; - add(m_backend, canonical_value(e.value())); + using default_ops::eval_add; + eval_add(m_backend, canonical_value(e.value())); } template @@ -1098,23 +1098,23 @@ private: template void do_add(const Exp& e, const detail::add_immediates&) { - using default_ops::add; - add(m_backend, canonical_value(e.left().value())); - add(m_backend, canonical_value(e.right().value())); + using default_ops::eval_add; + eval_add(m_backend, canonical_value(e.left().value())); + eval_add(m_backend, canonical_value(e.right().value())); } template void do_add(const Exp& e, const detail::subtract_immediates&) { - using default_ops::add; - using default_ops::subtract; - add(m_backend, canonical_value(e.left().value())); - subtract(m_backend, canonical_value(e.right().value())); + using default_ops::eval_add; + using default_ops::eval_subtract; + eval_add(m_backend, canonical_value(e.left().value())); + eval_subtract(m_backend, canonical_value(e.right().value())); } template void do_subtract(const Exp& e, const detail::terminal&) { - using default_ops::subtract; - subtract(m_backend, canonical_value(e.value())); + using default_ops::eval_subtract; + eval_subtract(m_backend, canonical_value(e.value())); } template @@ -1144,17 +1144,17 @@ private: template void do_subtract(const Exp& e, const detail::add_immediates&) { - using default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value())); - subtract(m_backend, canonical_value(e.right().value())); + using default_ops::eval_subtract; + eval_subtract(m_backend, canonical_value(e.left().value())); + eval_subtract(m_backend, canonical_value(e.right().value())); } template void do_subtract(const Exp& e, const detail::subtract_immediates&) { - using default_ops::add; - using default_ops::subtract; - subtract(m_backend, canonical_value(e.left().value())); - add(m_backend, canonical_value(e.right().value())); + using default_ops::eval_add; + using default_ops::eval_subtract; + eval_subtract(m_backend, canonical_value(e.left().value())); + eval_add(m_backend, canonical_value(e.right().value())); } template void do_subtract(const Exp& e, const unknown&) @@ -1166,8 +1166,8 @@ private: template void do_multiplies(const Exp& e, const detail::terminal&) { - using default_ops::multiply; - multiply(m_backend, canonical_value(e.value())); + using default_ops::eval_multiply; + eval_multiply(m_backend, canonical_value(e.value())); } template @@ -1199,31 +1199,31 @@ private: template void do_multiplies(const Exp& e, const detail::multiply_immediates&) { - using default_ops::multiply; - multiply(m_backend, canonical_value(e.left().value())); - multiply(m_backend, canonical_value(e.right().value())); + using default_ops::eval_multiply; + eval_multiply(m_backend, canonical_value(e.left().value())); + eval_multiply(m_backend, canonical_value(e.right().value())); } template void do_multiplies(const Exp& e, const detail::divide_immediates&) { - using default_ops::multiply; - using default_ops::divide; - multiply(m_backend, canonical_value(e.left().value())); - divide(m_backend, canonical_value(e.right().value())); + using default_ops::eval_multiply; + using default_ops::eval_divide; + eval_multiply(m_backend, canonical_value(e.left().value())); + eval_divide(m_backend, canonical_value(e.right().value())); } template void do_multiplies(const Exp& e, const unknown&) { - using default_ops::multiply; + using default_ops::eval_multiply; self_type temp(e); - multiply(m_backend, temp.m_backend); + eval_multiply(m_backend, temp.m_backend); } template void do_divide(const Exp& e, const detail::terminal&) { - using default_ops::divide; - divide(m_backend, canonical_value(e.value())); + using default_ops::eval_divide; + eval_divide(m_backend, canonical_value(e.value())); } template @@ -1255,50 +1255,50 @@ private: template void do_divides(const Exp& e, const detail::multiply_immediates&) { - using default_ops::divide; - divide(m_backend, canonical_value(e.left().value())); - divide(m_backend, canonical_value(e.right().value())); + using default_ops::eval_divide; + eval_divide(m_backend, canonical_value(e.left().value())); + eval_divide(m_backend, canonical_value(e.right().value())); } template void do_divides(const Exp& e, const detail::divide_immediates&) { - using default_ops::multiply; - using default_ops::divide; - divide(m_backend, canonical_value(e.left().value())); + using default_ops::eval_multiply; + using default_ops::eval_divide; + eval_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 default_ops::multiply; + using default_ops::eval_multiply; self_type temp(e); - divide(m_backend, temp.m_backend); + eval_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 default_ops::modulus; - modulus(m_backend, canonical_value(e.value())); + using default_ops::eval_modulus; + eval_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 default_ops::modulus; + using default_ops::eval_modulus; self_type temp(e); - modulus(m_backend, canonical_value(temp)); + eval_modulus(m_backend, canonical_value(temp)); } template void do_bitwise_and(const Exp& e, const detail::terminal&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise & operation is only valid for integer types"); - using default_ops::bitwise_and; - bitwise_and(m_backend, canonical_value(e.value())); + using default_ops::eval_bitwise_and; + eval_bitwise_and(m_backend, canonical_value(e.value())); } template void do_bitwise_and(const Exp& e, const detail::bitwise_and&) @@ -1313,17 +1313,17 @@ private: void do_bitwise_and(const Exp& e, const unknown&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise & operation is only valid for integer types"); - using default_ops::bitwise_and; + using default_ops::eval_bitwise_and; self_type temp(e); - bitwise_and(m_backend, temp.m_backend); + eval_bitwise_and(m_backend, temp.m_backend); } template void do_bitwise_or(const Exp& e, const detail::terminal&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise | operation is only valid for integer types"); - using default_ops::bitwise_or; - bitwise_or(m_backend, canonical_value(e.value())); + using default_ops::eval_bitwise_or; + eval_bitwise_or(m_backend, canonical_value(e.value())); } template void do_bitwise_or(const Exp& e, const detail::bitwise_or&) @@ -1338,17 +1338,17 @@ private: void do_bitwise_or(const Exp& e, const unknown&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise | operation is only valid for integer types"); - using default_ops::bitwise_or; + using default_ops::eval_bitwise_or; self_type temp(e); - bitwise_or(m_backend, temp.m_backend); + eval_bitwise_or(m_backend, temp.m_backend); } template void do_bitwise_xor(const Exp& e, const detail::terminal&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ^ operation is only valid for integer types"); - using default_ops::bitwise_xor; - bitwise_xor(m_backend, canonical_value(e.value())); + using default_ops::eval_bitwise_xor; + eval_bitwise_xor(m_backend, canonical_value(e.value())); } template void do_bitwise_xor(const Exp& e, const detail::bitwise_xor&) @@ -1363,9 +1363,9 @@ private: void do_bitwise_xor(const Exp& e, const unknown&) { BOOST_STATIC_ASSERT_MSG(number_category::value == number_kind_integer, "The bitwise ^ operation is only valid for integer types"); - using default_ops::bitwise_xor; + using default_ops::eval_bitwise_xor; self_type temp(e); - bitwise_xor(m_backend, temp.m_backend); + eval_bitwise_xor(m_backend, temp.m_backend); } // Tests if the expression contains a reference to *this: diff --git a/include/boost/multiprecision/mpfr.hpp b/include/boost/multiprecision/mpfr.hpp index fc7e7f05..9f5e3ce1 100644 --- a/include/boost/multiprecision/mpfr.hpp +++ b/include/boost/multiprecision/mpfr.hpp @@ -16,7 +16,9 @@ #include #include -namespace boost{ namespace multiprecision{ +namespace boost{ +namespace multiprecision{ +namespace backends{ template struct mpfr_float_backend; @@ -560,47 +562,47 @@ struct mpfr_float_backend<0> : public detail::mpfr_float_imp<0> }; template -inline void add(mpfr_float_backend& result, const mpfr_float_backend& o) +inline void eval_add(mpfr_float_backend& result, const mpfr_float_backend& o) { mpfr_add(result.data(), result.data(), o.data(), GMP_RNDN); } template -inline void subtract(mpfr_float_backend& result, const mpfr_float_backend& o) +inline void eval_subtract(mpfr_float_backend& result, const mpfr_float_backend& o) { mpfr_sub(result.data(), result.data(), o.data(), GMP_RNDN); } template -inline void multiply(mpfr_float_backend& result, const mpfr_float_backend& o) +inline void eval_multiply(mpfr_float_backend& result, const mpfr_float_backend& o) { mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN); } template -inline void divide(mpfr_float_backend& result, const mpfr_float_backend& o) +inline void eval_divide(mpfr_float_backend& result, const mpfr_float_backend& o) { mpfr_div(result.data(), result.data(), o.data(), GMP_RNDN); } template -inline void add(mpfr_float_backend& result, unsigned long i) +inline void eval_add(mpfr_float_backend& result, unsigned long i) { mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN); } template -inline void subtract(mpfr_float_backend& result, unsigned long i) +inline void eval_subtract(mpfr_float_backend& result, unsigned long i) { mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN); } template -inline void multiply(mpfr_float_backend& result, unsigned long i) +inline void eval_multiply(mpfr_float_backend& result, unsigned long i) { mpfr_mul_ui(result.data(), result.data(), i, GMP_RNDN); } template -inline void divide(mpfr_float_backend& result, unsigned long i) +inline void eval_divide(mpfr_float_backend& result, unsigned long i) { mpfr_div_ui(result.data(), result.data(), i, GMP_RNDN); } template -inline void add(mpfr_float_backend& result, long i) +inline void eval_add(mpfr_float_backend& result, long i) { if(i > 0) mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN); @@ -608,7 +610,7 @@ inline void add(mpfr_float_backend& result, long i) mpfr_sub_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); } template -inline void subtract(mpfr_float_backend& result, long i) +inline void eval_subtract(mpfr_float_backend& result, long i) { if(i > 0) mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN); @@ -616,14 +618,14 @@ inline void subtract(mpfr_float_backend& result, long i) mpfr_add_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); } template -inline void multiply(mpfr_float_backend& result, long i) +inline void eval_multiply(mpfr_float_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_float_backend& result, long i) +inline void eval_divide(mpfr_float_backend& result, long i) { mpfr_div_ui(result.data(), result.data(), std::abs(i), GMP_RNDN); if(i < 0) @@ -633,17 +635,17 @@ inline void divide(mpfr_float_backend& result, long i) // Specialised 3 arg versions of the basic operators: // template -inline void add(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) +inline void eval_add(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) { mpfr_add(a.data(), x.data(), y.data(), GMP_RNDN); } template -inline void add(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) +inline void eval_add(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) { mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN); } template -inline void add(mpfr_float_backend& a, const mpfr_float_backend& x, long y) +inline void eval_add(mpfr_float_backend& a, const mpfr_float_backend& x, long y) { if(y < 0) mpfr_sub_ui(a.data(), x.data(), -y, GMP_RNDN); @@ -651,12 +653,12 @@ inline void add(mpfr_float_backend& a, const mpfr_float_backend -inline void add(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) +inline void eval_add(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) { mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN); } template -inline void add(mpfr_float_backend& a, long x, const mpfr_float_backend& y) +inline void eval_add(mpfr_float_backend& a, long x, const mpfr_float_backend& y) { if(x < 0) { @@ -667,17 +669,17 @@ inline void add(mpfr_float_backend& a, long x, const mpfr_float_backen mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN); } template -inline void subtract(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) +inline void eval_subtract(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) { mpfr_sub(a.data(), x.data(), y.data(), GMP_RNDN); } template -inline void subtract(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) +inline void eval_subtract(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) { mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN); } template -inline void subtract(mpfr_float_backend& a, const mpfr_float_backend& x, long y) +inline void eval_subtract(mpfr_float_backend& a, const mpfr_float_backend& x, long y) { if(y < 0) mpfr_add_ui(a.data(), x.data(), -y, GMP_RNDN); @@ -685,12 +687,12 @@ inline void subtract(mpfr_float_backend& a, const mpfr_float_backend -inline void subtract(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) +inline void eval_subtract(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) { mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN); } template -inline void subtract(mpfr_float_backend& a, long x, const mpfr_float_backend& y) +inline void eval_subtract(mpfr_float_backend& a, long x, const mpfr_float_backend& y) { if(x < 0) { @@ -702,17 +704,17 @@ inline void subtract(mpfr_float_backend& a, long x, const mpfr_float_b } template -inline void multiply(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) +inline void eval_multiply(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) { mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN); } template -inline void multiply(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) +inline void eval_multiply(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) { mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN); } template -inline void multiply(mpfr_float_backend& a, const mpfr_float_backend& x, long y) +inline void eval_multiply(mpfr_float_backend& a, const mpfr_float_backend& x, long y) { if(y < 0) { @@ -723,12 +725,12 @@ inline void multiply(mpfr_float_backend& a, const mpfr_float_backend -inline void multiply(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) +inline void eval_multiply(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) { mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN); } template -inline void multiply(mpfr_float_backend& a, long x, const mpfr_float_backend& y) +inline void eval_multiply(mpfr_float_backend& a, long x, const mpfr_float_backend& y) { if(x < 0) { @@ -740,17 +742,17 @@ inline void multiply(mpfr_float_backend& a, long x, const mpfr_float_b } template -inline void divide(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) +inline void eval_divide(mpfr_float_backend& a, const mpfr_float_backend& x, const mpfr_float_backend& y) { mpfr_div(a.data(), x.data(), y.data(), GMP_RNDN); } template -inline void divide(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) +inline void eval_divide(mpfr_float_backend& a, const mpfr_float_backend& x, unsigned long y) { mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN); } template -inline void divide(mpfr_float_backend& a, const mpfr_float_backend& x, long y) +inline void eval_divide(mpfr_float_backend& a, const mpfr_float_backend& x, long y) { if(y < 0) { @@ -761,12 +763,12 @@ inline void divide(mpfr_float_backend& a, const mpfr_float_backend -inline void divide(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) +inline void eval_divide(mpfr_float_backend& a, unsigned long x, const mpfr_float_backend& y) { mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN); } template -inline void divide(mpfr_float_backend& a, long x, const mpfr_float_backend& y) +inline void eval_divide(mpfr_float_backend& a, long x, const mpfr_float_backend& y) { if(x < 0) { @@ -778,45 +780,45 @@ inline void divide(mpfr_float_backend& a, long x, const mpfr_float_bac } template -inline bool is_zero(const mpfr_float_backend& val) +inline bool eval_is_zero(const mpfr_float_backend& val) { return 0 != mpfr_zero_p(val.data()); } template -inline int get_sign(const mpfr_float_backend& val) +inline int eval_get_sign(const mpfr_float_backend& val) { return mpfr_sgn(val.data()); } template -inline void convert_to(unsigned long* result, const mpfr_float_backend& val) +inline void eval_convert_to(unsigned long* result, const mpfr_float_backend& val) { *result = mpfr_get_ui(val.data(), GMP_RNDN); } template -inline void convert_to(long* result, const mpfr_float_backend& val) +inline void eval_convert_to(long* result, const mpfr_float_backend& val) { *result = mpfr_get_si(val.data(), GMP_RNDN); } #ifdef _MPFR_H_HAVE_INTMAX_T template -inline void convert_to(unsigned long long* result, const mpfr_float_backend& val) +inline void eval_convert_to(unsigned long long* result, const mpfr_float_backend& val) { *result = mpfr_get_uj(val.data(), GMP_RNDN); } template -inline void convert_to(long long* result, const mpfr_float_backend& val) +inline void eval_convert_to(long long* result, const mpfr_float_backend& val) { *result = mpfr_get_sj(val.data(), GMP_RNDN); } #endif template -inline void convert_to(double* result, const mpfr_float_backend& val) +inline void eval_convert_to(double* result, const mpfr_float_backend& val) { *result = mpfr_get_d(val.data(), GMP_RNDN); } template -inline void convert_to(long double* result, const mpfr_float_backend& val) +inline void eval_convert_to(long double* result, const mpfr_float_backend& val) { *result = mpfr_get_ld(val.data(), GMP_RNDN); } @@ -988,13 +990,17 @@ inline void eval_tanh(mpfr_float_backend& result, const mpfr_float_bac mpfr_tanh(result.data(), arg.data(), GMP_RNDN); } +} // namespace backends + +using boost::multiprecision::backends::mpfr_float_backend; + typedef mp_number > mpfr_float_50; typedef mp_number > mpfr_float_100; typedef mp_number > mpfr_float_500; typedef mp_number > mpfr_float_1000; typedef mp_number > mpfr_float; -} // namespace boost +} // namespace multiprecision namespace math{ @@ -1003,7 +1009,7 @@ namespace tools{ template <> inline int digits() { - return boost::multiprecision::detail::get_default_precision(); + return boost::multiprecision::backends::detail::get_default_precision(); } } diff --git a/include/boost/multiprecision/rational_adapter.hpp b/include/boost/multiprecision/rational_adapter.hpp index cc0e786b..2436147f 100644 --- a/include/boost/multiprecision/rational_adapter.hpp +++ b/include/boost/multiprecision/rational_adapter.hpp @@ -16,6 +16,7 @@ namespace boost{ namespace multiprecision{ +namespace backends{ template struct rational_adapter @@ -123,42 +124,42 @@ private: }; template -inline void add(rational_adapter& result, const rational_adapter& o) +inline void eval_add(rational_adapter& result, const rational_adapter& o) { result.data() += o.data(); } template -inline void subtract(rational_adapter& result, const rational_adapter& o) +inline void eval_subtract(rational_adapter& result, const rational_adapter& o) { result.data() -= o.data(); } template -inline void multiply(rational_adapter& result, const rational_adapter& o) +inline void eval_multiply(rational_adapter& result, const rational_adapter& o) { result.data() *= o.data(); } template -inline void divide(rational_adapter& result, const rational_adapter& o) +inline void eval_divide(rational_adapter& result, const rational_adapter& o) { result.data() /= o.data(); } template -inline void convert_to(R* result, const rational_adapter& backend) +inline void eval_convert_to(R* result, const rational_adapter& backend) { *result = backend.data().numerator().template convert_to(); *result /= backend.data().denominator().template convert_to(); } template -inline bool is_zero(const rational_adapter& val) +inline bool eval_is_zero(const rational_adapter& val) { - return is_zero(val.data().numerator().backend()); + return eval_is_zero(val.data().numerator().backend()); } template -inline int get_sign(const rational_adapter& val) +inline int eval_get_sign(const rational_adapter& val) { - return get_sign(val.data().numerator().backend()); + return eval_get_sign(val.data().numerator().backend()); } template @@ -181,6 +182,10 @@ inline void assign_components(rational_adapter& result, const V& v1, template struct number_category > : public mpl::int_{}; +} // namespace backends + +using boost::multiprecision::backends::rational_adapter; + template struct component_type > { diff --git a/include/boost/multiprecision/tommath.hpp b/include/boost/multiprecision/tommath.hpp index 683d5e5b..a30a3868 100644 --- a/include/boost/multiprecision/tommath.hpp +++ b/include/boost/multiprecision/tommath.hpp @@ -17,7 +17,7 @@ #include #include -namespace boost{ namespace multiprecision{ +namespace boost{ namespace multiprecision{ namespace backends{ namespace detail{ @@ -241,31 +241,31 @@ protected: if(SIGN(&x.data()))\ BOOST_THROW_EXCEPTION(std::runtime_error("Bitwise operations on libtommath negative valued integers are disabled as they produce unpredictable results")) -int get_sign(const tommath_int& val); +int eval_get_sign(const tommath_int& val); -inline void add(tommath_int& t, const tommath_int& o) +inline void eval_add(tommath_int& t, const tommath_int& o) { detail::check_tommath_result(mp_add(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void subtract(tommath_int& t, const tommath_int& o) +inline void eval_subtract(tommath_int& t, const tommath_int& o) { detail::check_tommath_result(mp_sub(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void multiply(tommath_int& t, const tommath_int& o) +inline void eval_multiply(tommath_int& t, const tommath_int& o) { detail::check_tommath_result(mp_mul(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void divide(tommath_int& t, const tommath_int& o) +inline void eval_divide(tommath_int& t, const tommath_int& o) { tommath_int temp; detail::check_tommath_result(mp_div(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data(), &temp.data())); } -inline void modulus(tommath_int& t, const tommath_int& o) +inline void eval_modulus(tommath_int& t, const tommath_int& o) { - bool neg = get_sign(t) < 0; - bool neg2 = get_sign(o) < 0; + bool neg = eval_get_sign(t) < 0; + bool neg2 = eval_get_sign(o) < 0; detail::check_tommath_result(mp_mod(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); - if((neg != neg2) && (get_sign(t) != 0)) + if((neg != neg2) && (eval_get_sign(t) != 0)) { t.negate(); detail::check_tommath_result(mp_add(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); @@ -277,72 +277,72 @@ inline void modulus(tommath_int& t, const tommath_int& o) } } template -inline void left_shift(tommath_int& t, UI i) +inline void eval_left_shift(tommath_int& t, UI i) { detail::check_tommath_result(mp_mul_2d(&t.data(), static_cast(i), &t.data())); } template -inline void right_shift(tommath_int& t, UI i) +inline void eval_right_shift(tommath_int& t, UI i) { tommath_int d; detail::check_tommath_result(mp_div_2d(&t.data(), static_cast(i), &t.data(), &d.data())); } template -inline void left_shift(tommath_int& t, const tommath_int& v, UI i) +inline void eval_left_shift(tommath_int& t, const tommath_int& v, UI i) { detail::check_tommath_result(mp_mul_2d(const_cast< ::mp_int*>(&v.data()), static_cast(i), &t.data())); } template -inline void right_shift(tommath_int& t, const tommath_int& v, UI i) +inline void eval_right_shift(tommath_int& t, const tommath_int& v, UI i) { tommath_int d; detail::check_tommath_result(mp_div_2d(const_cast< ::mp_int*>(&v.data()), static_cast(i), &t.data(), &d.data())); } -inline void bitwise_and(tommath_int& result, const tommath_int& v) +inline void eval_bitwise_and(tommath_int& result, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(result); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_and(&result.data(), const_cast< ::mp_int*>(&v.data()), &result.data())); } -inline void bitwise_or(tommath_int& result, const tommath_int& v) +inline void eval_bitwise_or(tommath_int& result, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(result); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_or(&result.data(), const_cast< ::mp_int*>(&v.data()), &result.data())); } -inline void bitwise_xor(tommath_int& result, const tommath_int& v) +inline void eval_bitwise_xor(tommath_int& result, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(result); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_xor(&result.data(), const_cast< ::mp_int*>(&v.data()), &result.data())); } -inline void add(tommath_int& t, const tommath_int& p, const tommath_int& o) +inline void eval_add(tommath_int& t, const tommath_int& p, const tommath_int& o) { detail::check_tommath_result(mp_add(const_cast< ::mp_int*>(&p.data()), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void subtract(tommath_int& t, const tommath_int& p, const tommath_int& o) +inline void eval_subtract(tommath_int& t, const tommath_int& p, const tommath_int& o) { detail::check_tommath_result(mp_sub(const_cast< ::mp_int*>(&p.data()), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void multiply(tommath_int& t, const tommath_int& p, const tommath_int& o) +inline void eval_multiply(tommath_int& t, const tommath_int& p, const tommath_int& o) { detail::check_tommath_result(mp_mul(const_cast< ::mp_int*>(&p.data()), const_cast< ::mp_int*>(&o.data()), &t.data())); } -inline void divide(tommath_int& t, const tommath_int& p, const tommath_int& o) +inline void eval_divide(tommath_int& t, const tommath_int& p, const tommath_int& o) { tommath_int d; detail::check_tommath_result(mp_div(const_cast< ::mp_int*>(&p.data()), const_cast< ::mp_int*>(&o.data()), &t.data(), &d.data())); } -inline void modulus(tommath_int& t, const tommath_int& p, const tommath_int& o) +inline void eval_modulus(tommath_int& t, const tommath_int& p, const tommath_int& o) { - bool neg = get_sign(p) < 0; - bool neg2 = get_sign(o) < 0; + bool neg = eval_get_sign(p) < 0; + bool neg2 = eval_get_sign(o) < 0; detail::check_tommath_result(mp_mod(const_cast< ::mp_int*>(&p.data()), const_cast< ::mp_int*>(&o.data()), &t.data())); - if((neg != neg2) && (get_sign(t) != 0)) + if((neg != neg2) && (eval_get_sign(t) != 0)) { t.negate(); detail::check_tommath_result(mp_add(&t.data(), const_cast< ::mp_int*>(&o.data()), &t.data())); @@ -354,28 +354,28 @@ inline void modulus(tommath_int& t, const tommath_int& p, const tommath_int& o) } } -inline void bitwise_and(tommath_int& result, const tommath_int& u, const tommath_int& v) +inline void eval_bitwise_and(tommath_int& result, const tommath_int& u, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(u); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_and(const_cast< ::mp_int*>(&u.data()), const_cast< ::mp_int*>(&v.data()), &result.data())); } -inline void bitwise_or(tommath_int& result, const tommath_int& u, const tommath_int& v) +inline void eval_bitwise_or(tommath_int& result, const tommath_int& u, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(u); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_or(const_cast< ::mp_int*>(&u.data()), const_cast< ::mp_int*>(&v.data()), &result.data())); } -inline void bitwise_xor(tommath_int& result, const tommath_int& u, const tommath_int& v) +inline void eval_bitwise_xor(tommath_int& result, const tommath_int& u, const tommath_int& v) { BOOST_MP_TOMMATH_BIT_OP_CHECK(u); BOOST_MP_TOMMATH_BIT_OP_CHECK(v); detail::check_tommath_result(mp_xor(const_cast< ::mp_int*>(&u.data()), const_cast< ::mp_int*>(&v.data()), &result.data())); } /* -inline void complement(tommath_int& result, const tommath_int& u) +inline void eval_complement(tommath_int& result, const tommath_int& u) { // // Although this code works, it doesn't really do what the user might expect.... @@ -400,32 +400,32 @@ inline void complement(tommath_int& result, const tommath_int& u) // Create a mask providing the extra bits we need and add to result: tommath_int mask; mask = static_cast((1u << padding) - 1); - left_shift(mask, shift); + eval_left_shift(mask, shift); add(result, mask); } */ -inline bool is_zero(const tommath_int& val) +inline bool eval_is_zero(const tommath_int& val) { return mp_iszero(&val.data()); } -inline int get_sign(const tommath_int& val) +inline int eval_get_sign(const tommath_int& val) { return mp_iszero(&val.data()) ? 0 : SIGN(&val.data()) ? -1 : 1; } template -inline void convert_to(A* result, const tommath_int& val) +inline void eval_convert_to(A* result, const tommath_int& val) { *result = boost::lexical_cast(val.str(0, std::ios_base::fmtflags(0))); } -inline void convert_to(char* result, const tommath_int& val) +inline void eval_convert_to(char* result, const tommath_int& val) { *result = static_cast(boost::lexical_cast(val.str(0, std::ios_base::fmtflags(0)))); } -inline void convert_to(unsigned char* result, const tommath_int& val) +inline void eval_convert_to(unsigned char* result, const tommath_int& val) { *result = static_cast(boost::lexical_cast(val.str(0, std::ios_base::fmtflags(0)))); } -inline void convert_to(signed char* result, const tommath_int& val) +inline void eval_convert_to(signed char* result, const tommath_int& val) { *result = static_cast(boost::lexical_cast(val.str(0, std::ios_base::fmtflags(0)))); } @@ -442,6 +442,9 @@ inline void eval_lcm(tommath_int& result, const tommath_int& a, const tommath_in detail::check_tommath_result(mp_lcm(const_cast< ::mp_int*>(&a.data()), const_cast< ::mp_int*>(&b.data()), const_cast< ::mp_int*>(&result.data()))); } +} // namespace backends + +using boost::multiprecision::backends::tommath_int; template<> struct number_category : public mpl::int_{}; diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index 5d5d47ea..b7e53e1d 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -1049,6 +1049,7 @@ int main() test(); test > >(); test > >(); + test(); #endif #ifdef TEST_CPP_INT_BR test();