Beispiel #1
0
Datei: rat.go Projekt: ncw/gmp
// SetFrac sets z to a/b and returns z.
func (z *Rat) SetFrac(a, b *Int) *Rat {
	z.doinit()
	a.doinit()
	b.doinit()
	// FIXME copying? or referencing?
	C.mpq_set_num(&z.i[0], &a.i[0])
	C.mpq_set_den(&z.i[0], &b.i[0])
	C.mpq_canonicalize(&z.i[0])
	return z
}
Beispiel #2
0
Datei: rat.go Projekt: ncw/gmp
// SetDenom sets the numerator of z returning z
//
// NB this isn't part of math/big which uses Num().Set() for this
// purpose. In gmp Num() returns a copy hence the need for a SetNum()
// method.
func (z *Rat) SetDenom(a *Int) *Rat {
	z.doinit()
	a.doinit()
	C.mpq_set_den(&z.i[0], &a.i[0])
	// If numerator is zero don't canonicalize
	if C._mpq_num_sgn(&z.i[0]) != 0 {
		C.mpq_canonicalize(&z.i[0])
	}
	return z
}
Beispiel #3
0
func (q *Rat) SetDen(n *Int) *Rat {
	q.doinit()
	n.doinit()
	C.mpq_set_den(&q.i[0], &n.i[0])
	return q
}