error_handling.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 645 行 · 第 1/2 页
HPP
645 行
return val;}template <class T>inline T raise_denorm_error( const char* function, const char* message, const T& val, const ::boost::math::policies::denorm_error< ::boost::math::policies::user_error>&){ return user_denorm_error(function, message, val);}template <class T>inline T raise_evaluation_error( const char* function, const char* message, const T& val, const ::boost::math::policies::evaluation_error< ::boost::math::policies::throw_on_error>&){ raise_error<boost::math::evaluation_error, T>(function, message, val); // we never get here: return T(0);}template <class T>inline T raise_evaluation_error( const char* , const char* , const T& val, const ::boost::math::policies::evaluation_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 val;}template <class T>inline T raise_evaluation_error( const char* , const char* , const T& val, const ::boost::math::policies::evaluation_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 val;}template <class T>inline T raise_evaluation_error( const char* function, const char* message, const T& val, const ::boost::math::policies::evaluation_error< ::boost::math::policies::user_error>&){ return user_evaluation_error(function, message, val);}template <class T>inline T raise_rounding_error( const char* function, const char* message, const T& val, 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>inline T raise_rounding_error( const char* , const char* , const T& val, 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 val;}template <class T>inline T raise_rounding_error( const char* , const char* , const T& val, 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 val;}template <class T>inline T raise_rounding_error( const char* function, const char* message, const T& val, const ::boost::math::policies::rounding_error< ::boost::math::policies::user_error>&){ return user_rounding_error(function, message, val);}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 detailtemplate <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());}template <class T, class Policy>inline T raise_overflow_error(const char* function, const char* message, const Policy&){ typedef typename Policy::overflow_error_type policy_type; return detail::raise_overflow_error<T>( function, message ? message : "Overflow Error", policy_type());}template <class T, class Policy>inline T raise_underflow_error(const char* function, const char* message, const Policy&){ typedef typename Policy::underflow_error_type policy_type; return detail::raise_underflow_error<T>( function, message ? message : "Underflow Error", policy_type());}template <class T, class Policy>inline T raise_denorm_error(const char* function, const char* message, const T& val, const Policy&){ typedef typename Policy::denorm_error_type policy_type; return detail::raise_denorm_error<T>( function, message ? message : "Denorm Error", val, policy_type());}template <class T, class Policy>inline T raise_evaluation_error(const char* function, const char* message, const T& val, const Policy&){ typedef typename Policy::evaluation_error_type policy_type; return detail::raise_evaluation_error( function, message ? message : "Internal Evaluation Error, best value so far was %1%", val, policy_type());}template <class T, class Policy>inline T raise_rounding_error(const char* function, const char* message, const T& val, const Policy&){ typedef typename Policy::rounding_error_type policy_type; return detail::raise_rounding_error( function, message ? message : "Value %1% can not be represented in the target integer type.", val, policy_type());}template <class T, class R, class Policy>inline T raise_indeterminate_result_error(const char* function, const char* message, const T& val, const R& result, const Policy&){ typedef typename Policy::indeterminate_result_error_type policy_type; return detail::raise_indeterminate_result_error( function, message ? message : "Indeterminate result with value %1%", val, result, policy_type());}//// checked_narrowing_cast://namespace detail{template <class R, class T, class Policy>inline bool check_overflow(T val, R* result, const char* function, const Policy& pol){ BOOST_MATH_STD_USING if(fabs(val) > tools::max_value<R>()) { *result = static_cast<R>(boost::math::policies::detail::raise_overflow_error<R>(function, 0, pol)); return true; } return false;}template <class R, class T, class Policy>inline bool check_underflow(T val, R* result, const char* function, const Policy& pol){ if((val != 0) && (static_cast<R>(val) == 0)) { *result = static_cast<R>(boost::math::policies::detail::raise_underflow_error<R>(function, 0, pol)); return true; } return false;}template <class R, class T, class Policy>inline bool check_denorm(T val, R* result, const char* function, const Policy& pol){ BOOST_MATH_STD_USING if((fabs(val) < static_cast<T>(tools::min_value<R>())) && (static_cast<R>(val) != 0)) { *result = static_cast<R>(boost::math::policies::detail::raise_denorm_error<R>(function, 0, static_cast<R>(val), pol)); return true; } return false;}// Default instantiations with ignore_error policy.template <class R, class T>inline bool check_overflow(T /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&){ return false; }template <class R, class T>inline bool check_underflow(T /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&){ return false; }template <class R, class T>inline bool check_denorm(T /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&){ return false; }} // namespace detailtemplate <class R, class Policy, class T>inline R checked_narrowing_cast(T val, const char* function){ typedef typename Policy::overflow_error_type overflow_type; typedef typename Policy::underflow_error_type underflow_type; typedef typename Policy::denorm_error_type denorm_type; // // Most of what follows will evaluate to a no-op: // R result; if(detail::check_overflow<R>(val, &result, function, overflow_type())) return result; if(detail::check_underflow<R>(val, &result, function, underflow_type())) return result; if(detail::check_denorm<R>(val, &result, function, denorm_type())) return result; return static_cast<R>(val);}template <class Policy>inline void check_series_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol){ if(max_iter >= policies::get_max_series_iterations<Policy>()) raise_evaluation_error<boost::uintmax_t>( function, "Series evaluation exceeded %1% iterations, giving up now.", max_iter, pol);}} //namespace policies#ifdef BOOST_MSVC# pragma warning(pop)#endif}} // namespaces boost/math#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?