Commit 0dc24603 authored by Eoghan Sherry's avatar Eoghan Sherry Committed by Robert Griesemer

big: fix (*Rat) SetFrac64(a, b) when b < 0.

R=gri
CC=golang-dev
https://golang.org/cl/3352041
parent e1149aa0
...@@ -35,9 +35,8 @@ func (z *Rat) SetFrac(a, b *Int) *Rat { ...@@ -35,9 +35,8 @@ func (z *Rat) SetFrac(a, b *Int) *Rat {
func (z *Rat) SetFrac64(a, b int64) *Rat { func (z *Rat) SetFrac64(a, b int64) *Rat {
z.a.SetInt64(a) z.a.SetInt64(a)
if b < 0 { if b < 0 {
z.b.setUint64(uint64(-b)) b = -b
z.a.neg = !z.a.neg z.a.neg = !z.a.neg
return z.norm()
} }
z.b = z.b.setUint64(uint64(b)) z.b = z.b.setUint64(uint64(b))
return z.norm() return z.norm()
......
...@@ -257,3 +257,26 @@ func TestIssue820(t *testing.T) { ...@@ -257,3 +257,26 @@ func TestIssue820(t *testing.T) {
t.Errorf("got %s want %s", z, q) 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)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment