什么是浮点错误-1#Ĵ是什么意思? [英] What does floating point error -1.#J mean?
问题描述
近日,有时(很少),当我们从我们的应用程序中导出数据,导出日志包含看起来像浮点值-1。#J。我一直无法重现它,所以我不知道浮动样子二进制,或者如何Visual Studio中显示出来。
Recently, sometimes (rarely) when we export data from our application, the export log contains float values that look like "-1.#J". I haven't been able to reproduce it so I don't know what the float looks like in binary, or how Visual Studio displays it.
我试图查看源$ C $ c代表的printf,但没有发现任何东西(不是100%肯定我看着正确的版本,虽然...)。
I tried looking at the source code for printf, but didn't find anything (not 100% sure I looked at the right version though...).
我试过,但谷歌搜索谷歌丢弃任何#,它似乎。而且我找不到浮动错误的任何名单。
I've tried googling but google throws away any #, it seems. And I can't find any lists of float errors.
推荐答案
它可以是负无穷大或NaN(非数字)。由于在球场上的printf的格式不区分它们。
It can be either negative infinity or NaN (not a number). Due to the formatting on the field printf does not differentiate between them.
我尝试以下code在Visual Studio 2008:
I tried the following code in Visual Studio 2008:
double a = 0.0;
printf("%.3g\n", 1.0 / a); // +inf
printf("%.3g\n", -1.0 / a); // -inf
printf("%.3g\n", a / a); // NaN
这会导致下面的输出:
which results in the following output:
1.#J
-1.#J
-1.#J
删除.3格式说明符给出了:
removing the .3 formatting specifier gives:
1.#INF
-1.#INF
-1.#IND
所以很清楚0/0给人楠-1/0给出了负无穷大(南安,-INF和+ INF是唯一的错误浮点数,如果我没有记错)
so it's clear 0/0 gives NaN and -1/0 gives negative infinity (NaN, -inf and +inf are the only "erroneous" floating point numbers, if I recall correctly)
这篇关于什么是浮点错误-1#Ĵ是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!