码头工人。gcc10 in arm64 debian.gcc7 in x86_64 debian.
#include <cstdio>
#include <limits>
#include <cstdint>
int main(int args, char *argv[]) {
double d = std::numeric_limits<int64_t>::max();
int64_t t = static_cast<int64_t>(d);
printf("%lld\n", t);
return 0;
}输出:
有人能帮我理解为什么会有不同吗?
发布于 2021-12-07 11:32:52
答案是ARM体系结构在转换中溢出的不同行为(在本例中为int64_t )。它是在这里记录的(对于ARMv7):https://developer.arm.com/documentation/ddi0403/d/Application-Level-Architecture/Application-Level-Programmers--Model/The-optional-Floating-point-extension/Floating-point-data-types-and-arithmetic?lang=en
TL:DR:最大可表示值用于ARM (int64_t为9223372036854775807)。( @PeterCordes猜测)
编辑:对于x86 / x64,溢出将导致一个整数,只有MSB设置(在int64_t情况下为-9223372036854775808 )。
https://stackoverflow.com/questions/70258776
复制相似问题