MCPcopy Create free account
hub / github.com/cockroachdb/apd / ShouldAddOne

Method ShouldAddOne

round.go:36–59  ·  view source on GitHub ↗

ShouldAddOne returns true if 1 should be added to the absolute value of a number being rounded. result is the result to which the 1 would be added. neg is true if the number is negative. half is -1 if the discarded digits are < 0.5, 0 if = 0.5, or 1 if > 0.5.

(result *BigInt, neg bool, half int)

Source from the content-addressed store, hash-verified

34// be added. neg is true if the number is negative. half is -1 if the
35// discarded digits are < 0.5, 0 if = 0.5, or 1 if > 0.5.
36func (r Rounder) ShouldAddOne(result *BigInt, neg bool, half int) bool {
37 // NOTE: this is written using a switch statement instead of some
38 // other form of dynamic dispatch to assist Go's escape analysis.
39 switch r {
40 case RoundDown:
41 return roundDown(result, neg, half)
42 case RoundHalfUp:
43 return roundHalfUp(result, neg, half)
44 case RoundHalfEven:
45 return roundHalfEven(result, neg, half)
46 case RoundCeiling:
47 return roundCeiling(result, neg, half)
48 case RoundFloor:
49 return roundFloor(result, neg, half)
50 case RoundHalfDown:
51 return roundHalfDown(result, neg, half)
52 case RoundUp:
53 return roundUp(result, neg, half)
54 case Round05Up:
55 return round05Up(result, neg, half)
56 default:
57 return roundHalfUp(result, neg, half)
58 }
59}
60
61// Round sets d to rounded x.
62func (r Rounder) Round(c *Context, d, x *Decimal, disableIfPrecisionZero bool) Condition {

Callers 3

RoundMethod · 0.95
QuoMethod · 0.80
setExponentMethod · 0.80

Calls 8

roundDownFunction · 0.85
roundHalfUpFunction · 0.85
roundHalfEvenFunction · 0.85
roundCeilingFunction · 0.85
roundFloorFunction · 0.85
roundHalfDownFunction · 0.85
roundUpFunction · 0.85
round05UpFunction · 0.85

Tested by

no test coverage detected