@@ -109,23 +109,23 @@ FLATTEN SignedBigInteger SignedBigInteger::minus(SignedBigInteger const& other)
109109 // x - y = - (y - x)
110110 if (m_unsigned_data < other.m_unsigned_data ) {
111111 // The result will be negative.
112- return { other.m_unsigned_data .minus (m_unsigned_data), true };
112+ return { MUST ( other.m_unsigned_data .minus (m_unsigned_data) ), true };
113113 }
114114
115115 // The result will be either zero, or positive.
116- return SignedBigInteger { m_unsigned_data.minus (other.m_unsigned_data ) };
116+ return SignedBigInteger { MUST ( m_unsigned_data.minus (other.m_unsigned_data ) ) };
117117 }
118118
119119 // Both operands are negative.
120120 // -x - -y = y - x
121121 if (m_unsigned_data < other.m_unsigned_data ) {
122122 // The result will be positive.
123- return SignedBigInteger { other.m_unsigned_data .minus (m_unsigned_data) };
123+ return SignedBigInteger { MUST ( other.m_unsigned_data .minus (m_unsigned_data) ) };
124124 }
125125 // y - x = - (x - y)
126126 if (m_unsigned_data > other.m_unsigned_data ) {
127127 // The result will be negative.
128- return SignedBigInteger { m_unsigned_data.minus (other.m_unsigned_data ), true };
128+ return SignedBigInteger { MUST ( m_unsigned_data.minus (other.m_unsigned_data ) ), true };
129129 }
130130 // Both operands have the same magnitude, the result is positive zero.
131131 return SignedBigInteger { 0 };
@@ -135,9 +135,9 @@ FLATTEN SignedBigInteger SignedBigInteger::plus(UnsignedBigInteger const& other)
135135{
136136 if (m_sign) {
137137 if (other < m_unsigned_data)
138- return { m_unsigned_data.minus (other), true };
138+ return { MUST ( m_unsigned_data.minus (other) ), true };
139139
140- return { other.minus (m_unsigned_data), false };
140+ return { MUST ( other.minus (m_unsigned_data) ), false };
141141 }
142142
143143 return { m_unsigned_data.plus (other), false };
@@ -149,9 +149,9 @@ FLATTEN SignedBigInteger SignedBigInteger::minus(UnsignedBigInteger const& other
149149 return { m_unsigned_data.plus (m_unsigned_data), true };
150150
151151 if (other < m_unsigned_data)
152- return { m_unsigned_data.minus (other), false };
152+ return { MUST ( m_unsigned_data.minus (other) ), false };
153153
154- return { other.minus (m_unsigned_data), true };
154+ return { MUST ( other.minus (m_unsigned_data) ), true };
155155}
156156
157157FLATTEN SignedBigInteger SignedBigInteger::bitwise_not () const
@@ -190,16 +190,16 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_or(SignedBigInteger const& ot
190190 // This saves one ~.
191191 if (is_negative () && !other.is_negative ()) {
192192 size_t index = unsigned_value ().one_based_index_of_highest_set_bit ();
193- return { unsigned_value ().minus (1 ).bitwise_and (other.unsigned_value ().bitwise_not_fill_to_one_based_index (index)).plus (1 ), true };
193+ return { MUST ( unsigned_value ().minus (1 ) ).bitwise_and (other.unsigned_value ().bitwise_not_fill_to_one_based_index (index)).plus (1 ), true };
194194 }
195195
196196 // -(A | -B) == ~A & (B - 1) + 1
197197 if (!is_negative () && other.is_negative ()) {
198198 size_t index = other.unsigned_value ().one_based_index_of_highest_set_bit ();
199- return { unsigned_value ().bitwise_not_fill_to_one_based_index (index).bitwise_and (other.unsigned_value ().minus (1 )).plus (1 ), true };
199+ return { unsigned_value ().bitwise_not_fill_to_one_based_index (index).bitwise_and (MUST ( other.unsigned_value ().minus (1 ) )).plus (1 ), true };
200200 }
201201
202- return { unsigned_value ().minus (1 ).bitwise_and (other.unsigned_value ().minus (1 )).plus (1 ), true };
202+ return { MUST ( unsigned_value ().minus (1 )) .bitwise_and (MUST ( other.unsigned_value ().minus (1 ) )).plus (1 ), true };
203203}
204204
205205FLATTEN SignedBigInteger SignedBigInteger::bitwise_and (SignedBigInteger const & other) const
@@ -237,7 +237,7 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(SignedBigInteger const& o
237237 // -A & -B == -( (A - 1) | (B - 1) + 1)
238238 // So we can compute the bitwise and by returning a negative number with magnitude (A - 1) | (B - 1) + 1.
239239 // This is better than the naive (~A + 1) & (~B + 1) because it needs just one O(n) scan for the or instead of 2 for the ~s.
240- return { unsigned_value ().minus (1 ).bitwise_or (other.unsigned_value ().minus (1 )).plus (1 ), true };
240+ return { MUST ( unsigned_value ().minus (1 )) .bitwise_or (MUST ( other.unsigned_value ().minus (1 ) )).plus (1 ), true };
241241}
242242
243243FLATTEN SignedBigInteger SignedBigInteger::bitwise_xor (SignedBigInteger const & other) const
@@ -333,9 +333,6 @@ void SignedBigInteger::set_bit_inplace(size_t bit_index)
333333
334334bool SignedBigInteger::operator ==(SignedBigInteger const & other) const
335335{
336- if (is_invalid () != other.is_invalid ())
337- return false ;
338-
339336 if (m_unsigned_data == 0 && other.m_unsigned_data == 0 )
340337 return true ;
341338
0 commit comments