Skip to content

math/big: about bigint add  #60762

@tedmax100

Description

@tedmax100

What version of Go are you using (go version)?

$ go version
go version go1.20.1 darwin/arm64

What did you do?

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"math/big"
)

type Test struct {
	target big.Int
}

func OO(input Test) {
	input.target.Add(&input.target, big.NewInt(2))
}

func main() {
	var yy Test
	yy.target.SetUint64(0)
	for i := 0; i < 4; i++ {
		OO(yy)
		fmt.Println(yy.target.String())
		yy.target.Add(&yy.target, big.NewInt(10))
	}
	fmt.Println(yy.target.String())
}
I 

What did you expect to see?

I thought the answer was.
0
10
20
30
40

But i got
0
10
22
34
44

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions