Changed comment on ScaledValue (#79738)

* Changed comment on ScaledValue and added additional test

* Added example to comment
This commit is contained in:
Josiah Bjorgaard 2019-08-08 10:03:32 -07:00 committed by Kubernetes Prow Robot
parent 5257266e9b
commit e861a8bf34
2 changed files with 4 additions and 1 deletions

View File

@ -697,7 +697,9 @@ func (q *Quantity) MilliValue() int64 {
return q.ScaledValue(Milli)
}
// ScaledValue returns the value of ceil(q * 10^scale); this could overflow an int64.
// ScaledValue returns the value of ceil(q / 10^scale).
// For example, NewQuantity(1, DecimalSI).ScaledValue(Milli) returns 1000.
// This could overflow an int64.
// To detect overflow, call Value() first and verify the expected magnitude.
func (q *Quantity) ScaledValue(scale Scale) int64 {
if q.d.Dec == nil {

View File

@ -1029,6 +1029,7 @@ func TestScaledValue(t *testing.T) {
{0, Micro, 1000 * 1000},
{0, Milli, 1000},
{0, 0, 1},
{2, -2, 100 * 100},
}
for _, item := range table {