|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r86779 - trunk/boost/multiprecision
From: john_at_[hidden]
Date: 2013-11-21 08:04:20
Author: johnmaddock
Date: 2013-11-21 08:04:20 EST (Thu, 21 Nov 2013)
New Revision: 86779
URL: http://svn.boost.org/trac/boost/changeset/86779
Log:
Add some better error checks to interval construction.
Text files modified:
trunk/boost/multiprecision/mpfi.hpp | 37 +++++++++++++++++++++++++++++++++++--
1 files changed, 35 insertions(+), 2 deletions(-)
Modified: trunk/boost/multiprecision/mpfi.hpp
==============================================================================
--- trunk/boost/multiprecision/mpfi.hpp Thu Nov 21 05:31:03 2013 (r86778)
+++ trunk/boost/multiprecision/mpfi.hpp 2013-11-21 08:04:20 EST (Thu, 21 Nov 2013) (r86779)
@@ -179,6 +179,8 @@
}
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()));
@@ -203,7 +205,22 @@
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)
{
@@ -745,7 +762,23 @@
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>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk