简体   繁体   中英

What is the practical use of changing the rounding mode in floating point evnironment?

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.

The rouding modes have little to do with the floor and ceiling (the latter round to integers ). I don't know about a trunk function.

Changing the rounding rule might be useful in some sophisticated cases where theoretical study shows that a particular rule has advantages over other or gives some desirable guarantee.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM