Numeric types
数字类型 表示整数或浮点值的集合。预先声明的与体系结构无关的数字类型为:
uint8 the set of all unsigned 8-bit integers (0 to 255)
uint16 the set of all unsigned 16-bit integers (0 to 65535)
uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
int8 the set of all signed 8-bit integers (-128 to 127)
int16 the set of all signed 16-bit integers (-32768 to 32767)
int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
float32 the set of all IEEE-754 32-bit floating-point numbers
float64 the set of all IEEE-754 64-bit floating-point numbers
complex64 the set of all complex numbers with float32 real and imaginary parts
complex128 the set of all complex numbers with float64 real and imaginary parts
byte alias for uint8
rune alias for int32
n 位整数的值是 n 位宽,并使用二进制补码算术表示。
还有一组预先声明的数字类型,具有特定于实现的大小:
uint either 32 or 64 bits
int same size as uint
uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value
为避免可移植性问题,所有数字类型均为定义的类型 因此除 byte
以外的其他数字类型都不同,后者是别名用于 uint8
, 和 rune
, 这是 int32
的别名。在表达式或赋值中混合使用不同的数字类型时,需要进行显式转换。例如,int32
和 int
的类型不同,即使它们在特定体系结构上的大小可能相同。
本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。