Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: show values of MaxXxx and MinXxx on documentation #51282

Open
shuLhan opened this issue Feb 20, 2022 · 1 comment
Open

math: show values of MaxXxx and MinXxx on documentation #51282

shuLhan opened this issue Feb 20, 2022 · 1 comment
Labels
Documentation NeedsInvestigation

Comments

@shuLhan
Copy link
Contributor

@shuLhan shuLhan commented Feb 20, 2022

Currently, the math package show the constants values for all except for max and min integer values (MaxIntXxx, MaxUintXxx, MinIntXxx,and MinUintXxx).

Usually developer get each values of max and min integers manually (by writing some script), or view it through /ref/spec [1], or search in internet.

The idea is to allow developer to check and/or copy their values through godoc.

What did you expect to see?

const (
    MaxInt    = 1<<(intSize-1) - 1  // Equal to MaxInt32 on 32-bit or MaxInt64 on 64-bit.
    MinInt    = -1 << (intSize - 1) // Equal to MinInt32 on 32-bit or MinInt64 on 64-bit.
    MaxInt8   = 1<<7 - 1            // 127
    MinInt8   = -1 << 7             // -128
    MaxInt16  = 1<<15 - 1           // 32767
    MinInt16  = -1 << 15            // -32768
    MaxInt32  = 1<<31 - 1           // 2147483647
    MinInt32  = -1 << 31            // -2147483648
    MaxInt64  = 1<<63 - 1           // 9223372036854775807
    MinInt64  = -1 << 63            // -9223372036854775808
    MaxUint   = 1<<intSize - 1      // Equal to MaxUint32 on 32-bit or MaxUint64 on 64-bit.
    MaxUint8  = 1<<8 - 1            // 255
    MaxUint16 = 1<<16 - 1           // 65535
    MaxUint32 = 1<<32 - 1           // 4294967295
    MaxUint64 = 1<<64 - 1           // 18446744073709551615
)

What did you see instead?

const (
	MaxInt    = 1<<(intSize-1) - 1
	MinInt    = -1 << (intSize - 1)
	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
	MaxUint   = 1<<intSize - 1
	MaxUint8  = 1<<8 - 1
	MaxUint16 = 1<<16 - 1
	MaxUint32 = 1<<32 - 1
	MaxUint64 = 1<<64 - 1
)

[1] https://golang.org/ref/spec#Numeric_types

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 20, 2022

Change https://go.dev/cl/343990 mentions this issue: math: show the value of each max and min integer constants in comments

@seankhliao seankhliao added the NeedsInvestigation label Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants