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


Golang Rat.Add方法代码示例

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


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

示例1: Total

// Total computes the Usage.Total() of all the Usages of a Basket
func (b *Basket) Total() *big.Rat {
	total := new(big.Rat)
	for _, usage := range *b {
		total = total.Add(total, usage.Total())
	}
	return total
}
开发者ID:awesome-docker,项目名称:scaleway-cli,代码行数:8,代码来源:basket.go

示例2: EstimatePiFromPrevious

func EstimatePiFromPrevious(iteration, previousIndex int, sum *big.Rat) (*big.Rat, *big.Rat) {
	for i := previousIndex; i < iteration; i++ {
		sum.Add(sum, sn(i))
	}
	pi := getPiFromSum(sum)
	return pi, sum
}
开发者ID:bonnefoa,项目名称:gobot,代码行数:7,代码来源:metapi.go

示例3: quo

func quo(x, y *complexRat) *complexRat {
	z := newComplexRat()
	denominator := new(big.Rat)
	t := new(big.Rat)
	t.Mul(y.r, y.r)
	denominator.Mul(y.i, y.i)
	denominator.Add(denominator, t)

	if denominator.Cmp(zero) == 0 {
		return newComplexRat()
	}

	ac := new(big.Rat)
	bd := new(big.Rat)
	ac.Mul(x.r, y.r)
	bd.Mul(x.i, y.i)

	bc := new(big.Rat)
	ad := new(big.Rat)
	bc.Mul(x.i, y.r)
	ad.Mul(x.r, y.i)

	z.r.Add(ac, bd)
	z.r.Quo(z.r, denominator)

	z.i.Add(bc, ad.Neg(ad))
	z.i.Quo(z.i, denominator)

	return z
}
开发者ID:ysohta,项目名称:gopl-ex,代码行数:30,代码来源:complexrat.go

示例4: binaryFloatOp

