|
Boost Users : |
Subject: Re: [Boost-users] [numeric conversation] behavior on std::numeric_limits<double>::max() + eps with numeric_cast
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2014-06-09 14:33:59
Am 09.06.2014 14:33, schrieb Antony Polukhin:
>
>
> 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() *
> 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()
thanks for answer, but
eps = 2.22045e-16
max*eps = 3.99168e+292
on my machine, no_rel is a high value ... Is this right?, I thought eps
is the absolute error/uncertainly of representation in real values. But
probably I have to read about FP ...
Thanks,
Olaf
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net