@@ -7,24 +7,21 @@ macro_rules! tests {
77 // Check that the following produce the correct values from
88 // `isqrt`:
99 //
10- // * `<$T>::MIN` (for signed types, no nonnegative value can
11- // negate to `<$T>::MIN)
1210 // * the first and last 128 nonnegative values
1311 // * powers of two, minus one
1412 // * powers of two
1513 //
16- // For signed types, check that `checked_isqrt` and
17- // `isqrt` either produce the same numeric value or
18- // respectively produce `None` and a panic.
14+ // For signed types, check that `checked_isqrt` and `isqrt`
15+ // either produce the same numeric value or respectively
16+ // produce `None` and a panic. Make sure to do a consistency
17+ // check for `<$T>::MIN` as well, as no nonnegative values
18+ // negate to it.
1919 //
2020 // For unsigned types check that `isqrt` produces the same
2121 // numeric value for `$T` and `NonZero<$T>`.
2222 #[ test]
2323 fn isqrt( ) {
24- // Check the minimum value because, for signed types,
25- // there's no nonnegative value that can be negated into
26- // the minimum value.
27- isqrt_consistency_check( $T:: MIN ) ;
24+ isqrt_consistency_check( <$T>:: MIN ) ;
2825
2926 for n in ( 0 ..=127 )
3027 . chain( <$T>:: MAX - 127 ..=<$T>:: MAX )
@@ -35,11 +32,17 @@ macro_rules! tests {
3532
3633 let isqrt_n = n. isqrt( ) ;
3734 assert!(
38- isqrt_n. checked_mul( isqrt_n) . map( |isqrt_n_squared| isqrt_n_squared <= n) . unwrap_or( false ) ,
35+ isqrt_n
36+ . checked_mul( isqrt_n)
37+ . map( |isqrt_n_squared| isqrt_n_squared <= n)
38+ . unwrap_or( false ) ,
3939 "`{n}.isqrt()` should be lower than {isqrt_n}."
4040 ) ;
4141 assert!(
42- ( isqrt_n + 1 ) . checked_mul( isqrt_n + 1 ) . map( |isqrt_n_plus_1_squared| n < isqrt_n_plus_1_squared) . unwrap_or( true ) ,
42+ ( isqrt_n + 1 )
43+ . checked_mul( isqrt_n + 1 )
44+ . map( |isqrt_n_plus_1_squared| n < isqrt_n_plus_1_squared)
45+ . unwrap_or( true ) ,
4346 "`{n}.isqrt()` should be higher than {isqrt_n})."
4447 ) ;
4548 }
@@ -173,8 +176,8 @@ macro_rules! signed_check {
173176 ( $T: ident) => {
174177 /// This takes an input and, if it's nonnegative or
175178 #[ doc = concat!( "`" , stringify!( $T) , "::MIN`," ) ]
176- /// checks that `isqrt` and `checked_isqrt` produce equivalent
177- /// results for that input and for the negative of that input.
179+ /// checks that `isqrt` and `checked_isqrt` produce equivalent results
180+ /// for that input and for the negative of that input.
178181 fn isqrt_consistency_check( n: $T) {
179182 // `<$T>::MIN` will be negative, so ignore it in this nonnegative
180183 // section.
@@ -186,8 +189,8 @@ macro_rules! signed_check {
186189 ) ;
187190 }
188191
189- // `wrapping_neg` so that `<$T>::MIN` will negate to
190- // itself rather than panicking.
192+ // `wrapping_neg` so that `<$T>::MIN` will negate to itself rather
193+ // than panicking.
191194 let negative_n = n. wrapping_neg( ) ;
192195
193196 // Zero negated will still be nonnegative, so ignore it in this
@@ -209,8 +212,8 @@ macro_rules! signed_check {
209212
210213macro_rules! unsigned_check {
211214 ( $T: ident) => {
212- /// This takes an input and, if it's nonzero, checks that
213- /// `isqrt` produces the same numeric value for both
215+ /// This takes an input and, if it's nonzero, checks that `isqrt`
216+ /// produces the same numeric value for both
214217 #[ doc = concat!( "`" , stringify!( $T) , "` and " ) ]
215218 #[ doc = concat!( "`NonZero<" , stringify!( $T) , ">`." ) ]
216219 fn isqrt_consistency_check( n: $T) {
@@ -220,7 +223,9 @@ macro_rules! unsigned_check {
220223 assert_eq!(
221224 n. isqrt( ) ,
222225 :: core:: num:: NonZero :: <$T>:: new( n)
223- . expect( "Was not able to create a new `NonZero` value from a nonzero value" )
226+ . expect(
227+ "Was not able to create a new `NonZero` value from a nonzero number."
228+ )
224229 . isqrt( )
225230 . get( ) ,
226231 "`{n}.isqrt` should match `NonZero`'s `{n}.isqrt().get()`." ,
0 commit comments