以下示例应用程序应该设置一个整数值:
#include <iostream>
#include <math.h>
int Round(double val)
{
return val + 0.5;
}
double Round2(double val)
{
return floor(val + 0.5);
}
int main() {
double val1 = 16.75;
cout << "Round 16.75: " << Round(val1) << endl;
cout << "Round 21.60: " << Round2(21.60) << endl;
cout << "Round 5.50: " << Round(5.50) << endl;
cout << "Round 5.40: " << Round2(5.40) << endl;
}
在我的台式电脑上,这两个功能都正常工作。
如果我使用 arm-gnueabi-toolchain (v4.7.2) 为我的 raspberry 交叉编译它,并将编译后的文件复制到我的 raspberry 上以执行它,使用该函数的floor
函数总是返回零。
如果我在我的覆盆子上编译应用程序,它工作正常。
这是一个错误还是我做错了什么?
更新:
arm-linux-gnueabi-readelf -h -A stamp
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8908
Start of program headers: 52 (bytes into file)
Start of section headers: 4852 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 32
Section header string table index: 29
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "4T"
Tag_CPU_arch: v4T
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-1
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_DIV_use: Not allowed
Update2
这不仅仅是双倍的问题。当我尝试返回时,float
我也只得到零。