小编Jer*_*son的帖子

同样简单的计算,不同的结果

使用 gcc 4.8.2 (Ubuntu 14.04) 我得到不同的结果,同时基本上以相同的方式计算一个值。根据我测试的系统上的架构(32 位 / 64 位),也存在差异。

#include <math.h>
#include <stdio.h>

int main()
{
    float h = 0.11f; 
    float y = 0.11f;
    float g = 1.37906f;
    float x = 2.916949f;

    float result1 = (h * y / fabs(g)) / x;

    float result2 = h * y / fabs(g);
    result2 /= x;

    float result3 = (h * y / g) / x;

    printf("%.20f \n", result1); //0.00300796888768672943 
    printf("%.20f \n", result2); //0.00300796912051737309 
    printf("%.20f \n", result3); //0.00300796912051737309 on x64
                                 //0.00300796888768672943 on …
Run Code Online (Sandbox Code Playgroud)

c floating-point gcc gcc4.8

2
推荐指数
1
解决办法
125
查看次数

标签 统计

c ×1

floating-point ×1

gcc ×1

gcc4.8 ×1