go - 如何将最小值/最大值设置为整数变量
问题描述
就像在 Java 中一样,我们将变量初始化为最小值/最大值,
Integer.MIN_VALUE and Integer.MAX_VALUE
Go有什么办法吗?
解决方案
它们在数学包中可用:
整数限制值。
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 )
推荐阅读
- c# - 如何在 Azure DevOps 中实现自动化集成测试 (C#) 和功能/场景之间的关联?
- sass - Nuxt & SassError:未定义的变量
- c# - ASP.Net Core - 从 Razor 视图调用静态方法 - 构建失败而不给出错误
- python - 可变源序列的所有唯一排列
- reactjs - “从不”类型上不存在属性“id”。地图功能
- excel - 如果工作表 1 中的 2 个短语在工作表 2 中匹配,则将该行复制到工作表 1
- kotlin - 将字符串转换为具有空安全性的日期
- javascript - 如何返回事件总线?
- flutter - 在超级构造函数中保证 globalkey
- reactjs -
反应路由器dom v6