当前位置: 首页>>代码示例>>Golang>>正文


Golang Int.SetBits方法代码示例

本文整理汇总了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)
}
开发者ID:EricLagergren,项目名称:decimal,代码行数:7,代码来源:abs.go

示例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)
}
开发者ID:asimshankar,项目名称:bn256,代码行数:7,代码来源:bn256_64.go

示例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)
}
开发者ID:asimshankar,项目名称:bn256,代码行数:8,代码来源:bn256_32.go

示例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}
}
开发者ID:jloup,项目名称:utils,代码行数:14,代码来源:flag.go

示例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
}
开发者ID:remyoudompheng,项目名称:bigfft,代码行数:40,代码来源:fermat.go

示例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])
	}
}
开发者ID:cookieo9,项目名称:go-misc,代码行数:12,代码来源:big128.go


注:本文中的math/big.Int.SetBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。