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/big: about bigint add #60762

Closed
tedmax100 opened this issue Jun 13, 2023 · 1 comment
Closed

math/big: about bigint add #60762

tedmax100 opened this issue Jun 13, 2023 · 1 comment

Comments

@tedmax100
Copy link

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

@tedmax100 tedmax100 changed the title math/big : bigint add math/big : about bigint add Jun 13, 2023
@seankhliao seankhliao changed the title math/big : about bigint add math/big: about bigint add Jun 13, 2023
@seankhliao
Copy link
Member

https://pkg.go.dev/math/big#Int

shallow copies of Ints are not supported and may lead to errors.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2023
@golang golang locked and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants