I'm trying to find a good use for changing rounding mode in IEEE-754 floating-point environment.
I'm looking mostly from perspective of C and C++ code. There, it can be done using
int fesetround(int round)
function from "fenv.x"
(or <cfenv>
in C++).
The best use I could find is setting the environment to FE_TONEAREST
, if for any godforsaken reason it wasn't the default.
In this question someone suggested using it to get some implementation-dependent behavior of string formatting. I personally find this answer completely wrong, and I believe changing rounding modes around formatting functions can only result in unexpected, or simply wrong behavior.
Another thing that is changed by rounding mode, are the functions: nearbyint
and rint
. But why would you ever want to use them, instead of dispatching to floor
, ceil
and trunc
functions?
That leaves us with the only useful part being local difference in floating point arithmetic. Where could that be useful? I was trying to find some niche use for that, but so far I couldn't find any.