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


Golang Int.SetInt64方法代码示例

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


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

示例1: zForAffine

// zForAffine returns a Jacobian Z value for the affine point (x, y). If x and
// y are zero, it assumes that they represent the point at infinity because (0,
// 0) is not on the any of the curves handled here.
func zForAffine(x, y *big.Int) *big.Int {
	z := new(big.Int)
	if x.Sign() != 0 || y.Sign() != 0 {
		z.SetInt64(1)
	}
	return z
}
开发者ID:h8liu,项目名称:golang,代码行数:10,代码来源:elliptic.go

示例2: Mul

func (z *Polynomial) Mul(x, y *Polynomial) *Polynomial {
	var zCoeffs *big.Int
	if z == x || z == y {
		// Ensure that we do not modify z if it's a parameter.
		zCoeffs = new(big.Int)
	} else {
		zCoeffs = &z.coeffs
		zCoeffs.SetInt64(0)
	}

	small, large := x, y
	if y.degree < x.degree {
		small, large = y, x
	}

	// Walk through small coeffs, shift large by the corresponding amount,
	// and accumulate in z.
	coeffs := new(big.Int).Set(&small.coeffs)
	zero := new(big.Int)
	for coeffs.Cmp(zero) > 0 {
		deg := calcDegree(coeffs)
		factor := new(big.Int).Lsh(&large.coeffs, deg)
		zCoeffs.Xor(zCoeffs, factor)

		// Prepare for next iteration.
		coeffs.SetBit(coeffs, int(deg), 0)
	}

	z.degree = calcDegree(zCoeffs)
	z.coeffs = *zCoeffs
	return z
}
开发者ID:lumjjb,项目名称:rabin,代码行数:32,代码来源:polynomial.go

示例3: main

