gpt4 book ai didi

c - C中的十六进制 float 常量

转载 作者:太空狗 更新时间:2023-10-29 16:20:28 26 4
gpt4 key购买 nike

0x0.3p10代表什么值?

上面语句中的p是什么意思?

最佳答案

0x0.3p10是在 C99(1) 中引入的十六进制浮点文字的示例。 p将底数与指数分开。

0x0.3位被称为有效数字部分(整体带有可选小数部分),指数是它缩放的 2 的幂。

该特定值计算为 0.3十六进制,或 3 * 16<sup>-1</sup> ( 3/16 ) 乘以 2<sup>10</sup> ( 1024 ),它给出 3 * 1024 / 16192 .以下程序证实了这一点:

#include <stdio.h>
int main (void) {
double d = 0x0.3p10;
printf ("%.f\n", d); // Outputs 192
return 0;
}

6.4.4.2 Floating constants C99 的所有详细信息:

A floating constant has a significand part that may be followed by an exponent part and a suffix that specifies its type. The components of the significand part may include a digit sequence representing the whole-number part, followed by a period ., followed by adigit sequence representing the fraction part.

The components of the exponent part are an e, E, p, or P followed by an exponent consisting of an optionally signed digit sequence. Either the whole-number part or the fraction part has to be present; for decimal floating constants, either the period or the exponent part has to be present.

The significand part is interpreted as a (decimal or hexadecimal) rational number; the digit sequence in the exponent part is interpreted as a decimal integer. For decimal floating constants, the exponent indicates the power of 10 by which the significand part is to be scaled. For hexadecimal floating constants, the exponent indicates the power of 2 by which the significand part is to be scaled.

For decimal floating constants, and also for hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either the nearest representable value, or the larger or smaller representable value immediately adjacent to the nearest representable value, chosen in an implementation-defined manner. For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is correctly rounded.


(1) 这些文字也在标准的 C++17 迭代中添加到 C++,尽管格式化和解析它们的能力是 C++11 的一部分。

关于c - C中的十六进制 float 常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4825824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com