@@ -46,7 +46,6 @@ pub(crate) const fn partial_reduce64(a: i64) -> i32 {
46
46
#[ allow( dead_code, clippy:: cast_possible_truncation) ] // I may come back to this and experiment more
47
47
pub ( crate ) const fn partial_reduce64b ( a : i64 ) -> i32 {
48
48
const MM : i64 = ( ( 1 << 64 ) / ( Q as i128 ) ) as i64 ;
49
- debug_assert ! ( a < ( i64 :: MAX / 64 ) , "partial_reduce64b input" ) ; // actually, works for all 64b inputs!!
50
49
let q = ( a as i128 * MM as i128 ) >> 64 ; // only top half is relevant
51
50
let res = a - ( q as i64 * Q as i64 ) ;
52
51
debug_assert ! ( res. abs( ) < 2 * Q as i64 , "partial_reduce64b output" ) ;
@@ -192,9 +191,26 @@ mod tests {
192
191
#[ test]
193
192
fn check_zeta ( ) {
194
193
let val = gen_zeta_table_mont ( ) ;
195
- assert_eq ! ( val[ 0 ] , 4193792 ) ;
196
- assert_eq ! ( val[ 1 ] , 25847 ) ;
197
- assert_eq ! ( val[ 2 ] , 5771523 ) ;
194
+ assert_eq ! ( val[ 0 ] , 4_193_792 ) ;
195
+ assert_eq ! ( val[ 1 ] , 25_847 ) ;
196
+ assert_eq ! ( val[ 2 ] , 5_771_523 ) ;
197
+ }
198
198
199
+ #[ test]
200
+ fn test_partial_reduce64b ( ) {
201
+ // Test with various input values
202
+ assert_eq ! ( partial_reduce64b( 0 ) , 0 ) ;
203
+ assert_eq ! ( partial_reduce64b( Q as i64 ) , partial_reduce64( Q as i64 ) ) ;
204
+ assert_eq ! ( partial_reduce64b( -Q as i64 ) , partial_reduce64b( -Q as i64 ) ) ;
205
+
206
+ // Test with large positive and negative values
207
+ let large_pos = i64:: MAX / 64 ;
208
+ let large_neg = -i64:: MAX / 64 ;
209
+ assert ! ( partial_reduce64b( large_pos) . abs( ) < 2 * Q ) ;
210
+ assert ! ( partial_reduce64b( large_neg) . abs( ) < 2 * Q ) ;
211
+
212
+ // Test with some specific values
213
+ assert_eq ! ( partial_reduce64b( 12345678 ) , partial_reduce64( 12345678 ) ) ;
214
+ assert_eq ! ( partial_reduce64b( -12345678 ) , partial_reduce64( -12345678 ) ) ;
199
215
}
200
216
}
0 commit comments