Skip to content

math/big: (*Rat).SetString("1234") not the same as big.NewRat(1234, 1) #28884

@damastes

Description

@damastes

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

1.11.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

func main() {
	var x, y big.Rat
	
	x = *big.NewRat(123456789, 1)
	y.SetString("123456789")
	
	fmt.Printf("%#v\n", x)
	fmt.Printf("%#v\n", y)
}

https://play.golang.org/p/yFKM2k6djNA

What did you expect to see?

I would expect to see both structures be identical.

big.Rat{a:big.Int{neg:false, abs:big.nat{0x75bcd15}}, b:big.Int{neg:false, abs:big.nat{}}}
big.Rat{a:big.Int{neg:false, abs:big.nat{0x75bcd15}}, b:big.Int{neg:false, abs:big.nat{}}}

What did you see instead?

While the same numerical value, they are different for the purposes of test assertion.

big.Rat{a:big.Int{neg:false, abs:big.nat{0x75bcd15}}, b:big.Int{neg:false, abs:big.nat{}}}
big.Rat{a:big.Int{neg:false, abs:big.nat{0x75bcd15}}, b:big.Int{neg:false, abs:big.nat(nil)}}

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