在C或C++中是否有标准宏表示int32_t、int64_t的最大值和最小值
Is there a standard macro in C or C++ represent the max and min value of int32_t, int64_t?
在C或C++中是否有任何宏表示int32_t和int64_t的最大值和最小值?我知道它可以自己定义,但最好有一个标准的宏。请注意,我不是在问int、long等的最大值。但intXX_t
在C++中,<limits>
标头中有std::numeric_limits::min()
和std::numeric_limits::max()
:
std::cout << std::numeric_limits<std::int32_t>::min() << std::endl;
等等。在C中,报头<stdint.h>
定义了INT32_MIN
、INT32_MAX
等。这些在C++<cstdint>
报头中也可用。
在C++中,您可以使用此标头中声明的标头<limits>
和类别std::numeric_limts
。
要知道类型int32_t和int64_t的最大值和最小值,可以编写例如
#include <cstdint>
#include <limits>
//...
std::cout << std::numeric_limits<int32_t>::max() << std::endl;
std::cout << std::numeric_limits<int32_t>::min() << std::endl;
std::cout << std::numeric_limits<int64_t>::max() << std::endl;
std::cout << std::numeric_limits<int64_t>::min() << std::endl;
在C中,您应该包括标题<stdint.h>
,并使用标题中定义的相应宏,例如
INT32_MIN
INT32_MAX
INT64_MIN
INT64_MAX
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 使用递归的数组的最小值.这是怎么回事
- 如何创建一个函数来计算并返回平均值、最大值和最小值
- 在二维数组中查找最小值和最大值?
- 有没有办法使用递归函数找到数组中最小值的 INDEX?C++
- 程序以使用 C++ 中的 while 循环查找一组数字的最小值
- 查找数组中第一个最小值和最后一个最大值元素之间的算术平均值
- C++ 函数,用于查找传入的 N 个数字的平均值、总和、最小值和最大值
- txt 文件中浮点数的最大和最小值
- 余数运算符的等效操作,用于处理低于允许的最小值
- 需要使用模板查找数组的第二个最小和最小值
- CUDA - 将 float3 数组的 (x,y,z) 分量的最小值/最大值分开?
- 查找包含 N 个元素的数组的最小值和最大值
- 错误C++在Visual Studio 2019中使用numeric_limits的长双精度最小值/最大值
- 是否存在用于 C 或 C++ 中常见数学运算(例如最小值、最大值和平均值)的可导入库?
- 如何在 c++ 中创建对的优先级队列.这会弹出具有最小值的元素.默认的弹出最大值
- 将最小值整数转换为无符号长整型
- 查找 std::vector 中的最小值和最大值 std::p air
- 如何找到每行的最大值和最小值
- 在不进行排序的情况下查找数组中n个最小值的索引