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


Golang Int.SetUint64方法代码示例

本文整理汇总了Golang中math/big.Int.SetUint64方法的典型用法代码示例。如果您正苦于以下问题:Golang Int.SetUint64方法的具体用法?Golang Int.SetUint64怎么用?Golang Int.SetUint64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math/big.Int的用法示例。


在下文中一共展示了Int.SetUint64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BenchmarkPe1bloop

func BenchmarkPe1bloop(b *testing.B) {
	bi := new(big.Int)
	bi.SetUint64(uint64(1000000))
	for i := 0; i < b.N; i++ {
		pe.Pe1bloop(bi)
	}
}
开发者ID:kittttttan,项目名称:pe,代码行数:7,代码来源:pe_test.go

示例2: TestDecodeBigNumber

func TestDecodeBigNumber(t *testing.T) {
	var value big.Int

	value.SetUint64(^uint64(0))

	value.Mul(&value, big.NewInt(32))

	b := bytes.Buffer{}
	e := NewEncoder(&b)

	err := e.Encode(value)
	if err != nil {
		t.Fatal(err)
	}

	t.Log(hex.Dump(b.Bytes()))

	d := NewDecoder(&b)

	found, err := d.DecodeNext()
	if err != nil {
		t.Fatal(err)
	}
	i := found.(big.Int)

	if i.Cmp(&value) != 0 {
		t.Fatalf("expected %v but %v found", value, found)
	}
}
开发者ID:shitfSign,项目名称:go-rencode,代码行数:29,代码来源:rencode_test.go

示例3: calcDifficultyFrontier

func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
	diff := new(big.Int)
	adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
	bigTime := new(big.Int)
	bigParentTime := new(big.Int)

	bigTime.SetUint64(time)
	bigParentTime.SetUint64(parentTime)

	if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
		diff.Add(parentDiff, adjust)
	} else {
		diff.Sub(parentDiff, adjust)
	}
	if diff.Cmp(params.MinimumDifficulty) < 0 {
		diff.Set(params.MinimumDifficulty)
	}

	periodCount := new(big.Int).Add(parentNumber, common.Big1)
	periodCount.Div(periodCount, ExpDiffPeriod)
	if periodCount.Cmp(common.Big1) > 0 {
		// diff = diff + 2^(periodCount - 2)
		expDiff := periodCount.Sub(periodCount, common.Big2)
		expDiff.Exp(common.Big2, expDiff, nil)
		diff.Add(diff, expDiff)
		diff = common.BigMax(diff, params.MinimumDifficulty)
	}

	return diff
}
开发者ID:yexingl,项目名称:go-ethereum,代码行数:30,代码来源:block_validator.go

示例4: bigIntFromFloat

// "stolen" from https://golang.org/pkg/math/big/#Rat.SetFloat64
// Removed non-finite case because we already check for
// Inf/NaN values
func bigIntFromFloat(f float64) *big.Int {
	const expMask = 1<<11 - 1
	bits := math.Float64bits(f)
	mantissa := bits & (1<<52 - 1)
	exp := int((bits >> 52) & expMask)
	if exp == 0 { // denormal
		exp -= 1022
	} else { // normal
		mantissa |= 1 << 52
		exp -= 1023
	}

	shift := 52 - exp

	// Optimization (?): partially pre-normalise.
	for mantissa&1 == 0 && shift > 0 {
		mantissa >>= 1
		shift--
	}

	if shift < 0 {
		shift = -shift
	}

	var a big.Int
	a.SetUint64(mantissa)
	return a.Lsh(&a, uint(shift))
}
开发者ID:patrickToca,项目名称:decimal,代码行数:31,代码来源:decimal.go

示例5: Info

