强制所有 QNaN 变为正常 NaN (SNaN),因此会引发异常
我已将 Visual Studio 配置为通过 _controlfp 函数引发浮点异常。这适用于 NAN 和 INF,但不适用于 QNAN。即安静的 NaN 不会导致引发异常。 Visual Studio 2008/2010 是否有任何函数或配置选项会强制 QNAN 变为 NAN,以便它们抛出异常?
I've configured Visual Studio to throw floating point exceptions via the _controlfp function. This works for NAN and INF, but not QNAN. I.e. Quiet NaNs don't cause an exception to be raised. Is there any function, or config option for Visual Studio 2008/2010, that will force QNANs to instead be NANs, so that they throw exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些有用的提示,尽管我从来没有远程做过这样的事情:
阅读:http://www.cisl.ucar.edu/docs/trap.error/errortypes.html
在互联网上进行的搜索(我实际上只花了大约 30 秒),导致我相信这通常是通过编译器选项启用的。
然而,我似乎还记得这种陷阱的启用/禁用可以通过编程方式指定,特别是在Windows中,这可以通过几乎任何程序来完成,例如当使用打印机进行打印时。此外,如果您以编程方式更改此选项,请尽快将其设置回以前的值,否则如果来自 .NET 的人员尝试使用您的代码,他们可能会遇到问题。
(换句话说,您对 _controlfp 的使用可能会被其他例程覆盖,假设这确实是正确的使用方法)
另请参阅 Visual Studio C++ 2008 / 2010 - 浮点数 NaN 时中断
Some helpful tips, although I've never even remotely done something like this:
Read: http://www.cisl.ucar.edu/docs/trap.error/errortypes.html
The resulting search on the internet (which I've really only spent about 30 seconds on), leads me to believe that this is normally enabled with a compiler option.
However, I also seem to recall that such enabling/disabling of traps can be specified programmatically, and especially in windows, this can be done by pretty much any program, such as when a printer is used for printing. Additionally, if you change this option programmatically, please set it back to the previous value as soon as you can, otherwise if people from .NET try to use your code, they might have issues.
(In other words, your use of _controlfp could be overriden by some other routine, assuming that is indeed the correct approach to use)
Also see Visual Studio C++ 2008 / 2010 - break on float NaN