为什么在64位系统上float不是double? [英] Why is float not a double on a 64-bit system?
问题描述
考虑到 int
在32位系统上为4个字节,在64位系统上为8个字节,为什么 float
没有处理相同?为什么64位系统上的
double
!= float
的大小?考虑到当我声明一个 int
(这导致更高的性能),对于 float
(这也会导致性能提高)不应该发生同样的情况吗?
Considering an int
will be 4 bytes on a 32-bit system and 8 bytes on a 64-bit system, why is float
not treated the same? Why is size of a double
!= size of a float
on a 64-bit system? Considering that the best native integer type is selected when I declare an int
(which results in higher performance), shouldn't the same happen for float
(which also results in a performance increase)?
相关问题:声明一个类型 my_float
(pardon的名称!)是一个坏主意,是 float
在32位系统上, double
在64位系统上?
Related question: Is it a bad idea to declare a type my_float
(pardon the name!) that is float
on 32-bit systems and double
on 64-bit systems?
推荐答案
您的问题是基于一个错误的前提。在大多数现代64位系统上, int
仍然是4字节。为什么消耗两倍的内存和两倍的内存带宽,这么大的整数是如此罕见的需要?在典型的现代64位系统上,对64位整数的数学运算不如32位整数的数学运算,因此没有任何好处。
Your question is based on a false premise. On most modern 64-bit systems, int
is still 4 bytes. Why consume twice as much memory and twice as much memory bandwidth when such large integers are so rarely needed? On typical modern 64-bit systems, math on 64-bit integers is not faster than math on 32-bit integers, so there's no benefit to be had.
这篇关于为什么在64位系统上float不是double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!