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


Golang Rat.Denom方法代碼示例

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


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

示例1: hostconfigcmd

// hostconfigcmd is the handler for the command `siac host config [setting] [value]`.
// Modifies host settings.
func hostconfigcmd(param, value string) {
	switch param {
	case "price":
		// convert price to hastings/byte/block
		p, ok := new(big.Rat).SetString(value)
		if !ok {
			die("Could not parse price")
		}
		p.Mul(p, big.NewRat(1e24/1e9, 4320))
		value = new(big.Int).Div(p.Num(), p.Denom()).String()
	case "totalstorage":
		// parse sizes of form 10GB, 10TB, 1TiB etc
		var err error
		value, err = parseSize(value)
		if err != nil {
			die("Could not parse totalstorage:", err)
		}
	case "minduration", "maxduration", "windowsize", "acceptingcontracts": // Other valid settings.
	default:
		// Reject invalid host config commands.
		die("\"" + param + "\" is not a host setting")
	}
	err := post("/host", param+"="+value)
	if err != nil {
		die("Could not update host settings:", err)
	}
	fmt.Println("Host settings updated.")
}
開發者ID:zzmjohn,項目名稱:Sia,代碼行數:30,代碼來源:hostcmd.go

示例2: hostconfigcmd

func hostconfigcmd(param, value string) {
	// convert price to hastings/byte/block
	if param == "price" {
		p, ok := new(big.Rat).SetString(value)
		if !ok {
			fmt.Println("could not parse price")
			return
		}
		p.Mul(p, big.NewRat(1e24/1e9, 4320))
		value = new(big.Int).Div(p.Num(), p.Denom()).String()
	}
	// parse sizes of form 10GB, 10TB, 1TiB etc
	if param == "totalstorage" {
		var err error
		value, err = parseSize(value)
		if err != nil {
			fmt.Println("could not parse " + param)
		}
	}
	err := post("/host", param+"="+value)
	if err != nil {
		fmt.Println("Could not update host settings:", err)
		return
	}
	fmt.Println("Host settings updated.")
}
開發者ID:cfromknecht,項目名稱:Sia,代碼行數:26,代碼來源:hostcmd.go

示例3: floor

func floor(n *big.Rat) *big.Rat {
	f := &big.Rat{}
	z := new(big.Int)
	z.Div(n.Num(), n.Denom())
	f.SetInt(z)
	return f
}
開發者ID:stellar,項目名稱:bridge-server,代碼行數:7,代碼來源:main.go

示例4: MulRat

// MulRat returns a new Currency value c = x * y, where y is a big.Rat.
func (x Currency) MulRat(y *big.Rat) (c Currency) {
	if y.Sign() < 0 {
		build.Critical(ErrNegativeCurrency)
	} else {
		c.i.Mul(&x.i, y.Num())
		c.i.Div(&c.i, y.Denom())
	}
	return
}
開發者ID:zzmjohn,項目名稱:Sia,代碼行數:10,代碼來源:currency.go

示例5: ratCeil

// Returns a new big.Int set to the ceiling of x.
func ratCeil(x *big.Rat) *big.Int {
	z := new(big.Int)
	m := new(big.Int)
	z.DivMod(x.Num(), x.Denom(), m)
	if m.Cmp(intZero) == 1 {
		z.Add(z, intOne)
	}
	return z
}
開發者ID:awesome-docker,項目名稱:scaleway-cli,代碼行數:10,代碼來源:utils.go

示例6: CalcGasLimit

func CalcGasLimit(parent *types.Block) *big.Int {
	// ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
	previous := new(big.Int).Mul(big.NewInt(1024-1), parent.GasLimit())
	current := new(big.Rat).Mul(new(big.Rat).SetInt(parent.GasUsed()), big.NewRat(6, 5))
	curInt := new(big.Int).Div(current.Num(), current.Denom())

	result := new(big.Int).Add(previous, curInt)
	result.Div(result, big.NewInt(1024))
	return common.BigMax(params.GenesisGasLimit, result)
}
開發者ID:hiroshi1tanaka,項目名稱:gethkey,代碼行數:10,代碼來源:chain_manager.go

示例7: Round

func Round(r *big.Rat) *big.Rat {
	d := new(big.Int).Set(r.Denom())
	n := new(big.Int).Set(r.Num())
	n.Mod(n, d)
	if new(big.Int).Mul(n, big.NewInt(2)).Cmp(d) >= 0 {
		r.Add(r, new(big.Rat).SetInt64(1))
	}
	r.Sub(r, new(big.Rat).SetFrac(n, d))
	return r
}
開發者ID:hundt,項目名稱:crypto-challenges,代碼行數:10,代碼來源:vector.go

示例8: RatToTarget

