@@ -198,6 +198,9 @@ fn subtract(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
198198 x1: The first unsigned integer (minuend).
199199 x2: The second unsigned integer (subtrahend).
200200
201+ Raises:
202+ Error: If x2 is greater than x1, resulting in an underflow.
203+
201204 Returns:
202205 The result of subtracting x2 from x1.
203206 """
@@ -206,7 +209,7 @@ fn subtract(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
206209 return x1
207210 if x1.is_zero():
208211 # x2 is not zero, so the result is negative, raise an error
209- raise Error(" Error in ` subtract` : Underflow due to x1 < x2" )
212+ raise Error(" biguint.arithmetics. subtract() : Underflow due to x1 < x2" )
210213
211214 # We need to determine which number has the larger magnitude
212215 var comparison_result = x1.compare(x2)
@@ -216,7 +219,7 @@ fn subtract(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
216219 return BigUInt() # Return zero
217220
218221 if comparison_result < 0 :
219- raise Error(" Error in ` subtract` : Underflow due to x1 < x2" )
222+ raise Error(" biguint.arithmetics. subtract() : Underflow due to x1 < x2" )
220223
221224 # Now it is safe to subtract the smaller number from the larger one
222225 # The result will have no more words than the larger operand
@@ -251,13 +254,16 @@ fn negative(x: BigUInt) raises -> BigUInt:
251254 Args:
252255 x: The BigUInt value to compute the negative of.
253256
257+ Raises:
258+ Error: If x is not zero, as negative of non-zero unsigned integer is undefined.
259+
254260 Returns:
255261 A new BigUInt containing the negative of x.
256262 """
257263 if not x.is_zero():
258264 raise Error(
259- " Error in ` negative` : Negative of non-zero unsigned integer is "
260- " undefined"
265+ " biguint.arithmetics. negative() : Negative of non-zero unsigned"
266+ " integer is undefined"
261267 )
262268 return BigUInt() # Return zero
263269
@@ -274,7 +280,7 @@ fn absolute(x: BigUInt) -> BigUInt:
274280 return x
275281
276282
277- fn multiply (x1 : BigUInt, x2 : BigUInt) raises -> BigUInt:
283+ fn multiply (x1 : BigUInt, x2 : BigUInt) -> BigUInt:
278284 """ Returns the product of two BigUInt numbers.
279285
280286 Args:
@@ -359,7 +365,7 @@ fn floor_divide(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
359365 if len (x2.words) == 1 :
360366 # SUB-CASE: Division by zero
361367 if x2.words[0 ] == 0 :
362- raise Error(" Error in `truncate_divide` : Division by zero" )
368+ raise Error(" biguint.arithmetics.floor_divide() : Division by zero" )
363369
364370 # SUB-CASE: Division by one
365371 if x2.words[0 ] == 1 :
@@ -488,7 +494,7 @@ fn ceil_divide(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
488494
489495 # CASE: Division by zero
490496 if x2.is_zero():
491- raise Error(" Error in ` ceil_divide` : Division by zero" )
497+ raise Error(" biguint.arithmetics. ceil_divide() : Division by zero" )
492498
493499 # Apply floor division and check if there is a remainder
494500 var quotient = floor_divide(x1, x2)
@@ -850,10 +856,14 @@ fn floor_divide_inplace_by_double_words(
850856 Args:
851857 x1: The BigUInt value to divide by the divisor.
852858 x2: The double-word divisor.
859+
860+ Raises:
861+ Error: If the divisor is zero.
853862 """
854863 if x2.is_zero():
855864 raise Error(
856- " Error in `floor_divide_inplace_by_double_words`: Division by zero"
865+ " biguint.arithmetics.floor_divide_inplace_by_double_words():"
866+ " Division by zero"
857867 )
858868
859869 # CASE: all other situations
@@ -911,12 +921,16 @@ fn scale_down_by_power_of_10(x: BigUInt, n: Int) raises -> BigUInt:
911921 x: The BigUInt value to multiply.
912922 n: The power of 10 to multiply by.
913923
924+ Raises:
925+ Error: If n is negative.
926+
914927 Returns:
915928 A new BigUInt containing the result of the multiplication.
916929 """
917930 if n < 0 :
918931 raise Error(
919- " Error in `scale_down_by_power_of_10`: n must be non-negative"
932+ " biguint.arithmetics.scale_down_by_power_of_10(): "
933+ " n must be non-negative"
920934 )
921935 if n == 0 :
922936 return x
@@ -1038,7 +1052,9 @@ fn shift_words_left(num: BigUInt, positions: Int) -> BigUInt:
10381052fn power_of_10 (n : Int) raises -> BigUInt:
10391053 """ Calculates 10^n efficiently."""
10401054 if n < 0 :
1041- raise Error(" Error in `power_of_10`: Negative exponent not supported" )
1055+ raise Error(
1056+ " biguint.arithmetics.power_of_10(): Negative exponent not supported"
1057+ )
10421058
10431059 if n == 0 :
10441060 return BigUInt(1 )
0 commit comments