如何在C ++中跟踪NaN [英] How to trace a NaN in C++

查看:194
本文介绍了如何在C ++中跟踪NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用C ++做一些数学计算。输入浮点数是有效数字,但在计算后,结果值为NaN。我想跟踪NaN值出现的点(可能使用GDB),而不是在代码中插入大量的 isNan()。但是我发现,即使这样的代码,当NaN值出现时也不会触发异常。

  double dirty = 0.0; 
double nanvalue = 0.0 / dirty;

任何人都可以建议一种跟踪NaN或将NaN变成异常的方法?

在Visual Studio中,您可以使用_controlfp函数设置浮点计算的行为(参见 msdn.microsoft.com/en-us/library/e9b52ceh(VS.80).aspx\">http://msdn.microsoft.com/en-us/library/e9b52ceh(VS.80).aspx )。也许你的平台有一个类似的变体。


I am going to do some math calculations using C++ . The input floating point number is a valid number, but after the calculations, the resulting value is NaN. I would like to trace the point where NaN value appears (possibly using GDB), instead of inserting a lot of isNan() into the code. But I found that even code like this will not trigger an exception when a NaN value appears.

double dirty = 0.0;
double nanvalue = 0.0/dirty;

Could anyone suggest a method for tracing the NaN or turning a NaN into an exception?

解决方案

In Visual Studio you can use the _controlfp function to set the behavior of floating-point calculations (see http://msdn.microsoft.com/en-us/library/e9b52ceh(VS.80).aspx). Maybe there is a similar variant for your platform.

这篇关于如何在C ++中跟踪NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