@@ -25,6 +25,34 @@ from decimojo.biguint.biguint import BigUInt
2525import decimojo.biguint.comparison
2626from decimojo.rounding_mode import RoundingMode
2727
28+ # ===----------------------------------------------------------------------=== #
29+ # List of functions in this module:
30+ # add(x1: BigUInt, x2: BigUInt) -> BigUInt
31+ # add_inplace(x1: BigUInt, x2: BigUInt)
32+ # add_inplace_by_1(x: BigUInt) -> None
33+ # subtract(x1: BigUInt, x2: BigUInt) -> BigUInt
34+ # negative(x: BigUInt) -> BigUInt
35+ # absolute(x: BigUInt) -> BigUInt
36+ # multiply(x1: BigUInt, x2: BigUInt) -> BigUInt
37+ # floor_divide(x1: BigUInt, x2: BigUInt) -> BigUInt
38+ # truncate_divide(x1: BigUInt, x2: BigUInt) -> BigUInt
39+ # ceil_divide(x1: BigUInt, x2: BigUInt) -> BigUInt
40+ # floor_modulo(x1: BigUInt, x2: BigUInt) -> BigUInt
41+ # truncate_modulo(x1: BigUInt, x2: BigUInt) -> BigUInt
42+ # ceil_modulo(x1: BigUInt, x2: BigUInt) -> BigUInt
43+ # divmod(x1: BigUInt, x2: BigUInt) -> Tuple[BigUInt, BigUInt]
44+ # scale_up_by_power_of_10(x: BigUInt, n: Int) -> BigUInt
45+ # floor_divide_general(x1: BigUInt, x2: BigUInt) -> BigUInt
46+ # floor_divide_partition(x1: BigUInt, x2: BigUInt) -> BigUInt
47+ # floor_divide_inplace_by_single_word(x1: BigUInt, x2: BigUInt) -> None
48+ # floor_divide_inplace_by_double_words(x1: BigUInt, x2: BigUInt) -> None
49+ # floor_divide_inplace_by_2(x: BigUInt) -> None
50+ # scale_down_by_power_of_10(x: BigUInt, n: Int) -> BigUInt
51+ # estimate_quotient(x1: BigUInt, x2: BigUInt, j: Int, m: Int) -> UInt64
52+ # shift_words_left(x: BigUInt, j: Int) -> BigUInt
53+ # power_of_10(n: Int) -> BigUInt
54+ # ===----------------------------------------------------------------------=== #
55+
2856# ===----------------------------------------------------------------------=== #
2957# Arithmetic Operations
3058# add, subtract, negative, absolute, multiply, floor_divide, modulo
@@ -75,7 +103,7 @@ fn add(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
75103
76104 var carry : UInt32 = 0
77105 var ith : Int = 0
78- var sum_of_words : UInt32 = 0
106+ var sum_of_words : UInt32
79107
80108 # Add corresponding words from both numbers
81109 while ith < len (x1.words) or ith < len (x2.words):
@@ -102,7 +130,7 @@ fn add(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
102130 return BigUInt(words = words^ )
103131
104132
105- fn add_inplace (mut x1 : BigUInt, x2 : BigUInt) raises :
133+ fn add_inplace (mut x1 : BigUInt, x2 : BigUInt) raises -> None :
106134 """ Increments a BigUInt number by another BigUInt number in place.
107135
108136 Args:
@@ -134,7 +162,7 @@ fn add_inplace(mut x1: BigUInt, x2: BigUInt) raises:
134162
135163 var carry : UInt32 = 0
136164 var ith : Int = 0
137- var sum_of_words : UInt32 = 0
165+ var sum_of_words : UInt32
138166 var x1_len = len (x1.words)
139167
140168 while ith < x1_len or ith < len (x2.words):
@@ -164,7 +192,7 @@ fn add_inplace(mut x1: BigUInt, x2: BigUInt) raises:
164192 return
165193
166194
167- fn add_inplace_by_1 (mut x : BigUInt) raises :
195+ fn add_inplace_by_1 (mut x : BigUInt) raises -> None :
168196 """ Increments a BigUInt number by 1."""
169197 var i = 0
170198 while i < len (x.words):
@@ -211,7 +239,7 @@ fn subtract(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
211239 var words = List[UInt32](capacity = max (len (x1.words), len (x2.words)))
212240 var borrow : Int32 = 0
213241 var ith : Int = 0
214- var difference : Int32 = 0 # Int32 is sufficient for the difference
242+ var difference : Int32 # Int32 is sufficient for the difference
215243
216244 while ith < len (x1.words):
217245 # Subtract the borrow
@@ -294,7 +322,7 @@ fn multiply(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
294322 # x1 = x1[0] + x1[1] * 10^9
295323 # x2 = x2[0] + x2[1] * 10^9
296324 # x1 * x2 = x1[0] * x2[0] + (x1[0] * x2[1] + x1[1] * x2[0]) * 10^9 + x1[1] * x2[1] * 10^18
297- var carry : UInt64 = 0
325+ var carry : UInt64
298326 for i in range (len (x1.words)):
299327 # Skip if the word is zero
300328 if x1.words[i] == 0 :
@@ -769,7 +797,7 @@ fn floor_divide_partition(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
769797 var number_of_words_remainder = len (x1.words) % len (x2.words)
770798 var number_of_words_dividend : Int
771799 var result = x1
772- result.words.resize(len (x1.words) - number_of_words_remainder)
800+ result.words.resize(len (x1.words) - number_of_words_remainder, UInt32( 0 ) )
773801 var remainder = BigUInt(List[UInt32](capacity = len (x2.words)))
774802 for i in range (len (x1.words) - number_of_words_remainder, len (x1.words)):
775803 remainder.words.append(x1.words[i])
@@ -804,7 +832,9 @@ fn floor_divide_partition(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
804832 return result^
805833
806834
807- fn floor_divide_inplace_by_single_word (mut x1 : BigUInt, x2 : BigUInt) raises :
835+ fn floor_divide_inplace_by_single_word (
836+ mut x1 : BigUInt, x2 : BigUInt
837+ ) raises -> None :
808838 """ Divides a BigUInt by a single word divisor in-place.
809839
810840 Args:
@@ -826,7 +856,9 @@ fn floor_divide_inplace_by_single_word(mut x1: BigUInt, x2: BigUInt) raises:
826856 x1.remove_leading_empty_words()
827857
828858
829- fn floor_divide_inplace_by_double_words (mut x1 : BigUInt, x2 : BigUInt) raises :
859+ fn floor_divide_inplace_by_double_words (
860+ mut x1 : BigUInt, x2 : BigUInt
861+ ) raises -> None :
830862 """ Divides a BigUInt by double-word divisor in-place.
831863
832864 Args:
@@ -846,7 +878,7 @@ fn floor_divide_inplace_by_double_words(mut x1: BigUInt, x2: BigUInt) raises:
846878 var carry = UInt128(0 )
847879 if len (x1.words) % 2 == 1 :
848880 carry = UInt128(x1.words[- 1 ])
849- x1.words.resize(len (x1.words) - 1 )
881+ x1.words.resize(len (x1.words) - 1 , UInt32( 0 ) )
850882
851883 for i in range (len (x1.words) - 1 , - 1 , - 2 ):
852884 var dividend = carry * UInt128(1_000_000_000_000_000_000 ) + UInt128(
@@ -861,7 +893,7 @@ fn floor_divide_inplace_by_double_words(mut x1: BigUInt, x2: BigUInt) raises:
861893 return
862894
863895
864- fn floor_divide_inplace_by_2 (mut x : BigUInt):
896+ fn floor_divide_inplace_by_2 (mut x : BigUInt) -> None :
865897 """ Divides a BigUInt by 2 in-place.
866898
867899 Args:
@@ -880,7 +912,7 @@ fn floor_divide_inplace_by_2(mut x: BigUInt):
880912
881913 # Remove leading zeros
882914 while len (x.words) > 1 and x.words[len (x.words) - 1 ] == 0 :
883- x.words.resize(len (x.words) - 1 )
915+ x.words.resize(len (x.words) - 1 , UInt32( 0 ) )
884916
885917
886918fn scale_down_by_power_of_10 (x : BigUInt, n : Int) raises -> BigUInt:
0 commit comments