@@ -1452,6 +1452,7 @@ public static PreciseNumber Add(PreciseNumber left, PreciseNumber right)
14521452 /// <param name="left">The first number to multiply.</param>
14531453 /// <param name="right">The second number to multiply.</param>
14541454 /// <returns>The result of the multiplication.</returns>
1455+ /// <exception cref="OverflowException">Thrown when the product needs an exponent outside the range of an <see cref="int"/>.</exception>
14551456 public static PreciseNumber Multiply ( PreciseNumber left , PreciseNumber right )
14561457 {
14571458 if ( left . Significand . IsZero || right . Significand . IsZero )
@@ -1469,7 +1470,7 @@ public static PreciseNumber Multiply(PreciseNumber left, PreciseNumber right)
14691470
14701471 // (l * 10^el) * (r * 10^er) == (l * r) * 10^(el + er), so there is no need to scale the
14711472 // operands to a common exponent first; doing so only inflates both significands.
1472- return new PreciseNumber ( left . Exponent + right . Exponent , left . Significand * right . Significand ) ;
1473+ return new PreciseNumber ( checked ( left . Exponent + right . Exponent ) , left . Significand * right . Significand ) ;
14731474 }
14741475
14751476 /// <summary>
@@ -1479,6 +1480,7 @@ public static PreciseNumber Multiply(PreciseNumber left, PreciseNumber right)
14791480 /// <param name="right">The number to divide by.</param>
14801481 /// <returns>The result of the division.</returns>
14811482 /// <exception cref="DivideByZeroException">Thrown when <paramref name="right"/> is zero.</exception>
1483+ /// <exception cref="OverflowException">Thrown when the quotient needs an exponent outside the range of an <see cref="int"/>.</exception>
14821484 /// <remarks>
14831485 /// A quotient whose decimal expansion terminates is produced exactly, however many digits that
14841486 /// takes. One that repeats is produced to the precision of the wider operand, and never fewer
@@ -1508,6 +1510,7 @@ public static PreciseNumber Divide(PreciseNumber left, PreciseNumber right)
15081510 /// <returns>The result of the division.</returns>
15091511 /// <exception cref="DivideByZeroException">Thrown when <paramref name="right"/> is zero.</exception>
15101512 /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="significantDigits"/> is less than one.</exception>
1513+ /// <exception cref="OverflowException">Thrown when the quotient needs an exponent outside the range of an <see cref="int"/>.</exception>
15111514 public static PreciseNumber Divide ( PreciseNumber left , PreciseNumber right , int significantDigits )
15121515 {
15131516 if ( significantDigits < 1 )
@@ -1527,7 +1530,7 @@ public static PreciseNumber Divide(PreciseNumber left, PreciseNumber right, int
15271530
15281531 BigInteger numerator = left . Significand ;
15291532 BigInteger denominator = right . Significand ;
1530- int exponent = left . Exponent - right . Exponent ;
1533+ int exponent = checked ( left . Exponent - right . Exponent ) ;
15311534
15321535 // Carry the sign on the numerator so the denominator can be factorized as a positive value.
15331536 if ( denominator . Sign < 0 )
@@ -1586,7 +1589,7 @@ private static bool TryDivideExactly(BigInteger numerator, BigInteger denominato
15861589 int scale = Math . Max ( twos , fives ) ;
15871590 BigInteger significand = numerator * BigInteger . Pow ( 2 , scale - twos ) * BigInteger . Pow ( 5 , scale - fives ) ;
15881591
1589- result = new PreciseNumber ( exponent - scale , significand ) ;
1592+ result = new PreciseNumber ( checked ( exponent - scale ) , significand ) ;
15901593 return true ;
15911594 }
15921595
@@ -1605,7 +1608,7 @@ private static PreciseNumber DivideToPrecision(BigInteger numerator, BigInteger
16051608 // rounding decision is made on.
16061609 int scale = significantDigits + 1 - CountDigits ( numerator ) + CountDigits ( denominator ) ;
16071610 BigInteger scaled = scale > 0 ? numerator * Pow10 ( scale ) : numerator ;
1608- int scaledExponent = exponent - Math . Max ( scale , 0 ) ;
1611+ int scaledExponent = checked ( exponent - Math . Max ( scale , 0 ) ) ;
16091612
16101613 BigInteger quotient = scaled / denominator ;
16111614 int excess = CountDigits ( quotient ) - significantDigits ;
@@ -1626,7 +1629,7 @@ private static PreciseNumber DivideToPrecision(BigInteger numerator, BigInteger
16261629 kept += quotient . Sign ;
16271630 }
16281631
1629- return new PreciseNumber ( scaledExponent + excess , kept ) ;
1632+ return new PreciseNumber ( checked ( scaledExponent + excess ) , kept ) ;
16301633 }
16311634
16321635 /// <summary>
0 commit comments