From 68406722d5bf7a847e0497cae0d652b26c233396 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 17 Oct 2013 15:11:13 +0000 Subject: [PATCH] Fix type of cast target when casting to allocator. Add additional type of argument to frexp/ldexp. Template integer types in float IO conversion routines. Improve termination condition in asin code. Fix some compiler errors that can occur in conversion routines. [SVN r86339] --- include/boost/multiprecision/cpp_int.hpp | 4 ++-- include/boost/multiprecision/detail/default_ops.hpp | 6 ++++-- include/boost/multiprecision/detail/float_string_cvt.hpp | 3 ++- include/boost/multiprecision/detail/functions/pow.hpp | 2 +- include/boost/multiprecision/detail/functions/trig.hpp | 8 +++++++- .../boost/multiprecision/detail/generic_interconvert.hpp | 6 +++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/boost/multiprecision/cpp_int.hpp b/include/boost/multiprecision/cpp_int.hpp index b6510bdde..eeac1227d 100644 --- a/include/boost/multiprecision/cpp_int.hpp +++ b/include/boost/multiprecision/cpp_int.hpp @@ -283,7 +283,7 @@ struct cpp_int_base(o)), m_limbs(o.m_limbs), m_sign(o.m_sign), m_internal(o.m_internal) + : allocator_type(static_cast(o)), m_limbs(o.m_limbs), m_sign(o.m_sign), m_internal(o.m_internal) { if(m_internal) { @@ -300,7 +300,7 @@ struct cpp_int_base(this) = static_cast(o); + *static_cast(this) = static_cast(o); m_limbs = o.m_limbs; m_sign = o.m_sign; m_internal = o.m_internal; diff --git a/include/boost/multiprecision/detail/default_ops.hpp b/include/boost/multiprecision/detail/default_ops.hpp index 8e93be36c..2e79ad87e 100644 --- a/include/boost/multiprecision/detail/default_ops.hpp +++ b/include/boost/multiprecision/detail/default_ops.hpp @@ -2007,8 +2007,10 @@ UNARY_OP_FUNCTOR(cosh, number_kind_floating_point) UNARY_OP_FUNCTOR(sinh, number_kind_floating_point) UNARY_OP_FUNCTOR(tanh, number_kind_floating_point) -HETERO_BINARY_OP_FUNCTOR(ldexp, int, number_kind_floating_point) -HETERO_BINARY_OP_FUNCTOR(frexp, int*, number_kind_floating_point) +HETERO_BINARY_OP_FUNCTOR(ldexp, short, number_kind_floating_point) +HETERO_BINARY_OP_FUNCTOR(frexp, short*, number_kind_floating_point) +HETERO_BINARY_OP_FUNCTOR_B(ldexp, int, number_kind_floating_point) +HETERO_BINARY_OP_FUNCTOR_B(frexp, int*, number_kind_floating_point) HETERO_BINARY_OP_FUNCTOR_B(ldexp, long, number_kind_floating_point) HETERO_BINARY_OP_FUNCTOR_B(frexp, long*, number_kind_floating_point) HETERO_BINARY_OP_FUNCTOR_B(ldexp, long long, number_kind_floating_point) diff --git a/include/boost/multiprecision/detail/float_string_cvt.hpp b/include/boost/multiprecision/detail/float_string_cvt.hpp index 6e327788e..8b0f2a1f9 100644 --- a/include/boost/multiprecision/detail/float_string_cvt.hpp +++ b/include/boost/multiprecision/detail/float_string_cvt.hpp @@ -16,7 +16,8 @@ namespace boost{ namespace multiprecision{ namespace detail{ -inline void round_string_up_at(std::string& s, int pos, int& expon) +template +inline void round_string_up_at(std::string& s, int pos, I& expon) { // // Rounds up a string representation of a number at pos: diff --git a/include/boost/multiprecision/detail/functions/pow.hpp b/include/boost/multiprecision/detail/functions/pow.hpp index 7570916af..2e9689b21 100644 --- a/include/boost/multiprecision/detail/functions/pow.hpp +++ b/include/boost/multiprecision/detail/functions/pow.hpp @@ -227,7 +227,7 @@ void eval_exp(T& result, const T& x) xx.negate(); // Check the range of the argument. - static const canonical_exp_type maximum_arg_for_exp = std::numeric_limits >::max_exponent == 0 ? (std::numeric_limits::max)() : std::numeric_limits >::max_exponent; + static const canonical_exp_type maximum_arg_for_exp = std::numeric_limits >::max_exponent == 0 ? static_cast((std::numeric_limits::max)()) : std::numeric_limits >::max_exponent; if(xx.compare(maximum_arg_for_exp) >= 0) { diff --git a/include/boost/multiprecision/detail/functions/trig.hpp b/include/boost/multiprecision/detail/functions/trig.hpp index 6116b9866..8387c9cc5 100644 --- a/include/boost/multiprecision/detail/functions/trig.hpp +++ b/include/boost/multiprecision/detail/functions/trig.hpp @@ -488,8 +488,11 @@ void eval_asin(T& result, const T& x) result = fp_type(std::asin(dd)); + unsigned current_digits = std::numeric_limits::digits - 5; + unsigned target_precision = boost::multiprecision::detail::digits2 >::value; + // Newton-Raphson iteration - while(true) + while(current_digits < target_precision) { T s, c; eval_sin(s, result); @@ -498,6 +501,8 @@ void eval_asin(T& result, const T& x) eval_divide(s, c); eval_subtract(result, s); + current_digits *= 2; + /* T lim; eval_ldexp(lim, result, 1 - boost::multiprecision::detail::digits2 >::value); if(eval_get_sign(s) < 0) @@ -506,6 +511,7 @@ void eval_asin(T& result, const T& x) lim.negate(); if(lim.compare(s) >= 0) break; + */ } if(b_neg) result.negate(); diff --git a/include/boost/multiprecision/detail/generic_interconvert.hpp b/include/boost/multiprecision/detail/generic_interconvert.hpp index dbcae2dd0..e503a2404 100644 --- a/include/boost/multiprecision/detail/generic_interconvert.hpp +++ b/include/boost/multiprecision/detail/generic_interconvert.hpp @@ -143,12 +143,12 @@ void generic_interconvert(To& to, const From& from, const mpl::int_("nan"); return; } else if(c == FP_INFINITE) { - to = "inf"; + to = static_cast("inf"); if(eval_get_sign(from) < 0) to.negate(); return; @@ -177,7 +177,7 @@ void generic_interconvert(To& to, const From& from, const mpl::int_ (std::numeric_limits::max)()) || (e < (std::numeric_limits::min)())) { - to = "inf"; + to = static_cast("inf"); if(eval_get_sign(from) < 0) to.negate(); return;