// RatToTarget converts a big.Rat to a Target.
func RatToTarget(r *big.Rat) (t Target) {
	if r.Num().Sign() < 0 {
		if build.DEBUG {
			panic(ErrNegativeTarget)
		}
	} else {
		i := new(big.Int).Div(r.Num(), r.Denom())
		t = IntToTarget(i)
	}
	return
}
開發者ID:CSSZiegler,項目名稱:Sia,代碼行數:12,代碼來源:target.go

示例9: Scale

func (sqe scaleQuoExact) Scale(x, y *Dec) Scale {
	rem := new(big.Rat).SetFrac(x.UnscaledBig(), y.UnscaledBig())
	f2, f5 := factor2(rem.Denom()), factor(rem.Denom(), bigInt[5])
	var f10 Scale
	if f2 > f5 {
		f10 = Scale(f2)
	} else {
		f10 = Scale(f5)
	}
	return x.Scale() - y.Scale() + f10
}
開發者ID:40a,項目名稱:bootkube,代碼行數:11,代碼來源:dec.go

示例10: MulRat

// MulRat returns a new Currency value c = x * y, where y is a big.Rat.
func (x Currency) MulRat(y *big.Rat) (c Currency) {
	if y.Sign() < 0 {
		if build.DEBUG {
			panic(ErrNegativeCurrency)
		}
	} else {
		c.i.Mul(&x.i, y.Num())
		c.i.Div(&c.i, y.Denom())
	}
	return
}
開發者ID:kustomzone,項目名稱:Sia,代碼行數:12,代碼來源:currency.go

示例11: isSolution

// Do the numerator and denominator of r provide a solution to the equation
// x**2 - D*(y**2) = 1?
func isSolution(D int, r *big.Rat) bool {
	S := big.NewInt(int64(D))
	x := r.Num()
	y := r.Denom()

	one := big.NewInt(1)
	two := big.NewInt(2)

	a := new(big.Int).Exp(x, two, nil)
	b := new(big.Int).Exp(y, two, nil)
	return new(big.Int).Sub(a, new(big.Int).Mul(S, b)).Cmp(one) == 0
}
開發者ID:mjwestcott,項目名稱:projecteuler,代碼行數:14,代碼來源:problem66.go

示例12: MulFloat

// COMPATv0.4.0 - until the first 10e3 blocks have been archived, MulFloat is
// needed while verifying the first set of blocks.
//
// MulFloat returns a new Currency value y = c * x, where x is a float64.
// Behavior is undefined when x is negative.
func (x Currency) MulFloat(y float64) (c Currency) {
	if y < 0 {
		build.Critical(ErrNegativeCurrency)
	} else {
		cRat := new(big.Rat).Mul(
			new(big.Rat).SetInt(&x.i),
			new(big.Rat).SetFloat64(y),
		)
		c.i.Div(cRat.Num(), cRat.Denom())
	}
	return
}
開發者ID:zzmjohn,項目名稱:Sia,代碼行數:17,代碼來源:currency.go

示例13: makeRat

func makeRat(x *big.Rat) Value {
	a := x.Num()
	b := x.Denom()
	if a.BitLen() < maxExp && b.BitLen() < maxExp {
		// ok to remain fraction
		return ratVal{x}
	}
	// components too large => switch to float
	fa := newFloat().SetInt(a)
	fb := newFloat().SetInt(b)
	return floatVal{fa.Quo(fa, fb)}
}
開發者ID:2thetop,項目名稱:go,代碼行數:12,代碼來源:value.go

示例14: toInt

func (v value) toInt() *big.Int {
	switch v := v.v.(type) {
	case *big.Int:
		return v
	case *big.Rat:
		// TODO rounding?
		return new(big.Int).Quo(v.Num(), v.Denom())
	case float64:
		r := new(big.Rat).SetFloat64(v)
		if r == nil {
			fatalf("cannot convert %v to float64", v)
		}
		// TODO rounding?
		return new(big.Int).Quo(r.Num(), r.Denom())
	}
	panic(fmt.Errorf("unexpected type %T", v.v))
}
開發者ID:zxpbenson,項目名稱:rog-go,代碼行數:17,代碼來源:calc.go

示例15: CalcGasLimit

func (block *Block) CalcGasLimit(parent *Block) *big.Int {
	if block.Number.Cmp(big.NewInt(0)) == 0 {
		return ethutil.BigPow(10, 6)
	}

	// ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024

	previous := new(big.Int).Mul(big.NewInt(1024-1), parent.GasLimit)
	current := new(big.Rat).Mul(new(big.Rat).SetInt(parent.GasUsed), big.NewRat(6, 5))
	curInt := new(big.Int).Div(current.Num(), current.Denom())

	result := new(big.Int).Add(previous, curInt)
	result.Div(result, big.NewInt(1024))

	min := big.NewInt(125000)

	return ethutil.BigMax(min, result)
}
開發者ID:vmatekole,項目名稱:eth-go,代碼行數:18,代碼來源:block.go


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