更新时间:2023-11-08 17:23:22
如果您的C ++标准库实现支持TR1函数 fetestexcept
, feraiseexcept
和 feclearexcept
我还没有这样我无法测试这个),你可以检测到五种浮点错误,然后你可以抛出任何你想要的异常。
If your C++ standard library implementation supports the TR1 functions
fetestexcept
, feraiseexcept
and feclearexcept
(mine doesn't yet so I can't test this) you can detect five kinds of floating point errors and then you can throw whatever exceptions you want.
请参阅这里,以了解这些功能的描述。
See here for a description of these functions.
我还推荐Pete Becker(ISBN-13:9780321412997)的书籍C ++标准库扩展:教程和参考一书的第12.3节管理浮点环境一个exc使用示例代码对这些功能的描述。
I also recommend section 12.3, "Managing the Floating Point Environment," of the book The C++ Standard Library Extensions: A Tutorial and Reference by Pete Becker, ISBN-13: 9780321412997, for an excellent description of these functions with sample code.
alt text http://ak.buy.com/db_assets/prod_images/225/202452225.jpg