func (m *Material) Info() [][][2]string {
	var info [][][2]string

	maybe := func(name string, stat world.Stat) {
		var total, volume, tmp big.Int
		for _, c := range m.components {
			tmp.SetUint64(c.volume)
			volume.Add(&volume, &tmp)
			total.Add(&total, tmp.Mul(c.data().Stat(stat), &tmp))
		}
		if volume.Sign() == 0 {
			return
		}
		total.Div(tmp.Mul(&total, &m.quality), &volume)
		switch total.Sign() {
		case 0:
			return
		case 1:
			info = append(info, [][2]string{
				{"+" + Comma(&total), "#4f4"},
				{name, "#ccc"},
			})
		case -1:
			info = append(info, [][2]string{
				{Comma(&total), "#f44"},
				{name, "#ccc"},
			})
		}
	}

	maybe(" power", world.StatPower)
	maybe(" magic", world.StatMagic)
	maybe(" agility", world.StatAgility)
	maybe(" luck", world.StatLuck)
	maybe(" intelligence", world.StatIntelligence)
	maybe(" stamina", world.StatStamina)
	maybe(" integrity", world.StatIntegrity)

	maybe(" melee damage", world.StatMeleeDamage)
	maybe(" magic damage", world.StatMagicDamage)
	maybe(" mana", world.StatMana)
	maybe(" mana regen", world.StatManaRegen)
	maybe(" crit chance", world.StatCritChance)
	maybe(" attack speed", world.StatAttackSpeed)

	maybe(" melee armor", world.StatMeleeArmor)
	maybe(" magic armor", world.StatMagicArmor)
	maybe(" health", world.StatHealth)
	maybe(" health regen", world.StatHealthRegen)
	maybe(" resistance", world.StatResistance)
	maybe(" movement speed", world.StatMovementSpeed)

	maybe(" gathering", world.StatGathering)
	maybe(" structure health", world.StatStructureHealth)

	return info
}
开发者ID:BenLubar,项目名称:Rnoadm,代码行数:57,代码来源:material.go

示例6: TestPe1bloop

func TestPe1bloop(t *testing.T) {
	bi := new(big.Int)
	bi.SetUint64(uint64(1000))

	actual := pe.Pe1bloop(bi)
	expected := new(big.Int).SetUint64(uint64(234168))

	if actual.Cmp(expected) != 0 {
		t.Errorf("got %v, want %v", actual, expected)
	}
}
开发者ID:kittttttan,项目名称:pe,代码行数:11,代码来源:pe_test.go

示例7: computeChildSecret

// computeChildSecret helper method that derives a child secret key from the
// intermediary state.
func (k *HDKey) computeChildSecret(ilInt *big.Int) *eckey.SecretKey {
	keyInt := new(big.Int).SetBytes(k[childKeyOffset+1:])
	defer keyInt.SetUint64(0)

	ilInt.Add(ilInt, keyInt)
	ilInt.Mod(ilInt, eckey.S256.N)

	sk := new(eckey.SecretKey)
	util.PaddedCopy(sk[:], ilInt.Bytes(), eckey.SecretSize)

	return sk
}
开发者ID:NebulousLabs,项目名称:hdkey,代码行数:14,代码来源:extend_key.go

示例8: Child

// Child computes the descendant of an HDKey at the specified child number.
func (k *HDKey) Child(i uint32) (*HDKey, error) {
	// Verify that child derivation is possible
	isChildHardened := i >= HardenedKeyStart
	if !k.IsPrivate() && isChildHardened {
		return nil, ErrDeriveHardenedFromPublic
	}

	// Assemble seed data for HMAC
	seed := make([]byte, childKeySize+childNumberSize)
	if isChildHardened {
		copy(seed, k[childKeyOffset:]) // Copy 0x00 || 32-byte secret key
	} else {
		copy(seed, k.CompressedPublicKey()[:]) // Copy HEADER || 32-byte X-coord
	}
	// Copy child number as uint32
	binary.BigEndian.PutUint32(seed[childKeySize:], i)

	// il, ir = HMAC-512(chainCode, seed), clean up intermediary state
	il, childChainCode := util.HMAC512Split(k.chainCode(), seed)
	defer func() { util.Zero(il); util.Zero(childChainCode) }()

	// Left 32 bytes becomes intermediate secret key, defer clean up
	ilInt := new(big.Int).SetBytes(il)
	defer ilInt.SetUint64(0)

	// Check that ilInt creates valid SecretKey, clean up intermediary SecretKey
	isk, err := eckey.NewSecretKeyInt(ilInt)
	if err != nil {
		return nil, ErrUnusableSeed
	}
	defer isk.Zero()

	ver := k.version()
	parentCPK := k.CompressedPublicKey()
	fpBytes := util.Hash256d(parentCPK[:])[:fingerprintSize]
	fp := binary.BigEndian.Uint32(fpBytes)

	// If key is private, derive a child secret key
	if k.IsPrivate() {
		sk := k.computeChildSecret(ilInt)
		return newHDSecretKey(ver, k.depth()+1, fp, i, childChainCode, sk), nil
	}

	// Otherwise, derive child public key
	cpk, err := computeChildPublic(parentCPK, isk)
	if err != nil {
		return nil, err
	}

	return newHDPublicKey(ver, k.depth()+1, fp, i, childChainCode, cpk), nil
}
开发者ID:NebulousLabs,项目名称:hdkey,代码行数:52,代码来源:extend_key.go

示例9: TestModSqr

func TestModSqr(t *testing.T) {
	A := new(big.Int)
	B := new(big.Int)
	for _, a := range numbers {
		A.SetUint64(a)
		b := mod_sqr(a)
		B.Mul(A, A)
		B.Mod(B, P)
		expected := B.Uint64()
		if b != expected {
			t.Fatalf("%d**2: Expecting %d but got %d", a, expected, b)
		}
	}
}
开发者ID:ncw,项目名称:iprime,代码行数:14,代码来源:mod_math_test.go

示例10: pe1b

func pe1b() {
	bi := new(big.Int)
	if len(os.Args) > 1 {
		if _, ok := bi.SetString(os.Args[1], 10); !ok {
			fmt.Printf("couldn't interpret line %#v\n", os.Args[1])
		}
	} else {
		bi.SetUint64(uint64(1000))
	}

	//ans := pe.Pe1bloop(bi)
	ans := pe.Pe1b(bi)
	fmt.Println("pe1: ", ans)
}
开发者ID:kittttttan,项目名称:pe,代码行数:14,代码来源:main.go

示例11: stat

func (m *Material) stat(stat, meta *world.Stat) *big.Int {
	var total, volume, tmp big.Int
	for _, c := range m.components {
		tmp.SetUint64(c.volume)
		volume.Add(&volume, &tmp)
		total.Add(&total, tmp.Mul(c.data().Stat(*stat), &tmp))
		if meta != nil {
			total.Add(&total, tmp.Div(tmp.Mul(c.data().Stat(*meta), tmp.SetUint64(c.volume)), world.TuningMetaStatDivisor))
		}
	}
	if volume.Sign() == 0 {
		return &volume
	}
	total.Div(tmp.Mul(&total, &m.quality), &volume)
	return &total
}
开发者ID:BenLubar,项目名称:Rnoadm,代码行数:16,代码来源:material.go

示例12: NewSecretKey

func NewSecretKey(b []byte) (*SecretKey, error) {
	if len(b) != SecretSize {
		return nil, ErrInvalidSecretLength
	}

	// Copy secret bytes and clean up
	s := new(big.Int).SetBytes(b)
	defer s.SetUint64(0)

	sk, err := NewSecretKeyInt(s)
	if err != nil {
		return nil, err
	}

	return sk, nil
}
开发者ID:NebulousLabs,项目名称:hdkey,代码行数:16,代码来源:secret_key.go

示例13: TestModInv

func TestModInv(t *testing.T) {
	A := new(big.Int)
	B := new(big.Int)
	for _, a := range numbers {
		if a == 0 {
			continue
		}
		A.SetUint64(a)
		b := mod_inv(a)
		B.ModInverse(A, P)
		expected := B.Uint64()
		if b != expected {
			t.Fatalf("inv(%d): Expecting %d but got %d", a, expected, b)
		}
	}
}
开发者ID:ncw,项目名称:iprime,代码行数:16,代码来源:mod_math_test.go

示例14: TestModShift

func TestModShift(t *testing.T) {
	A := new(big.Int)
	C := new(big.Int)
	for _, a := range numbers {
		A.SetUint64(a)
		for b := uint8(0); b < 96; b++ {
			c := mod_shift(a, b)
			C.Lsh(A, uint(b))
			C.Mod(C, P)
			expected := C.Uint64()
			if c != expected {
				t.Fatalf("%d << %d: Expecting %d but got %d", a, b, expected, c)
			}
		}
	}
}
开发者ID:ncw,项目名称:iprime,代码行数:16,代码来源:mod_math_test.go

示例15: TestModPow

func TestModPow(t *testing.T) {
	A := new(big.Int)
	B := new(big.Int)
	C := new(big.Int)
	for _, a := range numbers {
		A.SetUint64(a)
		for _, b := range numbers {
			B.SetUint64(b)
			c := mod_pow(a, b)
			C.Exp(A, B, P)
			expected := C.Uint64()
			if c != expected {
				t.Errorf("0x%X ** 0x%X: Expecting 0x%X but got 0x%X", a, b, expected, c)
			}
		}
	}
}
开发者ID:ncw,项目名称:iprime,代码行数:17,代码来源:mod_math_test.go


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