问题描述
我读C语言的书,它说%F,%E,%G,%A
是用于浮printf的字符
和双击
数据类型。目前,我能理解%F,%E,%G
完全
I am reading a C language book, it said %f, %e, %g, %a
were printf chars used for float
and double
data types. Currently I can understand %f, %e, %g
completely.
当我需要用%A
打印浮动
和双击
类型的数据?
When do I need use %a
to print float
and double
type data ?
能否请你告诉我一个例子。
Can you please show me an example.
推荐答案
的%A
格式化说明在C99是新的。它打印十六进制形式的浮点数。这是不是你会使用present号码的用户,但它是非常方便的在引擎罩/技术的使用案例。
The %a
formatting specifier is new in C99. It prints the floating-point number in hexadecimal form. This is not something you would use to present numbers to users, but it's very handy for under-the-hood/technical use cases.
作为一个例子,这个code:
As an example, this code:
printf("pi=%a\n", 3.14);
打印:
pi=0x1.91eb86p+1
在评论中链接的优秀的文章解释说,这应该读1.91EB86 * 2 (也就是 p
是幂的两个
浮点数字提高到的)。在这种情况下,1.91EB86 是1.5700000524520874 。乘以这个2 ,你会得到3.140000104904175
The excellent article linked in the comments explains that this should be read "1.91EB86 * 2" (that is, the p
is for power-of-two
the floating-point number is raised to). In this case, "1.91EB86" is "1.5700000524520874". Multiply this by the "2", and you get "3.140000104904175".
请注意,这也有preserving的有用的属性precision的所有位,和presenting他们在一个可靠的方法。
Note that this also has the useful property of preserving all bits of precision, and presenting them in a robust way.
这篇关于格式说明符%一个在C的printf()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!