Modify

Ticket #7905 (closed Bugs: fixed)

Opened 15 months ago

Last modified 14 months ago

boost::math::policies::raise_rounding_error returns the wrong min/max values for ignore_error and errno_on_error

Reported by: benkerby@… Owned by: johnmaddock
Milestone: To Be Determined Component: math
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description

In the documentation for the rounding functions, in "Table 6. Possible Actions for Rounding Errors", it says that the round function will return "the largest representable value of the target integer type (or the most negative value if the argument to the function was less than zero).

However, the specializations of the raise_rounding_error function for ignore_error and errno_on_error call std::numeric_limits min() and max() with the source type rather than the result type.

For example, calling

iround(INT_MAX + 1.0)

will return

static_cast<int>(std::numeric_limits<double>::max())

rather than

static_cast<int>(std::numeric_limits<int>::max())

as was specified.

Attachments

Change History

comment:1 Changed 15 months ago by benkerby@…

Note that the function reads:

   // 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;

but it should read

   // 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<TargetType>::is_specialized ? (val > 0 ? (std::numeric_limits<TargetType>::max)() : (std::numeric_limits<TargetType>::min)()): val;

Two changes:

  • template specialized on the TargetType?
  • return the minimum value rather than the negative version of the max value (important for unsigned types)

comment:2 Changed 15 months ago by benkerby@…

  • Owner set to johnmaddock
  • Component changed from None to math

comment:3 Changed 14 months ago by johnmaddock

  • Status changed from new to assigned

Confirmed, testing fix.

comment:4 Changed 14 months ago by johnmaddock

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [82885]) Fix raise_rounding_error to return the correct result (and type) when an error occurs. Fixes #7905.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.