Boost logo

Boost :

Subject: Re: [boost] [safe_numerics] Review Part 2 (Implementation)
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-03-07 19:33:03

2017-03-07 18:32 GMT+01:00 Robert Ramey via Boost <boost_at_[hidden]>:

>> using result_base_type = typename boost::mpl::if_c<
>> std::numeric_limits<t_base_type>::is_signed
>> || std::numeric_limits<u_base_type>::is_signed,
>> std::intmax_t,
>> std::uintmax_t
>> >::type;
>> Why division doesn't use calculate_max_t like multiplication
>> deserves some explanation. Division can overflow
>> too (numeric_limits<uintmax_t>::max() / 1).
> Hmmm - I'm sure it's because I've presumed that the result
> can aways be contained in the same size type as the number
> being divide. That t / x <= t - and divide by zero is
> checked separately. Am I wrong about this?

I am not sure if this is what Steve meant, but:

  int x = INT_MIN;
  int y = -1;
  int a = x / y; // overflows!

safe<int> does a check for this condition, but I find it quite surprising
that it throws a domain_error rather than overflow_error. How do you make a
call whether it is an overflow or a domain error? For mathematical ints
dividing -2147483648 by -1 is well defined.


Boost list run by bdawes at, gregod at, cpdaniel at, john at