本文整理汇总了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.")
}
示例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.")
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)}
}
示例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))
}
示例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)
}