func main() {
	var s string
	var n, two, tmp big.Int
	two.SetInt64(2)

	in, _ := os.Open("10519.in")
	defer in.Close()
	out, _ := os.Create("10519.out")
	defer out.Close()

	for {
		if _, err := fmt.Fscanf(in, "%s", &s); err != nil {
			break
		}
		if s == "0" {
			fmt.Fprintln(out, 1)
			continue
		}
		n.SetString(s, 10)
		tmp.Mul(&n, &n)
		tmp.Sub(&tmp, &n)
		tmp.Add(&tmp, &two)
		fmt.Fprintln(out, &tmp)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:25,代码来源:10519.go

示例4: DecodeBase58

func DecodeBase58(ba []byte) []byte {
	if len(ba) == 0 {
		return nil
	}

	x := new(big.Int)
	y := big.NewInt(58)
	z := new(big.Int)
	for _, b := range ba {
		v := strings.IndexRune(base58, rune(b))
		z.SetInt64(int64(v))
		x.Mul(x, y)
		x.Add(x, z)
	}
	xa := x.Bytes()

	// Restore leading zeros
	i := 0
	for i < len(ba) && ba[i] == '1' {
		i++
	}
	ra := make([]byte, i+len(xa))
	copy(ra[i:], xa)
	return ra
}
开发者ID:psyvisions,项目名称:bitwrk,代码行数:25,代码来源:base58.go

示例5: Rat

// Rat returns the rational number representation of z.
// If x is non-nil, Rat stores the result in x instead of
// allocating a new Rat.
func (z *Decimal) Rat(x *big.Rat) *big.Rat {
	// TODO(eric):
	// We use big.Ints here when technically we could use our
	// int64 with big.Rat's SetInt64 methoz.
	// I'm not sure if it'll be an optimization or not.
	var num, denom big.Int
	if z.compact != overflown {
		c := big.NewInt(z.compact)
		if z.scale >= 0 {
			num.Set(c)
			denom.Set(mulBigPow10(oneInt, z.scale))
		} else {
			num.Set(mulBigPow10(c, -z.scale))
			denom.SetInt64(1)
		}
	} else {
		if z.scale >= 0 {
			num.Set(&z.mantissa)
			denom.Set(mulBigPow10(oneInt, z.scale))
		} else {
			num.Set(mulBigPow10(&z.mantissa, -z.scale))
			denom.SetInt64(1)
		}
	}
	if x != nil {
		return x.SetFrac(&num, &denom)
	}
	return new(big.Rat).SetFrac(&num, &denom)
}
开发者ID:patrickToca,项目名称:decimal,代码行数:32,代码来源:decimal.go

示例6: main

func main() {

	var iban string
	var r, s, t, st []string
	u := new(big.Int)
	v := new(big.Int)
	w := new(big.Int)

	iban = "GB82 TEST 1234 5698 7654 32"
	r = strings.Split(iban, " ")
	s = strings.Split(r[0], "")
	t = strings.Split(r[1], "")

	st = []string{strconv.Itoa(sCode[t[0]]),
		strconv.Itoa(sCode[t[1]]),
		strconv.Itoa(sCode[t[2]]),
		strconv.Itoa(sCode[t[3]]),
		strings.Join(r[2:6], ""),
		strconv.Itoa(sCode[s[0]]),
		strconv.Itoa(sCode[s[1]]),
		strings.Join(s[2:4], ""),
	}

	u.SetString(strings.Join(st, ""), 10)
	v.SetInt64(97)
	w.Mod(u, v)

	if w.Uint64() == 1 && lCode[strings.Join(s[0:2], "")] == len(strings.Join(r, "")) {
		fmt.Printf("IBAN %s looks good!\n", iban)
	} else {
		fmt.Printf("IBAN %s looks wrong!\n", iban)
	}
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:33,代码来源:iban.go

示例7: HideEncode

// HideEncode a Int such that it appears indistinguishable
// from a HideLen()-byte string chosen uniformly at random,
// assuming the Int contains a uniform integer modulo M.
// For a Int this always succeeds and returns non-nil.
func (i *Int) HideEncode(rand cipher.Stream) []byte {

	// Lengh of required encoding
	hidelen := i.HideLen()

	// Bit-position of the most-significant bit of the modular integer
	// in the most-significant byte of its encoding.
	highbit := uint((i.M.BitLen() - 1) & 7)

	var enc big.Int
	for {
		// Pick a random multiplier of a suitable bit-length.
		var b [1]byte
		rand.XORKeyStream(b[:], b[:])
		mult := int64(b[0] >> highbit)

		// Multiply, and see if we end up with
		// a Int of the proper byte-length.
		// Reroll if we get a result larger than HideLen(),
		// to ensure uniformity of the resulting encoding.
		enc.SetInt64(mult).Mul(&i.V, &enc)
		if enc.BitLen() <= hidelen*8 {
			break
		}
	}

	b := enc.Bytes() // may be shorter than l
	if ofs := hidelen - len(b); ofs != 0 {
		b = append(make([]byte, ofs), b...)
	}
	return b
}
开发者ID:Liamsi,项目名称:crypto,代码行数:36,代码来源:int.go

示例8: BigInt

// BigInt sets all bytes in the passed big int to zero and then sets the
// value to 0.  This differs from simply setting the value in that it
// specifically clears the underlying bytes whereas simply setting the value
// does not.  This is mostly useful to forcefully clear private keys.
func BigInt(x *big.Int) {
	b := x.Bits()
	for i := range b {
		b[i] = 0
	}
	x.SetInt64(0)
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:11,代码来源:slice.go

示例9: OddSwing

func (ps *Swing) OddSwing(z *big.Int, k uint) *big.Int {
	if k < uint(len(SmallOddSwing)) {
		return z.SetInt64(SmallOddSwing[k])
	}
	rootK := xmath.FloorSqrt(k)
	ps.factors = ps.factors[:0] // reset length, reusing existing capacity
	ps.Sieve.Iterate(3, uint64(rootK), func(p uint64) (terminate bool) {
		q := uint64(k) / p
		for q > 0 {
			if q&1 == 1 {
				ps.factors = append(ps.factors, p)
			}
			q /= p
		}
		return
	})
	ps.Sieve.Iterate(uint64(rootK+1), uint64(k/3), func(p uint64) (term bool) {
		if (uint64(k) / p & 1) == 1 {
			ps.factors = append(ps.factors, p)
		}
		return
	})
	ps.Sieve.Iterate(uint64(k/2+1), uint64(k), func(p uint64) (term bool) {
		ps.factors = append(ps.factors, p)
		return
	})
	return xmath.Product(z, ps.factors)
}
开发者ID:pombredanne,项目名称:integer,代码行数:28,代码来源:swing.go

示例10: EncodeBigInt

// EncodeBigInt returns the base62 encoding of an arbitrary precision integer
func (e *Encoding) EncodeBigInt(n *big.Int) string {
	var (
		b    = make([]byte, 0)
		rem  = new(big.Int)
		bse  = new(big.Int)
		zero = new(big.Int)
	)
	bse.SetInt64(base)
	zero.SetInt64(0)

	// Progressively divide by base, until we hit zero
	// store remainder each time
	// Prepend as an additional character is the higher power
	for n.Cmp(zero) == 1 {
		n, rem = n.DivMod(n, bse, rem)
		b = append([]byte{e.encode[rem.Int64()]}, b...)
	}

	s := string(b)
	if e.padding > 0 {
		s = e.pad(s, e.padding)
	}

	return s
}
开发者ID:jmptrader,项目名称:base62,代码行数:26,代码来源:base62.go

示例11: main

func main() {
	out, _ := os.Create("485.out")
	defer out.Close()

	for !done {
		var one big.Int
		one.SetInt64(1)
		p = append(p, one)
		l := len(p)

		fmt.Fprint(out, &p[l-1])
		for i := l - 2; i > 0; i-- {
			p[i].Add(&p[i], &p[i-1])
			fmt.Fprintf(out, " %v", &p[i])

			s = fmt.Sprint(&p[i])
			if len(s) > MAX {
				done = true
				break
			}
		}

		if !done && l > 1 {
			fmt.Fprintf(out, " %v", &p[0])
		}
		fmt.Fprintln(out)
	}
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:28,代码来源:485.go

示例12: Decode

// Decode decodes a modified base58 string to a byte slice.
func Decode(b string) []byte {
	answer := big.NewInt(0)
	j := big.NewInt(1)

	scratch := new(big.Int)
	for i := len(b) - 1; i >= 0; i-- {
		tmp := b58[b[i]]
		if tmp == 255 {
			return []byte("")
		}
		scratch.SetInt64(int64(tmp))
		scratch.Mul(j, scratch)
		answer.Add(answer, scratch)
		j.Mul(j, bigRadix)
	}

	tmpval := answer.Bytes()

	var numZeros int
	for numZeros = 0; numZeros < len(b); numZeros++ {
		if b[numZeros] != alphabetIdx0 {
			break
		}
	}
	flen := numZeros + len(tmpval)
	val := make([]byte, flen, flen)
	copy(val[numZeros:], tmpval)

	return val
}
开发者ID:CrowBits,项目名称:btcutil,代码行数:31,代码来源:base58.go

示例13: factorial

func factorial(n int) string {
	var res big.Int
	res.SetInt64(1)
	for i := 1; i <= n; i++ {
		res.Mul(&res, big.NewInt(int64(i)))
	}
	return res.String()
}
开发者ID:codingsince1985,项目名称:UVa,代码行数:8,代码来源:324.go

示例14: nonceRFC6979

// nonceRFC6979 is a local instatiation of deterministic nonce generation
// by the standards of RFC6979.
func nonceRFC6979(privkey []byte, hash []byte, extra []byte,
	version []byte) []byte {
	pkD := new(big.Int).SetBytes(privkey)
	defer pkD.SetInt64(0)
	bigK := secp256k1.NonceRFC6979(pkD, hash, extra, version)
	defer bigK.SetInt64(0)
	k := BigIntToEncodedBytes(bigK)
	return k[:]
}
开发者ID:alexlyp,项目名称:dcrd,代码行数:11,代码来源:threshold.go

示例15: main

func main() {
	n := new(big.Int).SetInt64(int64(1))
	t := new(big.Int)
	for i := int64(1); i <= 100; i++ {
		t.SetInt64(i)
		n.Mul(n, t)
	}
	fmt.Printf("Problem 20: %d\n", SumOfBigIntDigits(n))
}
开发者ID:uluyol,项目名称:misc,代码行数:9,代码来源:p020.go


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