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


Golang v0.Scale函数代码示例

本文整理汇总了Golang中gopkg/in/inf/v0.Scale函数的典型用法代码示例。如果您正苦于以下问题:Golang Scale函数的具体用法?Golang Scale怎么用?Golang Scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: Unmarshal

// Reset implements the protobuf marshalling interface.
func (q *Quantity) Unmarshal(data []byte) error {
	p := QuantityProto{}
	if err := p.Unmarshal(data); err != nil {
		return err
	}
	q.Format = p.Format
	b := big.NewInt(0)
	b.SetBytes(p.Bigint)
	q.Amount = inf.NewDecBig(b, inf.Scale(p.Scale))
	return nil
}
开发者ID:caesarxuchao,项目名称:heapster,代码行数:12,代码来源:quantity_proto.go

示例2: infScale

// infScale adapts a Scale value to an inf.Scale value.
func (s Scale) infScale() inf.Scale {
	return inf.Scale(-s) // inf.Scale is upside-down
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:4,代码来源:amount.go

示例3: AsDec

// AsDec returns an inf.Dec representation of this value.
func (a int64Amount) AsDec() *inf.Dec {
	var base inf.Dec
	base.SetUnscaled(a.value)
	base.SetScale(inf.Scale(-a.scale))
	return &base
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:7,代码来源:amount.go

示例4: dec

func dec(i int64, exponent int) *inf.Dec {
	// See the below test-- scale is the negative of an exponent.
	return inf.NewDec(i, inf.Scale(-exponent))
}
开发者ID:odacremolbap,项目名称:kubernetes,代码行数:4,代码来源:quantity_test.go

示例5: TestJSON

				q.Amount.SetScale(0)
				q.Amount.SetUnscaled(c.Int63())
				return
			}
			// Be sure to test cases like 1Mi
			q.Amount.SetScale(0)
			q.Amount.SetUnscaled(c.Int63n(1024) << uint(10*c.Intn(5)))
			return
		}
		if c.RandBool() {
			q.Format = DecimalSI
		} else {
			q.Format = DecimalExponent
		}
		if c.RandBool() {
			q.Amount.SetScale(inf.Scale(c.Intn(4)))
			q.Amount.SetUnscaled(c.Int63())
			return
		}
		// Be sure to test cases like 1M
		q.Amount.SetScale(inf.Scale(3 - c.Intn(15)))
		q.Amount.SetUnscaled(c.Int63n(1000))
	},
)

func TestJSON(t *testing.T) {
	for i := 0; i < 500; i++ {
		q := &Quantity{}
		fuzzer.Fuzz(q)
		b, err := json.Marshal(q)
		if err != nil {
开发者ID:odacremolbap,项目名称:kubernetes,代码行数:31,代码来源:quantity_test.go

示例6: amount

func amount(i int64, exponent int) infDecAmount {
	// See the below test-- scale is the negative of an exponent.
	return infDecAmount{inf.NewDec(i, inf.Scale(-exponent))}
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:4,代码来源:quantity_test.go

示例7: TestJSON

			// Be sure to test cases like 1Mi
			dec := &inf.Dec{}
			q.d = infDecAmount{Dec: dec}
			dec.SetScale(0)
			dec.SetUnscaled(c.Int63n(1024) << uint(10*c.Intn(5)))
			return
		}
		if c.RandBool() {
			q.Format = DecimalSI
		} else {
			q.Format = DecimalExponent
		}
		if c.RandBool() {
			dec := &inf.Dec{}
			q.d = infDecAmount{Dec: dec}
			dec.SetScale(inf.Scale(c.Intn(4)))
			dec.SetUnscaled(c.Int63())
			return
		}
		// Be sure to test cases like 1M
		dec := &inf.Dec{}
		q.d = infDecAmount{Dec: dec}
		dec.SetScale(inf.Scale(3 - c.Intn(15)))
		dec.SetUnscaled(c.Int63n(1000))
	},
)

func TestJSON(t *testing.T) {
	for i := 0; i < 500; i++ {
		q := &Quantity{}
		fuzzer.Fuzz(q)
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:31,代码来源:quantity_test.go

示例8: CmpInt64

// CmpInt64 returns 0 if the quantity is equal to y, -1 if the quantity is less than y, or 1 if the
// quantity is greater than y.
func (q *Quantity) CmpInt64(y int64) int {
	if q.d.Dec != nil {
		return q.d.Dec.Cmp(inf.NewDec(y, inf.Scale(0)))
	}
	return q.i.Cmp(int64Amount{value: y})
}
开发者ID:humblec,项目名称:kubernetes,代码行数:8,代码来源:quantity.go


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