无法确定并打印出从 int 到 float 隐式转换的截断错误

Unable to determine and print out truncation error from int to float implicit cast

看书学C。在我的书中,类似的代码应该产生“3.000000”作为截断错误。这本书有点旧,仍然是C99标准。我错过了什么?

#include <stdio.h>

int main()
{
    int i;
    float f;

    scanf("%d", &i); // 123456789
    f = i; // implicit type cast

    printf("int: %d with size %d\n", i, sizeof(i)); // int: 123456789 with size 4
    printf("float: %f with size %d\n", f, sizeof(f)); // float: 123456792.000000 with size 4

    printf("error: %f with size %d\n", f-i, sizeof(f-i)); // error 0.000000 with size 4

    return 0;
}

我认为0.000000是正确的。 C99 6.3.1.8p1 说:

Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float.

所以在 f-i 中,i 被转换为 float,产生与 f 相同的值。我不确定你的书的编译器是如何得到 3.000000.

如果您真的想看到截断错误,请执行 (double)f - i