當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Int.Int64方法代碼示例

本文整理匯總了Golang中math/big.Int.Int64方法的典型用法代碼示例。如果您正苦於以下問題:Golang Int.Int64方法的具體用法?Golang Int.Int64怎麽用?Golang Int.Int64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在math/big.Int的用法示例。


在下文中一共展示了Int.Int64方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UnmarshalJSON

func (n *Number) UnmarshalJSON(data []byte) error {
	input := strings.TrimSpace(string(data))

	if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
		input = input[1 : len(input)-1]
	}

	if len(input) == 0 {
		*n = Number(latestBlockNumber.Int64())
		return nil
	}

	in := new(big.Int)
	_, ok := in.SetString(input, 0)

	if !ok { // test if user supplied string tag
		return fmt.Errorf(`invalid number %s`, data)
	}

	if in.Cmp(earliestBlockNumber) >= 0 && in.Cmp(maxBlockNumber) <= 0 {
		*n = Number(in.Int64())
		return nil
	}

	return fmt.Errorf("blocknumber not in range [%d, %d]", earliestBlockNumber, maxBlockNumber)
}
開發者ID:efaysal,項目名稱:etherapis,代碼行數:26,代碼來源:types.go

示例2: Base58Encode

// Base58Encode encodes a byte slice to a modified base58 string.
func Base58Encode(b []byte, alphabet string) string {
	x := new(big.Int)
	x.SetBytes(b)

	answer := make([]byte, 0)
	for x.Cmp(bigZero) > 0 {
		mod := new(big.Int)
		x.DivMod(x, bigRadix, mod)
		answer = append(answer, alphabet[mod.Int64()])
	}

	// leading zero bytes
	for _, i := range b {
		if i != 0 {
			break
		}
		answer = append(answer, alphabet[0])
	}

	// reverse
	alen := len(answer)
	for i := 0; i < alen/2; i++ {
		answer[i], answer[alen-1-i] = answer[alen-1-i], answer[i]
	}

	return string(answer)
}
開發者ID:robcat,項目名稱:ripple,代碼行數:28,代碼來源:base58.go

示例3: Encode

// Encode encodes src into EncodedMaxLen(len(src))
// or fewer bytes of dst. It returns the number of bytes written to dst.
func Encode(dst, src []byte) int {
	zeros := 0
	for _, b := range src {
		if int(b) == 0 {
			zeros++
		} else {
			break
		}
	}
	i := new(big.Int).SetBytes(src)
	big58 := big.NewInt(58)
	big0 := big.NewInt(0)

	var index int
	for i.Cmp(big0) > 0 {
		tmp := new(big.Int).Mod(i, big58)
		i.Div(i, big58)
		dst[index] = base58alphabet[tmp.Int64()]
		index++
	}
	for ; zeros > 0; zeros-- {
		dst[index] = base58alphabet[0]
		index++
	}
	reverseInplace(dst[0:index])
	return index
}
開發者ID:runeaune,項目名稱:bitcoin-base58,代碼行數:29,代碼來源:base58.go

示例4: BigComma

// BigComma produces a string form of the given big.Int in base 10
// with commas after every three orders of magnitude.
func BigComma(b *big.Int) string {
	sign := ""
	if b.Sign() < 0 {
		sign = "-"
		b.Abs(b)
	}

	athousand := big.NewInt(1000)
	c := (&big.Int{}).Set(b)
	_, m := oom(c, athousand)
	parts := make([]string, m+1)
	j := len(parts) - 1

	mod := &big.Int{}
	for b.Cmp(athousand) >= 0 {
		b.DivMod(b, athousand, mod)
		parts[j] = strconv.FormatInt(mod.Int64(), 10)
		switch len(parts[j]) {
		case 2:
			parts[j] = "0" + parts[j]
		case 1:
			parts[j] = "00" + parts[j]
		}
		j--
	}
	parts[j] = strconv.Itoa(int(b.Int64()))
	return sign + strings.Join(parts[j:len(parts)], ",")
}
開發者ID:satyamkotakonda,項目名稱:rack,代碼行數:30,代碼來源:comma.go

示例5: rand

func rand(max *big.Int) int64 {
	i, err := urandom.Int(urandom.Reader, max)
	if err != nil {
		return prandom.Int63n(max.Int64())
	}
	return i.Int64()
}
開發者ID:qingshao,項目名稱:simpleuuid,代碼行數:7,代碼來源:uuid.go

示例6: EncodeBase58

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

	// Expected size increase from base58 conversion is approximately 137%, use 138% to be safe
	ri := len(ba) * 138 / 100
	ra := make([]byte, ri+1)

	x := new(big.Int).SetBytes(ba) // ba is big-endian
	x.Abs(x)
	y := big.NewInt(58)
	m := new(big.Int)

	for x.Sign() > 0 {
		x, m = x.DivMod(x, y, m)
		ra[ri] = base58[int32(m.Int64())]
		ri--
	}

	// Leading zeroes encoded as base58 zeros
	for i := 0; i < len(ba); i++ {
		if ba[i] != 0 {
			break
		}
		ra[ri] = '1'
		ri--
	}
	return ra[ri+1:]
}
開發者ID:psyvisions,項目名稱:bitwrk,代碼行數:30,代碼來源:base58.go

