Skip to content

Commit

Permalink
BREAKING CHANGE: Correct definition of user_rounding_error, (#836)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: Correct definition of user_rounding_error,
To return correct type.
Likewise fix up a few other rounding error inconsistencies.
Fixes #834.

* Remove redundant error handler.
  • Loading branch information
jzmaddock authored Oct 9, 2022
1 parent ea9c3a2 commit ddf0143
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
4 changes: 2 additions & 2 deletions doc/policies/policy.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ must be provided by the user:
template <class T>
T user_rounding_error(const char* function, const char* message, const T& val);

template <class T>
T user_evaluation_error(const char* function, const char* message, const T& val);
template <class T, class TargetType>
TargetType user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t);

template <class T>
T user_indeterminate_result_error(const char* function, const char* message, const T& val);
Expand Down
2 changes: 1 addition & 1 deletion example/policy_eg_8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ boost/math/policies/error_handling.hpp like this:
template <class T>
T user_evaluation_error(const char* function, const char* message, const T& val);
template <class T, class TargetType>
T user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t);
TargetType user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t);
template <class T>
T user_indeterminate_result_error(const char* function, const char* message, const T& val);
Expand Down
21 changes: 3 additions & 18 deletions include/boost/math/policies/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ T user_denorm_error(const char* function, const char* message, const T& val);
template <class T>
T user_evaluation_error(const char* function, const char* message, const T& val);
template <class T, class TargetType>
T user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t);
TargetType user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t);
template <class T>
T user_indeterminate_result_error(const char* function, const char* message, const T& val);

Expand Down Expand Up @@ -561,7 +561,7 @@ inline constexpr TargetType raise_rounding_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:
static_assert(std::numeric_limits<TargetType>::is_specialized, "The target type must be specialized.");
static_assert(std::numeric_limits<TargetType>::is_specialized, "The target type must have std::numeric_limits specialized.");
return val > 0 ? (std::numeric_limits<TargetType>::max)() : (std::numeric_limits<TargetType>::is_integer ? (std::numeric_limits<TargetType>::min)() : -(std::numeric_limits<TargetType>::max)());
}

Expand All @@ -576,24 +576,9 @@ inline TargetType raise_rounding_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:
static_assert(std::numeric_limits<TargetType>::is_specialized, "The target type must be specialized.");
static_assert(std::numeric_limits<TargetType>::is_specialized, "The target type must have std::numeric_limits specialized.");
return val > 0 ? (std::numeric_limits<TargetType>::max)() : (std::numeric_limits<TargetType>::is_integer ? (std::numeric_limits<TargetType>::min)() : -(std::numeric_limits<TargetType>::max)());
}

template <class T>
inline T raise_rounding_error(
const char* ,
const char* ,
const T& val,
const T&,
const ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T)
{
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 > 0 ? boost::math::tools::max_value<T>() : -boost::math::tools::max_value<T>();
}

template <class T, class TargetType>
inline TargetType raise_rounding_error(
const char* function,
Expand Down

0 comments on commit ddf0143

Please sign in to comment.