什么float值使得sprintf_s()产生" 1#QO"? [英] What float value makes sprintf_s() produce "1.#QO"?
问题描述
我有一些(旧的嵌入式C)code这一些的sprintf
通话装置产生.csv文件。偶尔我看到 1#QO
的值。我已经试过这应该给负无穷,正无穷大和NaN,但他们都不似乎给我的神奇 1#QO
结果重现条件的值。那么,什么是它产生的价值呢?
I have some (legacy embedded c) code which produces a .csv file by means of some sprintf
calls. Occasionally I see values of 1.#QO
. I've tried reproducing those values with conditions which should give negative infinity, positive infinity and NaN but none of them appear to give me the magical 1.#QO
result. So what is it that produces that value?
...是的,我知道有一些很明显在其中产生价值数学会错,但了解这意味着什么将有助于调试工作。
...and yes, I know there's obviously something going wrong in the maths which produce that value, but understanding what it means would assist in the debugging effort.
由它来完成转换的实际行是:
The actual line which does the conversion is:
sprintf_s(txt, CSV_HEADER_SIZE, "%.3f", value);
其中:
#define CSV_HEADER_SIZE (100)
char txt[CSV_HEADER_SIZE];
我与微软的Visual Studio 2008的编译。
I'm compiling with MS Visual Studio 2008.
多一点挖节目 0xFFFFFFFF的
给 -1#QO
:
unsigned int i = 0xFFFFFFFF;
float* f = (float*)&i;
printf("%.3f", *f); // gives -1.#QO
..看着,在Visual Studio调试器它扩展为 -1#QNAN00
所以它看起来像这可能是微软特有的再$ P $的psentation NaN的
?
..and looking at that in the Visual Studio debugger expands it to -1.#QNAN00
so it looks like this is probably a Microsoft-specific representation of NaN
?
推荐答案
- 1#QO是-1#QNAN。四舍五入为小数点后3位之后。 N个回合到O为'A'> ='5'和'N'+ 1 =='O'。
"-1.#QO" is "-1.#QNAN" after "rounding" for 3 places after the decimal. The N rounds to an O as 'A' >= '5' and 'N' + 1 == 'O'.
这同样是为什么你的调试器显示-1。#QNAN00,它打印与7位和添加填充零到最后。
This is similarly why your debugger shows "-1.#QNAN00", as it prints with 7 places and adds padding zeros to the end.
QNAN是静态NaN 。
这篇关于什么float值使得sprintf_s()产生" 1#QO"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!