Exemple #1
0
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.i if it needs it.  This is not inherent
// to FFI, just a mismatch between Go's convention of
// making zero values useful and gmp's decision not to.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	C.mpz_init(&z.i[0])
}
Exemple #2
0
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.t if it needs it.  This is not inherent
// to FFI, just a mismatch between Go's convention of
// making zero values useful and gmp's decision not to.
//
// Make z a reference to another mpz_t (not z.t) by directly assigning
// z.ptr and leaving z.t uninitialized. See Rat.Denom() for an example.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	z.ptr = &z.t[0]
	C.mpz_init(z.ptr)
}
Exemple #3
0
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.i if it needs it.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	C.mpz_init(&z.i[0])
	runtime.SetFinalizer(z, _Int_finalize)
}
Exemple #4
0
func (s *scalar) SetInt64(v int64) abstract.Scalar {
	vl := C.long(v)
	if int64(vl) != v {
		panic("Oops, int64 initializer doesn't fit into C.ulong")
	}
	var z C.mpz_t
	C.mpz_init(&z[0])
	C.mpz_set_si(&z[0], vl)
	C.element_set_mpz(&s.e[0], &z[0])
	C.mpz_clear(&z[0])
	return s
}