mirror of
https://github.com/golang/go
synced 2024-11-22 01:44:40 -07:00
big: fix (*Rat) SetFrac64(a, b) when b < 0.
R=gri CC=golang-dev https://golang.org/cl/3352041
This commit is contained in:
parent
e1149aa08d
commit
0dc24603eb
@ -35,9 +35,8 @@ func (z *Rat) SetFrac(a, b *Int) *Rat {
|
||||
func (z *Rat) SetFrac64(a, b int64) *Rat {
|
||||
z.a.SetInt64(a)
|
||||
if b < 0 {
|
||||
z.b.setUint64(uint64(-b))
|
||||
b = -b
|
||||
z.a.neg = !z.a.neg
|
||||
return z.norm()
|
||||
}
|
||||
z.b = z.b.setUint64(uint64(b))
|
||||
return z.norm()
|
||||
|
@ -257,3 +257,26 @@ func TestIssue820(t *testing.T) {
|
||||
t.Errorf("got %s want %s", z, q)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var setFrac64Tests = []struct {
|
||||
a, b int64
|
||||
out string
|
||||
}{
|
||||
{0, 1, "0"},
|
||||
{0, -1, "0"},
|
||||
{1, 1, "1"},
|
||||
{-1, 1, "-1"},
|
||||
{1, -1, "-1"},
|
||||
{-1, -1, "1"},
|
||||
{-9223372036854775808, -9223372036854775808, "1"},
|
||||
}
|
||||
|
||||
func TestRatSetFrac64Rat(t *testing.T) {
|
||||
for i, test := range setFrac64Tests {
|
||||
x := new(Rat).SetFrac64(test.a, test.b)
|
||||
if x.RatString() != test.out {
|
||||
t.Errorf("#%d got %s want %s", i, x.RatString(), test.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user