Example #1
0
// Cmp compares x and y. The result is
//
//   -1 if x <  y
//    0 if x == y
//   +1 if x >  y
//
func (x *Int) Cmp(y *Int) int {
	x.doinit()
	y.doinit()
	switch cmp := int(C.mpz_cmp(x.ptr, y.ptr)); {
	case cmp < 0:
		return -1
	case cmp == 0:
		return 0
	}
	return 1
}
Example #2
0
// CmpInt compares x and y. The result is
//
//   -1 if x <  y
//    0 if x == y
//   +1 if x >  y
//
func CmpInt(x, y *Int) int {
	x.doinit()
	y.doinit()
	switch cmp := C.mpz_cmp(&x.i[0], &y.i[0]); {
	case cmp < 0:
		return -1
	case cmp == 0:
		return 0
	}
	return +1
}
Example #3
0
File: int.go Project: locusf/gmp
// Cmp compares x and y and returns:
//
//   -1 if x <  y
//    0 if x == y
//   +1 if x >  y
//
func (x *Int) Cmp(y *Int) (r int) {
	x.doinit()
	y.doinit()
	r = int(C.mpz_cmp(&x.i[0], &y.i[0]))
	if r < 0 {
		r = -1
	} else if r > 0 {
		r = 1
	}
	return
}