func binaryFloatOp(x *big.Rat, op token.Token, y *big.Rat) interface{} {
	var z big.Rat
	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.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,代码行数:26,代码来源:const.go

示例5: PrintRegister

// Prints each transaction that matches the given filters.
func PrintRegister(generalLedger []*ledger.Transaction, filterArr []string, columns int) {
	runningBalance := new(big.Rat)
	for _, trans := range generalLedger {
		for _, accChange := range trans.AccountChanges {
			inFilter := len(filterArr) == 0
			for _, filter := range filterArr {
				if strings.Contains(accChange.Name, filter) {
					inFilter = true
				}
			}
			if inFilter {
				runningBalance.Add(runningBalance, accChange.Balance)
				writtenBytes, _ := fmt.Printf("%s %s", trans.Date.Format(ledger.TransactionDateFormat), trans.Payee)
				outBalanceString := accChange.Balance.FloatString(ledger.DisplayPrecision)
				outRunningBalanceString := runningBalance.FloatString(ledger.DisplayPrecision)
				spaceCount := columns - writtenBytes - 2 - len(outBalanceString) - len(outRunningBalanceString)
				if spaceCount < 0 {
					spaceCount = 0
				}
				fmt.Printf("%s%s %s", strings.Repeat(" ", spaceCount), outBalanceString, outRunningBalanceString)
				fmt.Println("")
			}
		}
	}
}
开发者ID:kalafut,项目名称:ledger,代码行数:26,代码来源:print.go

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

示例7: cumulFlows

func cumulFlows(flows []*types.Flow) (bals []*types.Amount) {
	x := new(big.Rat)
	for _, f := range flows {
		x = x.Add(x, (*big.Rat)(f.Price))
		bals = append(bals, new(types.Amount).SetRat(x))
	}
	return
}
开发者ID:remyoudompheng,项目名称:gocash,代码行数:8,代码来源:server.go

示例8: applyOp

func applyOp(val *big.Rat, op ast.OpClass, operand *big.Rat) {
	switch op {
	case ast.OpAdd:
		val.Add(val, operand)
	case ast.OpSubtract:
		val.Sub(val, operand)
	default:
		panic(fmt.Sprintf("eval.applyOp: unkown operand: %d (%s)", op, op))
	}
}
开发者ID:albrow,项目名称:calc,代码行数:10,代码来源:eval.go

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

示例10: runBilling

func runBilling(cmd *Command, rawArgs []string) error {
	if billingHelp {
		return cmd.PrintUsage()
	}
	if len(rawArgs) > 0 {
		return cmd.PrintShortUsage()
	}

	// cli parsing
	args := commands.PsArgs{
		NoTrunc: billingNoTrunc,
	}
	ctx := cmd.GetContext(rawArgs)

	logrus.Warn("")
	logrus.Warn("Warning: 'scw _billing' is a work-in-progress price estimation tool")
	logrus.Warn("For real usage, visit https://cloud.scaleway.com/#/billing")
	logrus.Warn("")

	// table
	w := tabwriter.NewWriter(ctx.Stdout, 20, 1, 3, ' ', 0)
	defer w.Flush()
	fmt.Fprintf(w, "ID\tNAME\tSTARTED\tMONTH PRICE\n")

	// servers
	servers, err := cmd.API.GetServers(true, 0)
	if err != nil {
		return err
	}

	totalMonthPrice := new(big.Rat)

	for _, server := range *servers {
		if server.State != "running" {
			continue
		}
		commercialType := strings.ToLower(server.CommercialType)
		shortID := utils.TruncIf(server.Identifier, 8, !args.NoTrunc)
		shortName := utils.TruncIf(utils.Wordify(server.Name), 25, !args.NoTrunc)
		modificationTime, _ := time.Parse("2006-01-02T15:04:05.000000+00:00", server.ModificationDate)
		modificationAgo := time.Now().UTC().Sub(modificationTime)
		shortModificationDate := units.HumanDuration(modificationAgo)
		usage := pricing.NewUsageByPath(fmt.Sprintf("/compute/%s/run", commercialType))
		usage.SetStartEnd(modificationTime, time.Now().UTC())

		totalMonthPrice = totalMonthPrice.Add(totalMonthPrice, usage.Total())

		fmt.Fprintf(w, "server/%s/%s\t%s\t%s\t%s\n", commercialType, shortID, shortName, shortModificationDate, usage.TotalString())
	}

	fmt.Fprintf(w, "TOTAL\t\t\t%s\n", pricing.PriceString(totalMonthPrice, "EUR"))

	return nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:54,代码来源:x_billing.go

示例11: Mul

func (z *BigComplex) Mul(x, y *BigComplex) *BigComplex {
	re := new(big.Rat).Mul(&x.Re, &y.Re)
	re.Sub(re, new(big.Rat).Mul(&x.Im, &y.Im))

	im := new(big.Rat).Mul(&x.Re, &y.Im)
	im.Add(im, new(big.Rat).Mul(&x.Im, &y.Re))

	z.Re = *re
	z.Im = *im
	return z
}
开发者ID:raff,项目名称:eval,代码行数:11,代码来源:bigcomplex.go

示例12: Dot

func (v1 Vector) Dot(v2 Vector) *big.Rat {
	if len(v1) != len(v2) {
		log.Fatalf("Lengths differ: %d != %d", len(v1), len(v2))
	}
	d := new(big.Rat)
	c := new(big.Rat)
	for i, e := range v1 {
		d.Add(d, c.Mul(e, v2[i]))
	}
	return d
}
开发者ID:hundt,项目名称:crypto-challenges,代码行数:11,代码来源:vector.go

示例13: Newt_Sqrt

func Newt_Sqrt(a *big.Rat, x *big.Rat) *big.Rat {
	for i := 0; i < 12; i++ {
		var quot1 = big.NewRat(1, 1)
		quot1 = quot1.Quo(x, big.NewRat(2, 1))
		var mul = big.NewRat(1, 1)
		mul = mul.Mul(big.NewRat(2, 1), x)
		var quot2 = big.NewRat(1, 1)
		quot2 = quot2.Quo(a, mul)
		x = x.Add(quot1, quot2)
	}
	return x
}
开发者ID:cko,项目名称:project-euler,代码行数:12,代码来源:80.go

示例14: abs

func abs(x *complexRat) *big.Rat {
	r := new(big.Rat)
	i := new(big.Rat)
	r.Set(x.r)
	i.Set(x.i)

	r.Mul(r, x.r) // r^2
	i.Mul(i, x.i) // i^2

	r.Add(r, i) // r^2 + i^2

	return sqrtFloat(r) // sqrt(r^2 + i^2)
}
开发者ID:ysohta,项目名称:gopl-ex,代码行数:13,代码来源:complexrat.go

示例15: sexToDec

func sexToDec(deg, min, sec *big.Rat, dir string) *big.Rat {
	// sexagesimal (base 60) to decimal
	// https://imm.dtf.wa.gov.au/helpfiles/Latitude_Longitude_conversion_hlp.htm

	deg.Add(deg, min.Quo(min, big.NewRat(60, 1)))
	deg.Add(deg, sec.Quo(sec, big.NewRat(3600, 1)))

	// N and E are the positive directions (like on an x,y axis)
	if dir == "S" || dir == "W" {
		deg.Neg(deg)
	}

	return deg
}
开发者ID:v64,项目名称:geophoto,代码行数:14,代码来源:geophoto.go


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