return z
}
+// SetUint64 sets z to x and returns z.
+func (z *Rat) SetUint64(x uint64) *Rat {
+ z.a.SetUint64(x)
+ z.b.abs = z.b.abs[:0]
+ return z
+}
+
// Set sets z to x (by making a copy of x) and returns z.
func (z *Rat) Set(x *Rat) *Rat {
if z != x {
}
}
}
+
+func TestRatSetInt64(t *testing.T) {
+ var testCases = []int64{
+ 0,
+ 1,
+ -1,
+ 12345,
+ -98765,
+ math.MaxInt64,
+ math.MinInt64,
+ }
+ var r = new(Rat)
+ for i, want := range testCases {
+ r.SetInt64(want)
+ if !r.IsInt() {
+ t.Errorf("#%d: Rat.SetInt64(%d) is not an integer", i, want)
+ }
+ num := r.Num()
+ if !num.IsInt64() {
+ t.Errorf("#%d: Rat.SetInt64(%d) numerator is not an int64", i, want)
+ }
+ got := num.Int64()
+ if got != want {
+ t.Errorf("#%d: Rat.SetInt64(%d) = %d, but expected %d", i, want, got, want)
+ }
+ }
+}
+
+func TestRatSetUint64(t *testing.T) {
+ var testCases = []uint64{
+ 0,
+ 1,
+ 12345,
+ ^uint64(0),
+ }
+ var r = new(Rat)
+ for i, want := range testCases {
+ r.SetUint64(want)
+ if !r.IsInt() {
+ t.Errorf("#%d: Rat.SetUint64(%d) is not an integer", i, want)
+ }
+ num := r.Num()
+ if !num.IsUint64() {
+ t.Errorf("#%d: Rat.SetUint64(%d) numerator is not a uint64", i, want)
+ }
+ got := num.Uint64()
+ if got != want {
+ t.Errorf("#%d: Rat.SetUint64(%d) = %d, but expected %d", i, want, got, want)
+ }
+ }
+}