C浮动操作在i386和arm上有不同的结果,但为什么呢?

Ale*_*rtt 4 c floating-point arm

我在C中实现了一个使用浮点数的算法.当我在i386上编译并运行时,我得到的结果与我在armel上编译和运行时获得的结果不同.特别是按浮点数划分,会产生不同的浮点数.

我从算法中提取了一些代码来演示这个问题:

#include <stdio.h>
void main(void)
{
    float x = 4.80000019;
    float y = 4.80000019;
    int a = 38000;
    int b = 10000;
    int result = (a/x)+(b/y);
    printf("%.8f, %.8f\n", x, y); // same on i386 and armel
    printf("%f, %f\n", a/x, b/y); // slightly different on each
    printf("%d\n", result);       // prints 9999 on i386, and 10000 on armel
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释为什么这两个平台产生不同的结果?

亚历克斯

R..*_*R.. 6

查找"超额精确度".要在现代x86上禁止它,请使用-msse2 -mfpmath=sse.