什么最大整数,能够加 1 浮点类型可以在 C++ 中保存?

Dim*_*ims 1 c++ floating-point types terminology numeric-limits

假设我float用来保存整数值并向其添加小偏移,大约 1 秒或 2 秒。在哪个值float会停止变化?这个值的名称是什么?

Nel*_*eal 8

a您得到的 IEEE 754 浮点变量的最小正值a == a+12^bits_precision,其中bits_precision比有效数中的位数多 1,可以通过 找到std::numeric_limits<T>::digits

对于 32 位float,这是 24;对于 64 位double,这是 53(同样,在 IEEE 754 的非常常见的上下文中)。

演示