c++ - 不正确的浮点行为

标签 c++ floating-point embedded-linux ieee-754 powerpc

当我在支持软件 float 仿真(禁用硬件浮点)的 32 位 powerpc 内核中运行以下 C++ 程序时,我得到一个不正确的条件评估。有人能告诉我这里的潜在问题是什么吗?

#include <stdio.h>

int main() {
   int newmax = 1;
   if ((newmax + 0.0) > 256) {
       printf("\nShouldn't be here\n");
   } else {
       printf("\nShould be here\n");
   }
}

编译:

powerpc-linux-g++ -msoft-float -c floating.cxx
powerpc-linux-g++  -o floating floating.o

目标系统中的输出:

[linux:/]$ ./floating
Shouldn't be here

最佳答案

你也应该在链接时指定 -msoft-float 给我们一个带有 -S 标志的反汇编:powerpc-linux-g++ -msoft-float -c floating.cxx -S -o floating.s

关于c++ - 不正确的浮点行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15045351/

相关文章:

c++ - 重载运算符 ()

c++ - 将压缩帧写入 mpeg4 chuncks C++

c++ - const关键字在编程中有什么好处?

c++ - 当子类的析构函数被调用时,父类的析构函数也会被调用吗?

c - 向下舍入浮点结果

linux - 在 NanoPi Neo 开发板上定制 Linux

linux - 嵌入式Linux内核与桌面Linux内核的区别

embedded-linux - IMAGE_INSTALL 与 PACKAGE_FEATURES - 有什么区别?

javascript - 处理大数时的中点 'rounding'?

c - floor(a/(double)b​​)*b==a 如果 a%b==0 在 C 中?