Beispiel #1
0
Datei: rat.go Projekt: ncw/gmp
// string returns z in the base given
func (z *Rat) string(base int) string {
	if z == nil {
		return "<nil>"
	}
	z.doinit()
	p := C.mpq_get_str(nil, C.int(base), &z.i[0])
	s := C.GoString(p)
	C.free(unsafe.Pointer(p))
	return s
}
Beispiel #2
0
// String returns the decimal representation of z.
func (q *Rat) StringBase(base int) (string, error) {
	if q == nil {
		return "nil", nil
	}
	if base < 2 || base > 36 {
		return "", os.ErrInvalid
	}
	q.doinit()
	p := C.mpq_get_str(nil, C.int(base), &q.i[0])
	s := C.GoString(p)
	C.free(unsafe.Pointer(p))
	return s, nil
}