目录 [−]

常量

1. 常量表达式， 如 4 * 5
2. 转换结果是常量， 如 int(10.0)
3. 内建函数的返回值， 如unsafe.Sizeofcaplen
4. 复数、实数和虚数的应用
5. truefalse赋值给bool类型的常量
6. 内建的 iota

• bool
• rune
• int
• float64
• complex128
• string

Go对常量的底层实现有限制：

• Represent integer constants with at least 256 bits.
• Represent floating-point constants, including the parts of a complex constant, with a mantissa of at least 256 bits and a signed exponent of at least 32 bits.
• Give an error if unable to represent an integer constant precisely.
• Give an error if unable to represent a floating-point or complex constant due to overflow.
• Round to the nearest representable constant if unable to represent a floating-point or complex constant due to limits on precision.