gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:34:21 26 4
gpt4 key购买 nike

当我在支持软件 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com