开发者

What is the use of feholdexcept etc.?

The documentation (in the standards) for all of fenv.h is rather confusing, but I'm especially confused about feholdexcept and the concept of "non-stop mode" for a floating point exception. As far as I can tell, on any IEEE floating point implementation, exceptions are non-signaling/"non-stop" by default, and the fenv.h interfaces seem to provide 开发者_开发百科no way to enable a signaling mode unless it was the default. Is the whole concept of feholdexcept useless except on non-IEEE systems or systems with nonstandard extensions for setting the signaling exception mask?


Suppose that you're implementing a library, and you don't know anything about what your callers might do the the floating-point environment before calling your code. They might unmask an exception, and install a custom trap handler that causes division-by-zero to produce the value 42. Suppose that your library depends on having default IEEE-754 behavior for division-by-zero. The feholdexcept function gives you a means to enforce this behavior. The caller's environment, complete with their unmasked exception, can then be restored using the fesetenv function.

This is admittedly a fairly obscure corner case of usage, but frankly everything in fenv.h is fairly obscure to most programmers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