本文整理匯總了Golang中C.mp_bitcnt_t函數的典型用法代碼示例。如果您正苦於以下問題:Golang mp_bitcnt_t函數的具體用法?Golang mp_bitcnt_t怎麽用?Golang mp_bitcnt_t使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mp_bitcnt_t函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetBit
// SetBit sets z to x, with x's i'th bit set to b (0 or 1).
// That is, if bit is 1 SetBit sets z = x | (1 << i);
// if bit is 0 it sets z = x &^ (1 << i). If bit is not 0 or 1,
// SetBit will panic.
func (z *Int) SetBit(x *Int, i int, b uint) *Int {
z.doinit()
if i < 0 {
panic("negative bit index")
}
z.Set(x)
switch b {
case 0:
C.mpz_clrbit(z.ptr, C.mp_bitcnt_t(i))
case 1:
C.mpz_setbit(z.ptr, C.mp_bitcnt_t(i))
default:
panic("set bit is not 0 or 1")
}
return z
}
示例2: doinit
// 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 f.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 (f *Float) doinit() {
if f.init {
return
}
if f.prec != 0 {
C.mpf_init2(&f.i[0], C.mp_bitcnt_t(f.prec))
} else {
C.mpf_init(&f.i[0])
}
f.init = true
}
示例3: EqFloat
// Return non-zero if the first n bits of x and y are equal,
// zero otherwise. I.e., test if x and y are approximately equal.
func EqFloat(x, y *Float, n uint) int {
x.doinit()
y.doinit()
return int(C.mpf_eq(&x.i[0], &y.i[0], C.mp_bitcnt_t(n)))
}
示例4: Div2Exp
// Div2Exp sets z = x / 2^s and returns z.
func (f *Float) Div2Exp(x *Float, s uint) *Float {
x.doinit()
f.doinit()
C.mpf_div_2exp(&f.i[0], &x.i[0], C.mp_bitcnt_t(s))
return f
}
示例5: SetDefaultPrec
func SetDefaultPrec(prec uint) {
C.mpf_set_default_prec(C.mp_bitcnt_t(prec))
}
示例6: SetPrecRaw
func (f *Float) SetPrecRaw(prec uint) {
f.doinit()
C.mpf_set_prec_raw(&f.i[0], C.mp_bitcnt_t(prec))
}
示例7: SetPrec
func (f *Float) SetPrec(prec uint) {
f.doinit()
C.mpf_set_prec(&f.i[0], C.mp_bitcnt_t(prec))
f.prec = prec
}
示例8: Rsh
// Rsh sets z = x >> s and returns 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))
return z
}
示例9: Div2Exp
// Div2Exp sets z = x / 2^s and returns z.
func (q *Rat) Div2Exp(x *Rat, s uint) *Rat {
x.doinit()
q.doinit()
C.mpq_div_2exp(&q.i[0], &x.i[0], C.mp_bitcnt_t(s))
return q
}
示例10: Bit
// Bit returns the value of the i'th bit of x. That is, it
// returns (x>>i)&1. The bit index i must be >= 0.
func (x *Int) Bit(i int) uint {
x.doinit()
return uint(C.mpz_tstbit(x.ptr, C.mp_bitcnt_t(i)))
}
示例11: Mul2Exp
// Mul2Exp sets z = x * 2^s and returns z.
func (f *Float) Mul2Exp(x *Float, s uint) *Float {
C.mpf_mul_2exp(&f.i[0], &x.i[0], C.mp_bitcnt_t(s))
return f
}
示例12: SetPrec
func (f *Float) SetPrec(prec int) {
C.mpf_set_prec(&f.i[0], C.mp_bitcnt_t(prec))
}