⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error_handling.qbk

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 QBK
📖 第 1 页 / 共 2 页
字号:
['"the corresponding mathematical function is not mathematically defined.]][:['"Note 2: A mathematical function is mathematically definedfor a given set of argument values if it is explicitly definedfor that set of argument values orif its limiting value exists and does not depend on the direction of approach."]]Note that in order to support information-rich error messages when throwingexceptions, `Message` must containa __format recognised format specifier: the argument `Val` is inserted intothe error message according to the specifier used.For example if `Message` contains a "%1%" then it is replaced by the value of`Val` to the full precision of T, where as "%.3g" would contain the value of`Val` to 3 digits.  See the __format documentation for more details.[heading [#pole_error]Evaluation at a pole]When a special function is passed an argument that is at a polewithout a well defined residual value, then the function returnsthe result of:   boost::math::policies::raise_pole_error<T>(FunctionName, Message, Val, __Policy);   Where`T` is the floating point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem, `Val` is the value of the argument that is at a pole, and __Policy is the current policy in use for the function that was called.The default behaviour of this function is to throw a std::domain_error exception.But __error_policy can be used to change this, for example to `ignore_error`and return NaN.Note that in order to support information-rich error messages when throwingexceptions, `Message` must containa __format recognised format specifier: the argument `val` is inserted intothe error message according to the specifier used.For example if `Message` contains a "%1%" then it is replaced by the value of`val` to the full precision of T, where as "%.3g" would contain the value of`val` to 3 digits.  See the __format documentation for more details.[heading [#overflow_error]Numeric Overflow]When the result of a special function is too large to fit in the argumentfloating-point type, then the function returns the result of:   boost::math::policies::raise_overflow_error<T>(FunctionName, Message, __Policy);   Where`T` is the floating-point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,and __Policy is the current policyin use for the function that was called.The default policy for this function is that `std::overflow_error` C++ exception is thrown. But if, for example, an `ignore_error` policy is used, then returns `std::numeric_limits<T>::infinity()`.In this situation if the type `T` doesn't support infinities,the maximum value for the type is returned.[heading [#underflow_error]Numeric Underflow]If the result of a special function is known to be non-zero, but thecalculated result underflows to zero, then the function returns the result of:   boost::math::policies::raise_underflow_error<T>(FunctionName, Message, __Policy);   Where`T` is the floating point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,and __Policy is the current policyin use for the called function.The default version of this function returns zero.But with another policy, like `throw_on_error`, throws an `std::underflow_error` C++ exception.  [heading [#denorm_error]Denormalisation Errors]If the result of a special function is a denormalised value /z/ then the functionreturns the result of:   boost::math::policies::raise_denorm_error<T>(z, FunctionName, Message, __Policy);   Where`T` is the floating point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,and __Policy is the current policyin use for the called function.The default version of this function returns /z/.But with another policy, like `throw_on_error` throws an `std::underflow_error` C++ exception.[heading [#evaluation_error]Evaluation Errors]When a special function calculates a result that is known to be erroneous,or where the result is incalculable then it calls:   boost::math::policies::raise_evaluation_error<T>(FunctionName, Message, Val, __Policy);   Where`T` is the floating point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,`Val` is the erroneous value,and __Policy is the current policyin use for the called function.The default behaviour of this function is to throw a `boost::math::evaluation_error`.Note that in order to support information rich error messages when throwingexceptions, `Message` must containa __format recognised format specifier: the argument `val` is inserted intothe error message according to the specifier used.For example if `Message` contains a "%1%" then it is replaced by the value of`val` to the full precision of T, where as "%.3g" would contain the value of`val` to 3 digits.  See the __format documentation for more details.[heading [#indeterminate_result_error]Indeterminate Result Errors]When the result of a special function is indeterminate for the value that waspassed to it, then the function returns the result of:   boost::math::policies::raise_overflow_error<T>(FunctionName, Message, Val, Default, __Policy);   Where`T` is the floating-point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,Val is the value for which the result is indeterminate, Default is analternative default result that must be returned for ignore_error anderrno_on_error policies, and __Policy is the current policy in use for thefunction that was called.The default policy for this function is `ignore_error`: note that this errortype is reserved for situations where the result is mathematicallyundefined or indeterminate, but there is none the less a convention for whatthe result should be: for example the C99 standard specifies that the resultof 0[super 0] is 1, even though the result is actually mathematically indeterminate.[heading [#rounding_error]Rounding Errors]When one of the rounding functions __round, __trunc or __modf iscalled with an argument that has no integer representation, oris too large to be represented in the result type then the value returned is the result of a call to:   boost::math::policies::raise_rounding_error<T>(FunctionName, Message, Val, __Policy);   Where`T` is the floating point type passed to the function, `FunctionName` is the name of the function, `Message` is an error message describing the problem,`Val` is the erroneous argument,and __Policy is the current policyin use for the called function.The default behaviour of this function is to throw a `boost::math::rounding_error`.Note that in order to support information rich error messages when throwingexceptions, `Message` must containa __format recognised format specifier: the argument `val` is inserted intothe error message according to the specifier used.For example if `Message` contains a "%1%" then it is replaced by the value of`val` to the full precision of T, where as "%.3g" would contain the value of`val` to 3 digits.  See the __format documentation for more details.[heading [#checked_narrowing_cast]Errors from typecasts]Many special functions evaluate their results at a higher precisionthan their arguments in order to ensure full machine precision in the result: for example, a function passed a float argument may evaluateits result using double precision internally.  Many of the errors listedabove may therefore occur not during evaluation, but when converting the result to the narrower result type.  The function:   template <class T, class __Policy, class U>   T checked_narrowing_cast(U const& val, const char* function);   Is used to perform these conversions, and will call the error handlerslisted above on [link overflow_error overflow], [link underflow_error underflow] or [link denorm_error denormalisation].[endsect][/section:error_handling Error Handling][/   Copyright 2006 John Maddock and Paul A. Bristow.  Distributed under the Boost Software License, Version 1.0.  (See accompanying file LICENSE_1_0.txt or copy at  http://www.boost.org/LICENSE_1_0.txt).]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -