Beispiel #1
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
}
Beispiel #2
0
Datei: int.go Projekt: locusf/gmp
// SetInt64 sets z to x and returns z.
func (z *Int) SetInt64(x int64) *Int {
	z.doinit()
	// Test for truncation
	y := C.long(x)
	if int64(y) == x {
		C.mpz_set_si(&z.i[0], y)
	} else {
		negative := false
		if x < 0 {
			x = -x
			negative = true
		}
		C.mpz_import(&z.i[0], 1, 0, 8, 0, 0, unsafe.Pointer(&x))
		if negative {
			C.mpz_neg(&z.i[0], &z.i[0])
		}
	}
	return z
}
Beispiel #3
0
// SetInt64 sets z = x and returns z.
func (z *Int) SetInt64(x int64) *Int {
	z.doinit()
	// TODO(rsc): more work on 32-bit platforms
	C.mpz_set_si(&z.i[0], C.long(x))
	return z
}