就像在 Java 中一样,我们将变量初始化为最小值/最大值,
Integer.MIN_VALUE and Integer.MAX_VALUE
Run Code Online (Sandbox Code Playgroud)
Go有什么办法吗?
它们在数学包中可用:
整数限制值。
Run Code Online (Sandbox Code Playgroud)const ( MaxInt8 = 1<<7 - 1 MinInt8 = -1 << 7 MaxInt16 = 1<<15 - 1 MinInt16 = -1 << 15 MaxInt32 = 1<<31 - 1 MinInt32 = -1 << 31 MaxInt64 = 1<<63 - 1 MinInt64 = -1 << 63 MaxUint8 = 1<<8 - 1 MaxUint16 = 1<<16 - 1 MaxUint32 = 1<<32 - 1 MaxUint64 = 1<<64 - 1 )
https://golang.org/pkg/math/#pkg-constants
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |