Is it guaranteed by the C++ standard that angle == std::acos(std::cos(angle))
if angle
is in the range [0, Pi], or in other words is it possible to restore the exact original value of angle
from the result of std::cos
using std::acos
given the mentioned range limit?
The marginal cases when angle
is infinity
or NaN
are omitted.
Answer by StoryTeller:
The standard cannot make that guarantee, simply because the result of
std::cos
may not be representable exactly by adouble
, so you get a truncation error, which will affect the result ofstd::acos
.