小编arm*_*nan的帖子

为什么返回浮点值会改变其值?

下面的代码提出了assertRed Hat 5.4 32位,但适用于Red Hat 5.4 64位(或CentOS).

在32位上,我必须将返回值millis2seconds放在变量中,否则assert会引发该值,表明double函数返回的值与传递给它的值不同.

如果你评论"#define BUG"行,它就可以了.

感谢@R,将-msse2 -mfpmath选项传递给编译器使millis2seconds函数的两个变量都起作用.

/*
 * TestDouble.cpp
 */

#include <assert.h>
#include <stdint.h>
#include <stdio.h>

static double millis2seconds(int millis) {
#define BUG
#ifdef BUG
    // following is not working on 32 bits architectures for any values of millis
    // on 64 bits architecture, it works
    return (double)(millis) / 1000.0;
#else
    //  on 32 bits architectures, we must do the operation in 2 steps ?!? ... …
Run Code Online (Sandbox Code Playgroud)

c c++ floating-point x86

20
推荐指数
2
解决办法
3280
查看次数

标签 统计

c ×1

c++ ×1

floating-point ×1

x86 ×1