问题描述
我有一个C ++程序。在程序中的某处(难以再现,但可再现),一个caclculation导致浮点beeing设置为NaN。因为涉及NaN的浮点运算产生一个NaN,所以它的传播速度很快。
I have an C++ program. Somewhere in the program (hard to reproduce, but reproduceable) a caclculation results in a float beeing set to a NaN. Since a floating point operation involving a NaN results in a NaN, this spreads fast.
有任何方法可以设置编译器(gcc 4.4)或调试器)在浮点运算导致NaN时停止?这将是非常有用的。
Is there any way I can setup the compiler (gcc 4.4) or the debuger (gdb) to stop when a floating point operation results in a NaN? That would be extremely useful.
谢谢!
Nathan
Thanks!Nathan
PS:可能有问题:我在ubuntu linux 10.10下工作。
PS: It might matter: I am working under ubuntu linux 10.10.
推荐答案
您可以启用浮点异常 - 请参阅 - 那么当您的 NaN
价值产生时,您会得到 SIGFPE
You could enable floating point exceptions - see glibc Control Functions - then you'll get a SIGFPE
when your NaN
value is produced
这篇关于在产生NaN浮点数时停止调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!