*/
package gmp
-// #include <gmp.h>
-// #include <stdlib.h>
+/*
+#cgo LDFLAGS: -lgmp
+#include <gmp.h>
+#include <stdlib.h>
+
+// gmp 5.0.0+ changed the type of the 3rd argument to mp_bitcnt_t,
+// so, to support older versions, we wrap these two functions.
+void _mpz_mul_2exp(mpz_ptr a, mpz_ptr b, unsigned long n) {
+ mpz_mul_2exp(a, b, n);
+}
+void _mpz_div_2exp(mpz_ptr a, mpz_ptr b, unsigned long n) {
+ mpz_div_2exp(a, b, n);
+}
+*/
import "C"
import (
func (z *Int) SetString(s string, base int) error {
z.doinit()
if base < 2 || base > 36 {
- return os.EINVAL
+ return os.ErrInvalid
}
p := C.CString(s)
defer C.free(unsafe.Pointer(p))
if C.mpz_set_str(&z.i[0], p, C.int(base)) < 0 {
- return os.EINVAL
+ return os.ErrInvalid
}
return nil
}
func (z *Int) Lsh(x *Int, s uint) *Int {
x.doinit()
z.doinit()
- C.mpz_mul_2exp(&z.i[0], &x.i[0], C.mp_bitcnt_t(s))
+ C._mpz_mul_2exp(&z.i[0], &x.i[0], C.ulong(s))
return z
}
func (z *Int) Rsh(x *Int, s uint) *Int {
x.doinit()
z.doinit()
- C.mpz_div_2exp(&z.i[0], &x.i[0], C.mp_bitcnt_t(s))
+ C._mpz_div_2exp(&z.i[0], &x.i[0], C.ulong(s))
return z
}
}
}
- fmt.Printf("\n%d calls; bit sizes: %d %d %d\n", runtime.Cgocalls(), numer.Len(), accum.Len(), denom.Len())
+ fmt.Printf("\n%d calls; bit sizes: %d %d %d\n", runtime.NumCgoCall(), numer.Len(), accum.Len(), denom.Len())
}