十六进制用C浮点常量 [英] hexadecimal floating constant in C

查看:707
本文介绍了十六进制用C浮点常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0x0.3p10 重新presents什么样的价值?

0x0.3p10 represents what value?

和什么的 P 在上面的语句中的含义是什么?

And what's the meaning of the p in the statement above?

推荐答案

0x0.3p10 是一个十六进制浮点文字,在C99推出的一个例子。在 P 从指数分隔基数。

0x0.3p10 is an example of a hexadecimal floating point literal, introduced in C99. The p separates the base number from the exponent.

0x0.3 位被称为尾数部分(全部具有可选的分数),指数是由其所缩放2的幂。

The 0x0.3 bit is called the significand part (whole with optional fraction) and the exponent is the power of two by which it is scaled.

这特别的值作为 0.3十六进制 3 * 16 1 3/16 )乘以 2 10 1024 ),这给 3 * 1024年至1016年 192

That particular value is calculated as 0.3 in hex, or 3 * 16-1 (3/16) multiplied by 210 (1024), which gives 3 * 1024 / 16 or 192.

以下程序证实了这一点:

The following program confirms this:

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

6.4.4.2 C99有所有的细节:

Section 6.4.4.2 of C99 has all the details:

一个浮点常量有一个尾数部分,可能跟有一个指数部分,并指定其类型的后缀。尾数部的部件可以包括一个数字序列重新presenting的整数部分,后跟一个句点(。),接着是
  数字序列重新presenting小数部分。

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 a digit sequence representing the fraction part.

指数部分的组成部分是一个电子,E,P,或随后通过由任选签署数字序列的指数P上。无论是整数部分或小数部分必须是present;十进制浮点常量,无论是期或指数部分必须是present。

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.

的尾数部分是PTED为(十进制或十六进制)有理数间$ P $;在指数部分数字序列PTED为十进制整数间$ P $。为十进制浮点常量,指数表示10的幂通过该尾数部分进行缩放。十六进制浮点常量,指数表示2的幂通过该尾数部分将被缩放。

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.

有关十进制浮点常量,也为十六进制浮点常量时FLT_RADIX不是2的幂,其结果是要么最近重新presentable值,或更大或更小重presentable紧邻值最近重新presentable价值,在实现定义的方式选择。对于十六进制浮点常量时,FLT_RADIX是2的幂,其结果是正确的舍入。

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.

这篇关于十六进制用C浮点常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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