@@ -21,13 +21,9 @@ func (c *Context) Round(d, x *Decimal) (Condition, error) {
2121 return c .goError (c .round (d , x ))
2222}
2323
24+ //gcassert:inline
2425func (c * Context ) round (d , x * Decimal ) Condition {
25- if c .Precision == 0 {
26- d .Set (x )
27- return d .setExponent (c , unknownNumDigits , 0 , int64 (d .Exponent ))
28- }
29- res := c .Rounding .Round (c , d , x )
30- return res
26+ return c .Rounding .Round (c , d , x , true /* disableIfPrecisionZero */ )
3127}
3228
3329// Rounder specifies the behavior of rounding.
@@ -63,12 +59,17 @@ func (r Rounder) ShouldAddOne(result *BigInt, neg bool, half int) bool {
6359}
6460
6561// Round sets d to rounded x.
66- func (r Rounder ) Round (c * Context , d , x * Decimal ) Condition {
62+ func (r Rounder ) Round (c * Context , d , x * Decimal , disableIfPrecisionZero bool ) Condition {
6763 d .Set (x )
6864 nd := x .NumDigits ()
6965 xs := x .Sign ()
7066 var res Condition
7167
68+ if disableIfPrecisionZero && c .Precision == 0 {
69+ // Rounding has been disabled.
70+ return d .setExponent (c , nd , res , int64 (d .Exponent ))
71+ }
72+
7273 // adj is the adjusted exponent: exponent + clength - 1
7374 if adj := int64 (x .Exponent ) + nd - 1 ; xs != 0 && adj < int64 (c .MinExponent ) {
7475 // Subnormal is defined before rounding.
0 commit comments