Boost-Geometry-Utils

 view release on metacpan or  search on metacpan

src/boost/math/policies/error_handling.hpp  view on Meta::CPAN

T user_indeterminate_result_error(const char* function, const char* message, const T& val);

namespace detail
{
//
// Helper function to avoid binding rvalue to non-const-reference,
// in other words a warning suppression mechansim:
//
template <class Formatter, class Group>
inline std::string do_format(Formatter f, const Group& g)
{
   return (f % g).str();
}

template <class E, class T>
void raise_error(const char* function, const char* message)
{
  if(function == 0)
       function = "Unknown function operating on type %1%";
  if(message == 0)
       message = "Cause unknown";

  std::string msg("Error in function ");
  msg += (boost::format(function) % typeid(T).name()).str();
  msg += ": ";
  msg += message;

  E e(msg);
  boost::throw_exception(e);
}

template <class E, class T>
void raise_error(const char* function, const char* message, const T& val)
{
  if(function == 0)
     function = "Unknown function operating on type %1%";
  if(message == 0)
     message = "Cause unknown: error caused by bad argument with value %1%";

  std::string msg("Error in function ");
  msg += (boost::format(function) % typeid(T).name()).str();
  msg += ": ";
  msg += message;

  int prec = 2 + (boost::math::policies::digits<T, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
  msg = do_format(boost::format(msg), boost::io::group(std::setprecision(prec), val));

  E e(msg);
  boost::throw_exception(e);
}

template <class T>
inline T raise_domain_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>&)
{
   raise_error<std::domain_error, T>(function, message, val);
   // we never get here:
   return std::numeric_limits<T>::quiet_NaN();
}

template <class T>
inline T raise_domain_error(
           const char* , 
           const char* , 
           const T& , 
           const ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>&)
{
   // This may or may not do the right thing, but the user asked for the error
   // to be ignored so here we go anyway:
   return std::numeric_limits<T>::quiet_NaN();
}

template <class T>
inline T raise_domain_error(
           const char* , 
           const char* , 
           const T& , 
           const ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>&)
{
   errno = EDOM;
   // This may or may not do the right thing, but the user asked for the error
   // to be silent so here we go anyway:
   return std::numeric_limits<T>::quiet_NaN();
}

template <class T>
inline T raise_domain_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const  ::boost::math::policies::domain_error< ::boost::math::policies::user_error>&)
{
   return user_domain_error(function, message, val);
}

template <class T>
inline T raise_pole_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const  ::boost::math::policies::pole_error< ::boost::math::policies::throw_on_error>&)
{
   return boost::math::policies::detail::raise_domain_error(function, message, val,  ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>());
}

template <class T>
inline T raise_pole_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const  ::boost::math::policies::pole_error< ::boost::math::policies::ignore_error>&)
{
   return  ::boost::math::policies::detail::raise_domain_error(function, message, val,  ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>());
}

template <class T>
inline T raise_pole_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const  ::boost::math::policies::pole_error< ::boost::math::policies::errno_on_error>&)
{
   return  ::boost::math::policies::detail::raise_domain_error(function, message, val,  ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>());
}

template <class T>
inline T raise_pole_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const  ::boost::math::policies::pole_error< ::boost::math::policies::user_error>&)
{
   return user_pole_error(function, message, val);
}

template <class T>
inline T raise_overflow_error(
           const char* function, 
           const char* message, 
           const  ::boost::math::policies::overflow_error< ::boost::math::policies::throw_on_error>&)
{
   raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow");
   // we never get here:

src/boost/math/policies/error_handling.hpp  view on Meta::CPAN

inline T raise_rounding_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const TargetType&,
           const  ::boost::math::policies::rounding_error< ::boost::math::policies::throw_on_error>&)
{
   raise_error<boost::math::rounding_error, T>(function, message, val);
   // we never get here:
   return T(0);
}

template <class T, class TargetType>
inline T raise_rounding_error(
           const char* , 
           const char* , 
           const T& val, 
           const TargetType&,
           const  ::boost::math::policies::rounding_error< ::boost::math::policies::ignore_error>&)
{
   // This may or may not do the right thing, but the user asked for the error
   // to be ignored so here we go anyway:
   return std::numeric_limits<T>::is_specialized ? (val > 0 ? (std::numeric_limits<T>::max)() : -(std::numeric_limits<T>::max)()): val;
}

template <class T, class TargetType>
inline T raise_rounding_error(
           const char* , 
           const char* , 
           const T& val, 
           const TargetType&,
           const  ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>&)
{
   errno = ERANGE;
   // This may or may not do the right thing, but the user asked for the error
   // to be silent so here we go anyway:
   return std::numeric_limits<T>::is_specialized ? (val > 0 ? (std::numeric_limits<T>::max)() : -(std::numeric_limits<T>::max)()): val;
}

template <class T, class TargetType>
inline T raise_rounding_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const TargetType& t,
           const  ::boost::math::policies::rounding_error< ::boost::math::policies::user_error>&)
{
   return user_rounding_error(function, message, val, t);
}

template <class T, class R>
inline T raise_indeterminate_result_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const R& ,
           const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::throw_on_error>&)
{
   raise_error<std::domain_error, T>(function, message, val);
   // we never get here:
   return std::numeric_limits<T>::quiet_NaN();
}

template <class T, class R>
inline T raise_indeterminate_result_error(
           const char* , 
           const char* , 
           const T& , 
           const R& result, 
           const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::ignore_error>&)
{
   // This may or may not do the right thing, but the user asked for the error
   // to be ignored so here we go anyway:
   return result;
}

template <class T, class R>
inline T raise_indeterminate_result_error(
           const char* , 
           const char* , 
           const T& , 
           const R& result, 
           const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::errno_on_error>&)
{
   errno = EDOM;
   // This may or may not do the right thing, but the user asked for the error
   // to be silent so here we go anyway:
   return result;
}

template <class T, class R>
inline T raise_indeterminate_result_error(
           const char* function, 
           const char* message, 
           const T& val, 
           const R& , 
           const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::user_error>&)
{
   return user_indeterminate_result_error(function, message, val);
}

}  // namespace detail

template <class T, class Policy>
inline T raise_domain_error(const char* function, const char* message, const T& val, const Policy&)
{
   typedef typename Policy::domain_error_type policy_type;
   return detail::raise_domain_error(
      function, message ? message : "Domain Error evaluating function at %1%", 
      val, policy_type());
}

template <class T, class Policy>
inline T raise_pole_error(const char* function, const char* message, const T& val, const Policy&)
{
   typedef typename Policy::pole_error_type policy_type;
   return detail::raise_pole_error(
      function, message ? message : "Evaluation of function at pole %1%", 
      val, policy_type());
}



( run in 1.770 second using v1.01-cache-2.11-cpan-39bf76dae61 )