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


Golang Rat.SetInt64方法代码示例

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


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

示例1: PutInt64

func (me *StatisticalAccumulator) PutInt64(x int64) {

	xx := new(big.Rat)
	xx.SetInt64(x)

	me.PutRat(xx)
}
开发者ID:reiver,项目名称:go-statisticalaccumulator,代码行数:7,代码来源:statisticalaccumulator_put.go

示例2: String

func String(v xdr.Int64) string {
	var f, o, r big.Rat

	f.SetInt64(int64(v))
	o.SetInt64(One)
	r.Quo(&f, &o)

	return r.FloatString(7)
}
开发者ID:zenododobird,项目名称:horizon,代码行数:9,代码来源:main.go

示例3: b

func b(n int) *big.Rat {
	var f big.Rat
	a := make([]big.Rat, n+1)
	for m := range a {
		a[m].SetFrac64(1, int64(m+1))
		for j := m; j >= 1; j-- {
			d := &a[j-1]
			d.Mul(f.SetInt64(int64(j)), d.Sub(d, &a[j]))
		}
	}
	return f.Set(&a[0])
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:12,代码来源:bernoulli-numbers.go

示例4: ToString

func (l *Ledger) ToString() string {
	balance := make(map[string]*big.Rat)

	for _, t := range l.Transactions {
		err := t.CheckBalance()
		check(err)

		for _, a := range t.Accounts {
			if b, ok := balance[a.Name]; ok {
				if a.Debit {
					b.Add(b, a.Amount)
				} else {
					b.Sub(b, a.Amount)
				}
			} else {
				if a.Debit {
					balance[a.Name] = a.Amount
				} else {
					neg := new(big.Rat)
					neg.SetInt64(-1)
					balance[a.Name] = a.Amount.Mul(a.Amount, neg)
				}
			}
		}
	}

	keys := make([]string, len(balance))
	i := 0
	for k := range balance {
		keys[i] = k
		i++
	}
	sort.Strings(keys)

	padLength := 20
	for _, key := range keys {
		if len(key) > padLength {
			padLength = len(key) + 2
		}
	}

	boom := ""
	for _, key := range keys {
		extra := ""
		if balance[key].Sign() == 1 {
			extra = "+"
		}
		boom += fmt.Sprintf("%s%s%s\n", padRight(key, " ", padLength), extra, balance[key].FloatString(2))
	}
	return boom
}
开发者ID:revolvingcow,项目名称:cash,代码行数:51,代码来源:ledger.go

示例5: mandelbrotRat

func mandelbrotRat(a, b *big.Rat) color.Color {
	var x, y, nx, ny, x2, y2, f2, f4, r2, tmp big.Rat
	f2.SetInt64(2)
	f4.SetInt64(4)
	x.SetInt64(0)
	y.SetInt64(0)

	defer func() { recover() }()

	for n := uint8(0); n < iterations; n++ {
		// Not update x2 and y2
		// because they are already updated in the previous loop
		nx.Sub(&x2, &y2)
		nx.Add(&nx, a)

		tmp.Mul(&x, &y)
		ny.Mul(&f2, &tmp)
		ny.Add(&ny, b)

		x.Set(&nx)
		y.Set(&ny)

		x2.Mul(&x, &x)
		y2.Mul(&y, &y)
		r2.Add(&x2, &y2)

		if r2.Cmp(&f4) > 0 {
			return color.Gray{255 - contrast*n}
		}
	}
	return color.Black
}
开发者ID:seikichi,项目名称:gopl,代码行数:32,代码来源:main.go

示例6: 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

示例7: TestIssue35

func TestIssue35(t *testing.T) {
	var bigInt big.Int
	var bigRat big.Rat
	bigInt.SetInt64(42)
	bigRat.SetInt64(24)
	db, err := OpenMem()
	if err != nil {
		t.Fatal(err)
	}

	ctx := NewRWCtx()
	_, _, err = db.Run(ctx, `
	BEGIN TRANSACTION;
		CREATE TABLE t (i bigint, r bigrat);
		INSERT INTO t VALUES ($1, $2);
	COMMIT;
	`, bigInt, bigRat)
	if err != nil {
		t.Fatal(err)
	}

	bigInt.SetInt64(420)
	bigRat.SetInt64(240)

	rs, _, err := db.Run(nil, "SELECT * FROM t;")
	if err != nil {
		t.Fatal(err)
	}

	n := 0
	if err := rs[0].Do(false, func(rec []interface{}) (bool, error) {
		switch n {
		case 0:
			n++
			if g, e := fmt.Sprint(rec), "[42 24/1]"; g != e {
				t.Fatal(g, e)
			}

			return true, nil
		default:
			t.Fatal(n)
			panic("unreachable")
		}
	}); err != nil {
		t.Fatal(err)
	}
}
开发者ID:pkf,项目名称:ql,代码行数:47,代码来源:all_test.go

示例8: Parse

func Parse(v string) (xdr.Int64, error) {
	var f, o, r big.Rat

	_, ok := f.SetString(v)
	if !ok {
		return xdr.Int64(0), fmt.Errorf("cannot parse amount: %s", v)
	}

	o.SetInt64(One)
	r.Mul(&f, &o)

	is := r.FloatString(0)
	i, err := strconv.ParseInt(is, 10, 64)
	if err != nil {
		return xdr.Int64(0), err
	}
	return xdr.Int64(i), nil
}
开发者ID:zenododobird,项目名称:horizon,代码行数:18,代码来源:main.go

示例9: recur

// Use the classic continued fraction for e
//     e = [1; 0, 1, 1, 2, 1, 1, ... 2n, 1, 1, ...]
// i.e., for the nth term, use
//     1          if   n mod 3 != 1
//  (n-1)/3 * 2   if   n mod 3 == 1
func recur(n, lim int64) *big.Rat {
	term := new(big.Rat)
	if n%3 != 1 {
		term.SetInt64(1)
	} else {
		term.SetInt64((n - 1) / 3 * 2)
	}

	if n > lim {
		return term
	}

	// Directly initialize frac as the fractional
	// inverse of the result of recur.
	frac := new(big.Rat).Inv(recur(n+1, lim))

	return term.Add(term, frac)
}
开发者ID:Greentor,项目名称:go,代码行数:23,代码来源:example_rat_test.go

示例10: New

func New() *StatisticalAccumulator {

	n := new(big.Rat)
	n.SetInt64(0)

	sigmaXI := new(big.Rat)
	sigmaXI.SetInt64(0)

	sigmaXISquared := new(big.Rat)
	sigmaXISquared.SetInt64(0)

	one := new(big.Rat)
	one.SetInt64(1)

	me := StatisticalAccumulator{
		n:              n,
		sigmaXI:        sigmaXI,
		sigmaXISquared: sigmaXISquared,
		one:            one,
	}

	return &me
}
开发者ID:reiver,项目名称:go-statisticalaccumulator,代码行数:23,代码来源:statisticalaccumulator.go

示例11: IntToRat

func IntToRat(v int64) *big.Rat {
	rat := new(big.Rat)
	rat.SetInt64(v)
	return rat
}
开发者ID:JamesDunne,项目名称:StockWatcher,代码行数:5,代码来源:util.go

示例12: renderRat

func renderRat(img *image.RGBA) {
	var yminR, ymaxMinR, heightR big.Rat
	yminR.SetInt64(ymin)
	ymaxMinR.SetInt64(ymax - ymin)
	heightR.SetInt64(height)

	var xminR, xmaxMinR, widthR big.Rat
	xminR.SetInt64(xmin)
	xmaxMinR.SetInt64(xmax - xmin)
	widthR.SetInt64(width)

	var y, x big.Rat
	for py := int64(0); py < height; py++ {
		// y := float64(py)/height*(ymax-ymin) + ymin
		y.SetInt64(py)
		y.Quo(&y, &heightR)
		y.Mul(&y, &ymaxMinR)
		y.Add(&y, &yminR)

		for px := int64(0); px < width; px++ {
			// x := float64(px)/width*(xmax-xmin) + xmin
			x.SetInt64(px)
			x.Quo(&x, &widthR)
			x.Mul(&x, &xmaxMinR)
			x.Add(&x, &xminR)

			c := mandelbrotRat(&x, &y)
			if c == nil {
				c = color.Black
			}
			img.Set(int(px), int(py), c)
		}
	}
}
开发者ID:seikichi,项目名称:gopl,代码行数:34,代码来源:main.go


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