浮点数与整数的结合加法相加会出现舍入误差吗?

Could rounding error occurs in the addition between float and an associative addition of integer?

(1) 我知道整数加法是关联的,例如(res1 & res 总是产生相同的结果)

int i1, i2, i3;
int res1 = i1 + i2 + i3;
int res2 = i1 + (i2 + i3);

(2) 我也了解到以下情况可能会出现舍入误差

float f = ...;
int   i1, i2, i3;
float res = f + i1 + i2 + i3 ; // rounding error may occur in `float + int`

(问题) 我想知道的是,在下面的代码中,res1 & res2 是否总是产生相同的结果(没有舍入误差)?

float f = ...;
int   i1, i2, i3;
float res1 = f + i1 + i2 + i3;
float res2 = f + (i1 + i2 + i3); // use associativity of integer addition

此代码:

#include <stdio.h>


int main(void)
{
    float f = 0x1p25f;
    int i1 = 1, i2 = 1, i3 = 1;
    printf("%.99g\n", f + i1 + i2 + i3);
    printf("%.99g\n", f + (i1 + i2 + i3));
}

打印:

33554432
33554436

float 是 IEEE-754 binary32 并且使用最近舍入法时。

在另一端,这段代码:

#include <stdio.h>


int main(void)
{
    float f = 0x1p-24f;
    int i1 = 1, i2 = -1, i3 = 0;
    printf("%.99g\n", f + i1 + i2 + i3);
    printf("%.99g\n", f + (i1 + i2 + i3));
}

打印:

0
5.9604644775390625e-08