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


Golang Int.Quo方法代码示例

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


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

示例1: sqrt

func sqrt(n *big.Int) *big.Int {
	a := new(big.Int)
	for b := new(big.Int).Set(n); ; {
		a.Set(b)
		b.Rsh(b.Add(b.Quo(n, a), a), 1)
		if b.Cmp(a) >= 0 {
			return a
		}
	}
	return a.SetInt64(0)
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:11,代码来源:multiplicative-order.go

示例2: mul

// mul multiplies the input amount by the input price
func mul(amount int64, pricen int64, priced int64) int64 {
	var r, n, d big.Int

	r.SetInt64(amount)
	n.SetInt64(pricen)
	d.SetInt64(priced)

	r.Mul(&r, &n)
	r.Quo(&r, &d)
	return r.Int64()
}
开发者ID:zenododobird,项目名称:horizon,代码行数:12,代码来源:order_book.go

示例3: Int64

// Int64 returns the numeric value of this literal truncated to fit
// a signed 64-bit integer.
//
func (l *Literal) Int64() int64 {
	switch x := l.Value.(type) {
	case int64:
		return x
	case *big.Int:
		return x.Int64()
	case *big.Rat:
		var q big.Int
		return q.Quo(x.Num(), x.Denom()).Int64() // truncate
	}
	panic(fmt.Sprintf("unexpected literal value: %T", l.Value))
}
开发者ID:serge-hulne,项目名称:golang,代码行数:15,代码来源:literal.go

示例4: Int64

// Int64 returns the numeric value of this literal truncated to fit
// a signed 64-bit integer.
//
func (l *Literal) Int64() int64 {
	switch x := l.Value.(type) {
	case int64:
		return x
	case *big.Int:
		return x.Int64()
	case *big.Rat:
		// TODO(adonovan): fix: is this the right rounding mode?
		var q big.Int
		return q.Quo(x.Num(), x.Denom()).Int64()
	}
	panic(fmt.Sprintf("unexpected literal value: %T", l.Value))
}
开发者ID:jmesmon,项目名称:gcc,代码行数:16,代码来源:literal.go

示例5: binaryIntOp

func binaryIntOp(x *big.Int, op token.Token, y *big.Int) interface{} {
	var z big.Int
	switch op {
	case token.ADD:
		return z.Add(x, y)
	case token.SUB:
		return z.Sub(x, y)
	case token.MUL:
		return z.Mul(x, y)
	case token.QUO:
		return z.Quo(x, y)
	case token.REM:
		return z.Rem(x, y)
	case token.AND:
		return z.And(x, y)
	case token.OR:
		return z.Or(x, y)
	case token.XOR:
		return z.Xor(x, y)
	case token.AND_NOT:
		return z.AndNot(x, y)
	case token.SHL:
		// The shift length must be uint, or untyped int and
		// convertible to uint.
		// TODO 32/64bit
		if y.BitLen() > 32 {
			panic("Excessive shift length")
		}
		return z.Lsh(x, uint(y.Int64()))
	case token.SHR:
		if y.BitLen() > 32 {
			panic("Excessive shift length")
		}
		return z.Rsh(x, uint(y.Int64()))
	case token.EQL:
		return x.Cmp(y) == 0
	case token.NEQ:
		return x.Cmp(y) != 0
	case token.LSS:
		return x.Cmp(y) < 0
	case token.LEQ:
		return x.Cmp(y) <= 0
	case token.GTR:
		return x.Cmp(y) > 0
	case token.GEQ:
		return x.Cmp(y) >= 0
	}
	panic("unreachable")
}
开发者ID:spate,项目名称:llgo,代码行数:49,代码来源:const.go

示例6: eExponent

// eExponent returns the exponent to use to display i in 1.23e+04 format.
func eExponent(x *big.Int) int {
	if x.Sign() < 0 {
		x.Neg(x)
	}
	e := 0
	for x.Cmp(bigIntBillion) >= 0 {
		e += 9
		x.Quo(x, bigIntBillion)
	}
	for x.Cmp(bigIntTen) >= 0 {
		e++
		x.Quo(x, bigIntTen)
	}
	return e
}
开发者ID:jmptrader,项目名称:ivy,代码行数:16,代码来源:bigint.go

示例7: moBachShallit58

func moBachShallit58(a, n *big.Int, pf []pExp) *big.Int {
	n1 := new(big.Int).Sub(n, one)
	var x, y, o1, g big.Int
	mo := big.NewInt(1)
	for _, pe := range pf {
		y.Quo(n1, y.Exp(pe.prime, big.NewInt(pe.exp), nil))
		var o int64
		for x.Exp(a, &y, n); x.Cmp(one) > 0; o++ {
			x.Exp(&x, pe.prime, n)
		}
		o1.Exp(pe.prime, o1.SetInt64(o), nil)
		mo.Mul(mo, o1.Quo(&o1, g.GCD(nil, nil, mo, &o1)))
	}
	return mo
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:15,代码来源:multiplicative-order.go

示例8: main

func main() {
	ln2, _ := new(big.Rat).SetString("0.6931471805599453094172")
	h := big.NewRat(1, 2)
	h.Quo(h, ln2)
	var f big.Rat
	var w big.Int
	for i := int64(1); i <= 17; i++ {
		h.Quo(h.Mul(h, f.SetInt64(i)), ln2)
		w.Quo(h.Num(), h.Denom())
		f.Sub(h, f.SetInt(&w))
		y, _ := f.Float64()
		d := fmt.Sprintf("%.3f", y)
		fmt.Printf("n: %2d  h: %18d%s  Nearly integer: %t\n",
			i, &w, d[1:], d[2] == '0' || d[2] == '9')
	}
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:16,代码来源:hickerson-series-of-almost-integers.go

示例9: Uint64

// Uint64 returns the numeric value of this literal truncated to fit
// an unsigned 64-bit integer.
//
func (l *Literal) Uint64() uint64 {
	switch x := l.Value.(type) {
	case int64:
		if x < 0 {
			return 0
		}
		return uint64(x)
	case *big.Int:
		return x.Uint64()
	case *big.Rat:
		// TODO(adonovan): fix: is this right?
		var q big.Int
		return q.Quo(x.Num(), x.Denom()).Uint64()
	}
	panic(fmt.Sprintf("unexpected literal value: %T", l.Value))
}
开发者ID:jmesmon,项目名称:gcc,代码行数:19,代码来源:literal.go

示例10: prime_divide

func prime_divide(n *big.Int) []*big.Int {
	r := make([]*big.Int, 0, 10)
	a := big.NewInt(2)

	for a.Cmp(n) == -1 || a.Cmp(n) == 0 {
		t := big.NewInt(0)
		t.Mod(n, a)

		if t.Cmp(big.NewInt(0)) == 0 {
			r = append(r, a)
			a = big.NewInt(a.Int64())
			n.Quo(n, a)
		} else {
			a.Add(a, big.NewInt(1))
		}
	}
	return r
}
开发者ID:murasesyuka,项目名称:misc-lang-snippet,代码行数:18,代码来源:03_Largest_prime_factor.go

示例11: rescale

// rescale returns a rescaled version of the decimal. Returned
// decimal may be less precise if the given exponent is bigger
// than the initial exponent of the Decimal.
// NOTE: this will truncate, NOT round
//
// Example:
//
// 	d := New(12345, -4)
//	d2 := d.rescale(-1)
//	d3 := d2.rescale(-4)
//	println(d1)
//	println(d2)
//	println(d3)
//
// Output:
//
//	1.2345
//	1.2
//	1.2000
//
func (d Decimal) rescale(exp int32) Decimal {
	d.ensureInitialized()
	// NOTE(vadim): must convert exps to float64 before - to prevent overflow
	diff := math.Abs(float64(exp) - float64(d.exp))
	value := new(big.Int).Set(d.value)

	expScale := new(big.Int).Exp(tenInt, big.NewInt(int64(diff)), nil)
	if exp > d.exp {
		value = value.Quo(value, expScale)
	} else if exp < d.exp {
		value = value.Mul(value, expScale)
	}

	return Decimal{
		value: value,
		exp:   exp,
	}
}
开发者ID:jperl,项目名称:decimal,代码行数:38,代码来源:decimal.go

示例12: binaryIntOp

func binaryIntOp(x *big.Int, op token.Token, y *big.Int) interface{} {
	var z big.Int
	switch op {
	case token.ADD:
		return z.Add(x, y)
	case token.SUB:
		return z.Sub(x, y)
	case token.MUL:
		return z.Mul(x, y)
	case token.QUO:
		return z.Quo(x, y)
	case token.REM:
		return z.Rem(x, y)
	case token.AND:
		return z.And(x, y)
	case token.OR:
		return z.Or(x, y)
	case token.XOR:
		return z.Xor(x, y)
	case token.AND_NOT:
		return z.AndNot(x, y)
	case token.SHL:
		panic("unimplemented")
	case token.SHR:
		panic("unimplemented")
	case token.EQL:
		return x.Cmp(y) == 0
	case token.NEQ:
		return x.Cmp(y) != 0
	case token.LSS:
		return x.Cmp(y) < 0
	case token.LEQ:
		return x.Cmp(y) <= 0
	case token.GTR:
		return x.Cmp(y) > 0
	case token.GEQ:
		return x.Cmp(y) >= 0
	}
	panic("unreachable")
}
开发者ID:anuvazhayil,项目名称:HelloWorld_32bitOS,代码行数:40,代码来源:const.go

示例13: bigRatToValue

// bigRatToValue converts 'number' to an SQL value with SQL type: valueType.
// If valueType is integral it truncates 'number' to the integer part according to the
// semantics of the big.Rat.Int method.
func bigRatToValue(number *big.Rat, valueType querypb.Type) sqltypes.Value {
	var numberAsBytes []byte
	switch {
	case sqltypes.IsIntegral(valueType):
		// 'number.Num()' returns a reference to the numerator of 'number'.
		// We copy it here to avoid changing 'number'.
		truncatedNumber := new(big.Int).Set(number.Num())
		truncatedNumber.Quo(truncatedNumber, number.Denom())
		numberAsBytes = bigIntToSliceOfBytes(truncatedNumber)
	case sqltypes.IsFloat(valueType):
		// Truncate to the closest 'float'.
		// There's not much we can do if there isn't an exact representation.
		numberAsFloat64, _ := number.Float64()
		numberAsBytes = strconv.AppendFloat([]byte{}, numberAsFloat64, 'f', -1, 64)
	default:
		panic(fmt.Sprintf("Unsupported type: %v", valueType))
	}
	result, err := sqltypes.ValueFromBytes(valueType, numberAsBytes)
	if err != nil {
		panic(fmt.Sprintf("sqltypes.ValueFromBytes failed with: %v", err))
	}
	return result
}
开发者ID:aaijazi,项目名称:vitess,代码行数:26,代码来源:equal_splits_algorithm.go

示例14: rescale

// rescale returns a rescaled version of the decimal. Returned
// decimal may be less precise if the given exponent is bigger
// than the initial exponent of the Decimal.
// NOTE: this will truncate, NOT round
//
// Example:
//
// 	d := New(12345, -4)
//	d2 := d.rescale(-1)
//	d3 := d2.rescale(-4)
//	println(d1)
//	println(d2)
//	println(d3)
//
// Output:
//
//	1.2345
//	1.2
//	1.2000
//
func (d Decimal) rescale(exp int32) Decimal {
	d.ensureInitialized()
	if exp < -MaxFractionDigits-1 {
		// Limit the number of digits but we can not call Round here because it is called by Round.
		// Limit it to MaxFractionDigits + 1 to make sure the final result is correct.
		exp = -MaxFractionDigits - 1
	}
	// Must convert exps to float64 before - to prevent overflow.
	diff := math.Abs(float64(exp) - float64(d.exp))
	value := new(big.Int).Set(d.value)

	expScale := new(big.Int).Exp(tenInt, big.NewInt(int64(diff)), nil)
	if exp > d.exp {
		value = value.Quo(value, expScale)
	} else if exp < d.exp {
		value = value.Mul(value, expScale)
	}
	return Decimal{
		value:      value,
		exp:        exp,
		fracDigits: d.fracDigits,
	}
}
开发者ID:ninefive,项目名称:tidb,代码行数:43,代码来源:decimal.go

示例15: _pollardFactoring

func _pollardFactoring(task *Task, toFactor *big.Int) []*big.Int {
	buffer := make([]*big.Int, 0)
	quo := new(big.Int)
	quo.Set(toFactor)

	//~ f := get_f(task.toFactor)

	for !quo.ProbablyPrime(prime_precision) { //quo.Cmp(big.NewInt(1)) > 0) {
		if task.ShouldStop() {
			return buffer
		}

		var factor *big.Int
		var error bool
		for i := 0; ; i++ {
			factor, error = pollardRho(task, quo, int64(i))

			if task.ShouldStop() {
				return buffer
			}
			if !error {
				break
			}
		}

		if !factor.ProbablyPrime(prime_precision) {
			sub := _pollardFactoring(task, factor)
			buffer = append(buffer, sub...)
		} else {
			buffer = append(buffer, factor)
		}

		quo.Quo(quo, factor)
	}
	return append(buffer, quo)
}
开发者ID:Tethik,项目名称:SeamlessIntegerFactorization,代码行数:36,代码来源:pollardrho.go


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