@@ -204,26 +204,36 @@ impl BigIntConstructor {
204204 let bigint = to_big_int ( agent, bigint. get ( agent) , gc. reborrow ( ) )
205205 . unbind ( ) ?
206206 . bind ( gc. nogc ( ) ) ;
207- match bigint {
208- BigInt :: BigInt ( int) => {
209- let int = & agent[ int] . data ;
210- let modulus = 2i64 . pow ( bits) ;
211- Ok (
212- BigInt :: from_num_bigint ( agent, ( ( int % modulus) + modulus) % modulus)
213- . into_value ( ) ,
214- )
215- }
216- BigInt :: SmallBigInt ( int) => {
217- let int = int. into_i64 ( ) ;
218- if let Some ( modulo) = 2i64
219- . checked_pow ( bits)
220- . and_then ( |base| int. checked_rem_euclid ( base) )
221- {
207+
208+ match 2i64 . checked_pow ( bits) {
209+ Some ( modulus) => match bigint {
210+ BigInt :: BigInt ( int) => {
211+ let int = & agent[ int] . data ;
212+ Ok (
213+ BigInt :: from_num_bigint ( agent, ( ( int % modulus) + modulus) % modulus)
214+ . into_value ( ) ,
215+ )
216+ }
217+ BigInt :: SmallBigInt ( int) => {
218+ let int = int. into_i64 ( ) ;
219+ let modulo = int. rem_euclid ( modulus) ;
222220 Ok ( BigInt :: from ( SmallBigInt :: try_from ( modulo) . unwrap ( ) ) . into_value ( ) )
223- } else {
224- let modulus = num_bigint:: BigInt :: from ( 2 ) . pow ( bits) ;
225- let result = ( ( int % modulus. clone ( ) ) + modulus. clone ( ) ) % modulus;
226- Ok ( BigInt :: from_num_bigint ( agent, result) . into_value ( ) )
221+ }
222+ } ,
223+ None => {
224+ let modulus =
225+ num_bigint:: BigInt :: from_bytes_le ( num_bigint:: Sign :: Plus , & [ 2 ] ) . pow ( bits) ;
226+ match bigint {
227+ BigInt :: BigInt ( int) => {
228+ let int = & agent[ int] . data ;
229+ let result = ( ( int % & modulus) + & modulus) % & modulus;
230+ Ok ( BigInt :: from_num_bigint ( agent, result) . into_value ( ) )
231+ }
232+ BigInt :: SmallBigInt ( int) => {
233+ let int = int. into_i64 ( ) ;
234+ let result = ( ( int % & modulus) + & modulus) % & modulus;
235+ Ok ( BigInt :: from_num_bigint ( agent, result) . into_value ( ) )
236+ }
227237 }
228238 }
229239 }
0 commit comments