gpt4 book ai didi

C++ F32 包含文件?

转载 作者:行者123 更新时间:2023-11-28 03:41:44 25 4
gpt4 key购买 nike

我刚刚开始编写自己的内存管理器,但为此,我需要某种类型的包含文件来创建 f32 ( float )。

我有 #include <cstdint>已经在我的程序中了,但我不确定 F32 需要什么, 或 I32就此而言。

最佳答案

据我所知,目前还没有标准化的方法来获取固定宽度的浮点类型——我认为是因为,与整数类型不同,floatdouble或多或少到处都是相同的(32 位 float ,64 位 double ,“奇怪”的 FP 类型有不同的类型)。

不过,如果您想更加确定,可以在创建 typedef 之前执行静态断言:

#include <climits>
static_assert(sizeof(float)*CHAR_BIT==32, "float is not 32 bit on this architecture, fix the f32 typedef.");
typedef float f32;

这样,在“健全”的平台上它会完美运行,而在“奇怪”的平台上它将无法编译,让您有机会添加特定于平台的 typedef .

至于I32,包含<cstdint>就够了并创建您的 typedef:

#include <cstdint>
typedef std::int32_t i32;

关于C++ F32 包含文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8965908/

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