简体   繁体   English

gcc的__float128浮点数是否考虑了当前的舍入模式?

[英]Do gcc's __float128 floating point numbers take the current rounding mode into account?

Do the arithmetic operations on gcc's __float128 floating point numbers take the current rounding mode into account? 对gcc的__float128浮点数的算术运算是否考虑了当前的舍入模式?

For instance, if using the C++11 function std::fesetenv , I change the rounding mode to FE_DOWNWARD , will results of arithmetic operations on __float128 be rounded down? 例如,如果使用C ++ 11功能std::fesetenv ,我改入模式FE_DOWNWARD ,将在算术运算的结果__float128四舍五入?

Is this guaranteed by the __float128 specification? 这是否由__float128规范保证?

I believe that it is guaranteed that operations on __float128 take the rounding mode into account. 我相信, 保证 __float128上的操作考虑了舍入模式。

According to the GNU C Library documentation floating-point calculations respect the rounding mode. 根据GNU C Library文档,浮点计算遵循舍入模式。

According to the GCC manual __float128 is a floating type which supports arithmetic operations as division etc. 根据GCC手册__float128是一种浮动类型,它支持算术运算如分区等。

From that I deduce, that for operations on __float128 , the rounding mode has to be taken into account. 从中我推断,对于__float128上的__float128必须考虑舍入模式。

The GNU C Library documentation states: GNU C Library文档说明:

20.6 Rounding Modes 20.6舍入模式

Floating-point calculations are carried out internally with extra precision, and then rounded to fit into the destination type. 浮点计算在内部以额外的精度执行,然后舍入以适合目标类型。 This ensures that results are as precise as the input data. 这可确保结果与输入数据一样精确。 IEEE 754 defines four possible rounding modes: [...] IEEE 754定义了四种可能的舍入模式:[...]

Reference: http://www.gnu.org/software/libc/manual/html_node/Rounding.html 参考: http //www.gnu.org/software/libc/manual/html_node/Rounding.html

The GCC manual states: GCC手册指出:

6.11 Additional Floating Types 6.11附加浮动类型

As an extension, GNU C supports additional floating types, __float80 and __float128 to support 80-bit (XFmode) and 128-bit (TFmode) floating types. 作为扩展,GNU C支持其他浮动类型__float80和__float128,以支持80位(XFmode)和128位(TFmode)浮点类型。 Support for additional types includes the arithmetic operators: add, subtract, multiply, divide; 支持其他类型包括算术运算符:加,减,乘,除; unary arithmetic operators; 一元算术运算符; relational operators; 关系运算符; equality operators; 平等操作者; [...] [...]

Reference: https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html 参考: https //gcc.gnu.org/onlinedocs/gcc/Floating-Types.html

Working Example 工作实例

Example code and output 示例代码和输出

__float128 f1=1.0;
__float128 f2=3.0;

char buf[256];

fesetround(FE_DOWNWARD);

quadmath_snprintf (buf, sizeof buf, "%*.34Qf",10, (f1/f2));
printf ("%s\n", buf);

fesetround(FE_UPWARD);

quadmath_snprintf (buf, sizeof buf, "%*.34Qf",10, (f1/f2));
printf ("%s\n", buf);

outputs: 输出:

0.3333333333333333333333333333333333
0.3333333333333333333333333333333334

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM