2014-06-09 10:53 GMT+04:00 Olaf Peter <ope-devel@gmx.de>:

at this time I play with numeric_cast and struggle with this:

            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

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() * std::numeric_limits<double>::epsilon();

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

Best regards,
Antony Polukhin