Skip to content

proposal: math/big: add Int.AddInt64, Int.CmpInt64 #29951

@TuomLarsen

Description

@TuomLarsen

Please consider adding big.Int methods Inc and Dec which would increase or decrease the given Int by one. It would be similar to the following code, except for the allocation:

x.Add(x, big.NewInt(1))

The motivation is that it is quite common operation and the code using it would be simpler and saving one allocation.

Alternatively, please consider AddInt(64) and SubInt(64), which would still save one allocation when knowing the increment/decrement fits a (64-bit) machine word.

Cursory look at Go source shows that the first alternative could be useful here and here, and the second one here.

Yet another alternative would be to expose intOne from int.go.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions