Boost logo

Boost Users :

Subject: Re: [Boost-users] [numeric conversation] behavior on std::numeric_limits<double>::max() + eps with numeric_cast
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-06-09 08:33:00

2014-06-09 10:53 GMT+04:00 Olaf Peter <ope-devel_at_[hidden]>:

> Hello,
> at this time I play with numeric_cast and struggle with this:
> first:
> double z = std::numeric_limits<double>::max();
> z += 2*std::numeric_limits<double>::epsilon(); // doesn't
> matter if 1*eps
> std::cout << z << std::endl;
> std::cout << boost::numeric_cast<double>(z) << '\n';
> I would expect that an exception is thrown which isn't, the output is
> 1.79769e+308
> 1.79769e+308

Machine epsilon gives an upper bound on the relative error due to rounding
in floating point arithmetic.
In other words absolute error for max value would be:

double non_rel = std::numeric_limits<double>::max() *

2*std::numeric_limits<double>::epsilon() is much less than non_rel and
adding it won't cause overflow: number will be rounded to

Best regards,
Antony Polukhin

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at