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


Golang Int.Append方法代碼示例

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


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

示例1: trailingZeros

// trailingZeros counts the number of trailing zeros in the
// big.Int value. It first attempts to use an unsigned integer
// representation of the big.Int to compute this because it is
// roughly 8x faster. If this unsigned integer would overflow,
// it falls back to formatting the big.Int itself.
func trailingZeros(bi *big.Int, tmp []byte) int {
	if bi.BitLen() <= 64 {
		i := bi.Uint64()
		bs := strconv.AppendUint(tmp, i, 10)
		return trailingZerosFromBytes(bs)
	}
	bs := bi.Append(tmp, 10)
	return trailingZerosFromBytes(bs)
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:14,代碼來源:decimal.go

示例2: main

func main() {
	factorial := new(big.Int).MulRange(1, 100)
	bytes := factorial.Append([]byte{}, 10)
	sum := 0
	for b := range bytes {
		sum += int(bytes[b] - '0')
	}
	fmt.Println("sum:", sum)
}
開發者ID:Zebbeni,項目名稱:Euler,代碼行數:9,代碼來源:main.go

示例3: numDigits

// numDigits returns the number of decimal digits that make up
// big.Int value. The function first attempts to look this digit
// count up in the digitsLookupTable. If the value is not there,
// it defaults to constructing a string value for the big.Int and
// using this to determine the number of digits. If a string value
// is constructed, it will be returned so it can be used again.
func numDigits(bi *big.Int, tmp []byte) (int, []byte) {
	if val, ok := lookupBits(bi.BitLen()); ok {
		if bi.Cmp(&val.border) < 0 {
			return val.digits, nil
		}
		return val.digits + 1, nil
	}
	bs := bi.Append(tmp, 10)
	return len(bs), bs
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:16,代碼來源:decimal.go


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