@@ -77,10 +77,6 @@ pub(crate) fn jacobi_symbol<const L: usize>(a: i32, p_long: &Uint<L>) -> JacobiS
7777 if p_long. is_even ( ) . into ( ) {
7878 panic ! ( "`p_long` must be an odd integer, but got {}" , p_long) ;
7979 }
80- if a == i32:: MIN {
81- // Otherwise it will cause an overflow when taking its absolute value.
82- panic ! ( "`a` must be greater than `i32::MIN`" ) ;
83- }
8480
8581 let result = JacobiSymbol :: One ; // Keep track of all the sign flips here.
8682
@@ -185,12 +181,6 @@ mod tests {
185181 let _j = jacobi_symbol ( 1 , & U128 :: from ( 4u32 ) ) ;
186182 }
187183
188- #[ test]
189- #[ should_panic( expected = "`a` must be greater than `i32::MIN`" ) ]
190- fn jacobi_symbol_a_is_too_small ( ) {
191- let _j = jacobi_symbol ( i32:: MIN , & U128 :: from ( 5u32 ) ) ;
192- }
193-
194184 // Reference from `num-modular` - supports long `p`, but only positive `a`.
195185 fn jacobi_symbol_ref ( a : i32 , p : & U128 ) -> JacobiSymbol {
196186 let a_bi = BigInt :: from ( a) ;
@@ -224,11 +214,18 @@ mod tests {
224214 let a = 2147483647i32 ; // 2^31 - 1, a prime
225215 let p = U128 :: from_be_hex ( "000000007ffffffeffffffe28000003b" ) ; // (2^31 - 1) * (2^64 - 59)
226216 assert_eq ! ( jacobi_symbol( a, & p) , JacobiSymbol :: Zero ) ;
217+ assert_eq ! ( jacobi_symbol_ref( a, & p) , JacobiSymbol :: Zero ) ;
227218
228219 // a = x^2 mod p, should give 1.
229220 let a = 659456i32 ; // Obtained from x = 2^70
230221 let p = U128 :: from_be_hex ( "ffffffffffffffffffffffffffffff5f" ) ; // 2^128 - 161 - not a prime
231222 assert_eq ! ( jacobi_symbol( a, & p) , JacobiSymbol :: One ) ;
223+ assert_eq ! ( jacobi_symbol_ref( a, & p) , JacobiSymbol :: One ) ;
224+
225+ let a = i32:: MIN ; // -2^31, check that no overflow occurs
226+ let p = U128 :: from_be_hex ( "000000007ffffffeffffffe28000003b" ) ; // (2^31 - 1) * (2^64 - 59)
227+ assert_eq ! ( jacobi_symbol( a, & p) , JacobiSymbol :: One ) ;
228+ assert_eq ! ( jacobi_symbol_ref( a, & p) , JacobiSymbol :: One ) ;
232229 }
233230
234231 prop_compose ! {
0 commit comments