本文整理汇总了Golang中math/big.Int.SetBits方法的典型用法代码示例。如果您正苦于以下问题:Golang Int.SetBits方法的具体用法?Golang Int.SetBits怎么用?Golang Int.SetBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/big.Int
的用法示例。
在下文中一共展示了Int.SetBits方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BigAbsCmp
func BigAbsCmp(x, y big.Int) int {
// SetBits sets to |v|, thus giving an absolute comparison.
var x0, y0 big.Int
x0.SetBits(x.Bits())
y0.SetBits(y.Bits())
return x0.Cmp(&y0)
}
示例2: scalar2big
func scalar2big(out *big.Int, in *[4]C.ulonglong) {
bits := make([]big.Word, 4)
for i := range bits {
bits[i] = big.Word(in[i])
}
out.SetBits(bits)
}
示例3: scalar2big
func scalar2big(out *big.Int, in *[4]C.ulonglong) {
bits := make([]big.Word, 8)
for i := 0; i < len(bits); i += 2 {
bits[i] = big.Word(in[i>>1] & 0x00000000ffffffff)
bits[i+1] = big.Word((in[i>>1] & 0xffffffff00000000) >> 32)
}
out.SetBits(bits)
}
示例4: NewBigInt
// Initialize a Flag that will Intersect with all flags with a value up to (length -1)
func NewBigInt(length int) Flag {
n := (length + _WORDSIZE - 1) / _WORDSIZE
wordTable := make([]big.Word, 0)
for i := 0; i < n; i++ {
wordTable = append(wordTable, _word1)
}
b := big.Int{}
b.SetBits(wordTable)
return Flag{N: b}
}
示例5: Mul
func (z fermat) Mul(x, y fermat) fermat {
n := len(x) - 1
if n < 30 {
z = z[:2*n+2]
basicMul(z, x, y)
z = z[:2*n+1]
} else {
var xi, yi, zi big.Int
xi.SetBits(x)
yi.SetBits(y)
zi.SetBits(z)
zb := zi.Mul(&xi, &yi).Bits()
if len(zb) <= n {
// Short product.
copy(z, zb)
for i := len(zb); i < len(z); i++ {
z[i] = 0
}
return z
}
z = zb
}
// len(z) is at most 2n+1.
if len(z) > 2*n+1 {
panic("len(z) > 2n+1")
}
i := len(z) - (n + 1) // i <= n
c := subVV(z[1:i+1], z[1:i+1], z[n+1:])
z = z[:n+1]
z[n]++ // Add -1.
subVW(z[i+1:], z[i+1:], c)
// Add 1.
if z[n] == 1 {
z[n] = 0
} else {
addVW(z, z, 1)
}
z.norm()
return z
}
示例6: PreallocInt
// PreallocInt preallocates 128-bits of storage for an existing
// big.Int value. Will not perform the pre-allocation if the given
// pointer is nil, or if the storage has already been allocated.
//
// This function serves very little purpose as it provides no benefits
// whatsoever, and is only included for completeness.
func PreallocInt(i *big.Int) {
var mem [pS]big.Word
if i != nil && cap(i.Bits()) == 0 {
i.SetBits(mem[0:0])
}
}