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)
| 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. |
| 36 | func (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. |
| 62 | func (r Rounder) Round(c *Context, d, x *Decimal, disableIfPrecisionZero bool) Condition { |
no test coverage detected