示例7: Validate

func Validate(user string, pass string) bool {
	sess := GetSession()
	defer sess.Close()
	authdb := sess.DB("prod").C("auth")

	var r *big.Int
	r, _ = rand.Int(rand.Reader, big.NewInt(5))
	time.Sleep(time.Duration(r.Int64()) * time.Nanosecond)

	var person S.User
	err := authdb.Find(bson.M{"user": user}).One(&person)
	if err != nil {
		fmt.Println(err)
	} else {
		hasher := sha256.New()
		hasher.Write([]byte(pass + string(person.Salt)))
		hashed := base64.URLEncoding.EncodeToString(hasher.Sum(nil))

		if hashed == person.Pass {
			return true
		}
	}

	return false
}
開發者ID:daycationapp,項目名稱:infrastructure,代碼行數:25,代碼來源:data.go

示例8: Resolver

func (self *EthReg) Resolver(n *big.Int) *registrar.Registrar {
	xe := self.backend
	if n != nil {
		xe = self.backend.AtStateNum(n.Int64())
	}
	return registrar.New(xe)
}
開發者ID:ruflin,項目名稱:go-ethereum,代碼行數:7,代碼來源:ethreg.go

示例9: setBignum

func setBignum(rv reflect.Value, x *big.Int) error {
	switch rv.Kind() {
	case reflect.Ptr:
		return setBignum(reflect.Indirect(rv), x)
	case reflect.Interface:
		rv.Set(reflect.ValueOf(*x))
		return nil
	case reflect.Int32:
		if x.BitLen() < 32 {
			rv.SetInt(x.Int64())
			return nil
		} else {
			return fmt.Errorf("int too big for int32 target")
		}
	case reflect.Int, reflect.Int64:
		if x.BitLen() < 64 {
			rv.SetInt(x.Int64())
			return nil
		} else {
			return fmt.Errorf("int too big for int64 target")
		}
	default:
		return fmt.Errorf("cannot assign bignum into Kind=%s Type=%s %#v", rv.Kind().String(), rv.Type().String(), rv)
	}
}
開發者ID:jbenet,項目名稱:go-cbor-incomplete,代碼行數:25,代碼來源:cbor.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: GetInstr

func (c *StateObject) GetInstr(pc *big.Int) *common.Value {
	if int64(len(c.code)-1) < pc.Int64() {
		return common.NewValue(0)
	}

	return common.NewValueFromBytes([]byte{c.code[pc.Int64()]})
}
開發者ID:ssonneborn22,項目名稱:go-ethereum,代碼行數:7,代碼來源:state_object.go

示例12: main

func main() {
	lim := 1000
	primes := allPrimes(lim)
	mx_cyc := 0
	mx_len := 0

	for _, i := range primes {
		j := 1
		for j < i {
			p := new(big.Int)
			*p = bigPow(10, j)
			res := new(big.Int)
			res.Mod(p, big.NewInt(int64(i)))
			if res.Int64() == 1 {
				if mx_len < j {
					mx_len = i
					mx_cyc = j
				}
				break
			}
			j++
		}
	}
	fmt.Printf("Found: 1/%d yields %d cycles\n", mx_len, mx_cyc)
}
開發者ID:hermansc,項目名稱:golang-euler,代碼行數:25,代碼來源:pb26.go

示例13: UnmarshalJSON

func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
	var obj []struct {
		Payload  string
		To       string
		From     string
		Topics   []string
		Priority interface{}
		Ttl      interface{}
	}

	if err = json.Unmarshal(b, &obj); err != nil {
		return shared.NewDecodeParamError(err.Error())
	}

	if len(obj) < 1 {
		return shared.NewInsufficientParamsError(len(obj), 1)
	}
	args.Payload = obj[0].Payload
	args.To = obj[0].To
	args.From = obj[0].From
	args.Topics = obj[0].Topics

	var num *big.Int
	if num, err = numString(obj[0].Priority); err != nil {
		return err
	}
	args.Priority = uint32(num.Int64())

	if num, err = numString(obj[0].Ttl); err != nil {
		return err
	}
	args.Ttl = uint32(num.Int64())

	return nil
}
開發者ID:ssonneborn22,項目名稱:go-ethereum,代碼行數:35,代碼來源:shh_args.go

示例14: bigRsh

func bigRsh(z, x, y *big.Int) *big.Int {
	i := y.Int64()
	if i < 0 {
		panic("negative shift")
	}
	return z.Rsh(x, uint(i))
}
開發者ID:juanman2,項目名稱:dot-emacs,代碼行數:7,代碼來源:ops.go

示例15: GetInstr

func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
	if int64(len(c.Code)-1) < pc.Int64() {
		return ethutil.NewValue(0)
	}

	return ethutil.NewValueFromBytes([]byte{c.Code[pc.Int64()]})
}
開發者ID:vmatekole,項目名稱:eth-go,代碼行數:7,代碼來源:state_object.go


注:本文中的math/big.Int.Int64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。