Skip to content

Commit

Permalink
Fix type of cast target when casting to allocator.
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
jzmaddock committed Oct 17, 2013
1 parent 0a32de0 commit 6840672
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/boost/multiprecision/cpp_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ struct cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, fals
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
cpp_int_base(cpp_int_base&& o)
: allocator_type(static_cast<Allocator&&>(o)), m_limbs(o.m_limbs), m_sign(o.m_sign), m_internal(o.m_internal)
: allocator_type(static_cast<allocator_type&&>(o)), m_limbs(o.m_limbs), m_sign(o.m_sign), m_internal(o.m_internal)
{
if(m_internal)
{
Expand All @@ -300,7 +300,7 @@ struct cpp_int_base<MinBits, MaxBits, signed_magnitude, Checked, Allocator, fals
{
if(!m_internal)
allocator().deallocate(m_data.ld.data, m_data.ld.capacity);
*static_cast<Allocator*>(this) = static_cast<Allocator&&>(o);
*static_cast<allocator_type*>(this) = static_cast<allocator_type&&>(o);
m_limbs = o.m_limbs;
m_sign = o.m_sign;
m_internal = o.m_internal;
Expand Down
6 changes: 4 additions & 2 deletions include/boost/multiprecision/detail/default_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion include/boost/multiprecision/detail/float_string_cvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

namespace boost{ namespace multiprecision{ namespace detail{

inline void round_string_up_at(std::string& s, int pos, int& expon)
template <class I>
inline void round_string_up_at(std::string& s, int pos, I& expon)
{
//
// Rounds up a string representation of a number at pos:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/multiprecision/detail/functions/pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<number<T, et_on> >::max_exponent == 0 ? (std::numeric_limits<long>::max)() : std::numeric_limits<number<T, et_on> >::max_exponent;
static const canonical_exp_type maximum_arg_for_exp = std::numeric_limits<number<T, et_on> >::max_exponent == 0 ? static_cast<canonical_exp_type>((std::numeric_limits<long>::max)()) : std::numeric_limits<number<T, et_on> >::max_exponent;

if(xx.compare(maximum_arg_for_exp) >= 0)
{
Expand Down
8 changes: 7 additions & 1 deletion include/boost/multiprecision/detail/functions/trig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ void eval_asin(T& result, const T& x)

result = fp_type(std::asin(dd));

unsigned current_digits = std::numeric_limits<double>::digits - 5;
unsigned target_precision = boost::multiprecision::detail::digits2<number<T, et_on> >::value;

// Newton-Raphson iteration
while(true)
while(current_digits < target_precision)
{
T s, c;
eval_sin(s, result);
Expand All @@ -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<number<T, et_on> >::value);
if(eval_get_sign(s) < 0)
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions include/boost/multiprecision/detail/generic_interconvert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_
}
else if(c == FP_NAN)
{
to = "nan";
to = static_cast<const char*>("nan");
return;
}
else if(c == FP_INFINITE)
{
to = "inf";
to = static_cast<const char*>("inf");
if(eval_get_sign(from) < 0)
to.negate();
return;
Expand Down Expand Up @@ -177,7 +177,7 @@ void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_
typedef typename To::exponent_type to_exponent;
if((e > (std::numeric_limits<to_exponent>::max)()) || (e < (std::numeric_limits<to_exponent>::min)()))
{
to = "inf";
to = static_cast<const char*>("inf");
if(eval_get_sign(from) < 0)
to.negate();
return;
Expand Down

0 comments on commit 6840672

Please sign in to comment.