Skip to content

Commit

Permalink
Add some better error checks to interval construction.
Browse files Browse the repository at this point in the history
[SVN r86779]
  • Loading branch information
jzmaddock committed Nov 21, 2013
1 parent 25e5455 commit 239fd62
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions include/boost/multiprecision/mpfi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ struct mpfi_float_imp
}
mpfi_float_imp& operator = (const char* s)
{
using default_ops::eval_fpclassify;

if(m_data[0].left._mpfr_d == 0)
mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));

Expand All @@ -203,7 +205,22 @@ struct mpfi_float_imp
part.erase();
b = part.c_str();

mpfi_interv_fr(m_data, a.data(), b.data());
if(eval_fpclassify(a) == FP_NAN)
{
mpfi_set_fr(this->data(), a.data());
}
else if(eval_fpclassify(b) == FP_NAN)
{
mpfi_set_fr(this->data(), b.data());
}
else
{
if(a.compare(b) > 0)
{
BOOST_THROW_EXCEPTION(std::runtime_error("Attempt to create interval with invalid range (start is greater than end)."));
}
mpfi_interv_fr(m_data, a.data(), b.data());
}
}
else if(mpfi_set_str(m_data, s, 10) != 0)
{
Expand Down Expand Up @@ -745,7 +762,23 @@ inline void eval_convert_to(long double* result, const mpfi_float_backend<digits
template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
inline void assign_components(mpfi_float_backend<D1>& result, const mpfr_float_backend<D2, AllocationType>& a, const mpfr_float_backend<D2, AllocationType>& b)
{
mpfi_interv_fr(result.data(), a.data(), b.data());
using default_ops::eval_fpclassify;
if(eval_fpclassify(a) == FP_NAN)
{
mpfi_set_fr(result.data(), a.data());
}
else if(eval_fpclassify(b) == FP_NAN)
{
mpfi_set_fr(result.data(), b.data());
}
else
{
if(a.compare(b) > 0)
{
BOOST_THROW_EXCEPTION(std::runtime_error("Attempt to create interval with invalid range (start is greater than end)."));
}
mpfi_interv_fr(result.data(), a.data(), b.data());
}
}

template <unsigned Digits10, class V>
Expand Down

0 comments on commit 239fd62

Please sign in to comment.