Skip to content

proposal: math: Go 2: use explicit types for limit constants #23087

@ianlancetaylor

Description

@ianlancetaylor

math.MaxInt64 and friends are untyped constants. This causes confusion when using the constants on 32-bit systems. For example, on a 32-bit system,

var V = math.MaxInt64

does not compile: constant 9223372036854775807 overflows int.

This confusion has been reported at #19621 and #23086.

This can not be changed for Go 1 without breaking backward compatibility. For Go 2 we could use explicit types for the constants, so that the type of math.MaxInt64 is int64, and so forth. I believe that would cause less confusion in the long run.

It could, however, break currently working code that expects values like math.MaxInt8 to take on type int. In this proposal they would be type int8. So some existing code may need to be changed to add explicit conversions to int. It should be possible to automate this conversion using go fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions