From: Colin Arnott Date: Thu, 6 Aug 2020 02:57:15 +0000 (+0000) Subject: math: add MaxUint, MinInt, MaxInt X-Git-Tag: go1.17beta1~277 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e8eb1d8269;p=gostls13.git math: add MaxUint, MinInt, MaxInt Since we have int8 to int64 min max and uint8 to uint64 max constants, we should probably have some for the word size types too. This change also adds tests to validate the correctness of all integer limit values. Fixes #28538 Change-Id: Idd25782e98d16c2abedf39959b7b66e9c4c0c98b Reviewed-on: https://go-review.googlesource.com/c/go/+/247058 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Robert Griesemer --- diff --git a/src/math/const.go b/src/math/const.go index 31954b0cae..5ea935fb42 100644 --- a/src/math/const.go +++ b/src/math/const.go @@ -37,6 +37,10 @@ const ( // Integer limit values. const ( + intSize = 32 << (^uint(0) >> 63) // 32 or 64 + + MaxInt = 1<<(intSize-1) - 1 + MinInt = -1 << (intSize - 1) MaxInt8 = 1<<7 - 1 MinInt8 = -1 << 7 MaxInt16 = 1<<15 - 1 @@ -45,6 +49,7 @@ const ( MinInt32 = -1 << 31 MaxInt64 = 1<<63 - 1 MinInt64 = -1 << 63 + MaxUint = 1<