@@ -131,28 +131,6 @@ fn main() {
131
131
);*/
132
132
*/
133
133
134
- assert_eq ! ( NonZeroU8 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 7 ) ;
135
- assert_eq ! ( NonZeroI8 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 7 ) ;
136
- assert_eq ! ( NonZeroU16 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 15 ) ;
137
- assert_eq ! ( NonZeroI16 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 15 ) ;
138
- assert_eq ! ( NonZeroU32 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 31 ) ;
139
- assert_eq ! ( NonZeroI32 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 31 ) ;
140
- assert_eq ! ( NonZeroU64 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 63 ) ;
141
- assert_eq ! ( NonZeroI64 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 63 ) ;
142
- assert_eq ! ( NonZeroU128 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 127 ) ;
143
- assert_eq ! ( NonZeroI128 :: new( 1 ) . unwrap( ) . leading_zeros( ) , 127 ) ;
144
- assert_eq ! ( NonZeroUsize :: new( 1 ) . unwrap( ) . leading_zeros( ) , usize :: BITS - 1 ) ;
145
- assert_eq ! ( NonZeroIsize :: new( 1 ) . unwrap( ) . leading_zeros( ) , usize :: BITS - 1 ) ;
146
-
147
- assert_eq ! ( NonZeroU8 :: new( u8 :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
148
- assert_eq ! ( NonZeroI8 :: new( ( u8 :: MAX >> 2 ) as i8 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
149
- assert_eq ! ( NonZeroU16 :: new( u16 :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
150
- assert_eq ! ( NonZeroI16 :: new( ( u16 :: MAX >> 2 ) as i16 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
151
- assert_eq ! ( NonZeroU32 :: new( u32 :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
152
- assert_eq ! ( NonZeroI32 :: new( ( u32 :: MAX >> 2 ) as i32 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
153
- assert_eq ! ( NonZeroU64 :: new( u64 :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
154
- assert_eq ! ( NonZeroI64 :: new( ( u64 :: MAX >> 2 ) as i64 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
155
-
156
134
/*
157
135
//let mut num = u128::MAX >> 20;
158
136
//let mut num = u128::MAX;
@@ -177,24 +155,53 @@ fn main() {
177
155
}
178
156
println!();
179
157
*/
180
- assert_eq ! ( NonZeroU128 :: new( u128 :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
181
- assert_eq ! ( NonZeroI128 :: new( ( u128 :: MAX >> 2 ) as i128 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
182
- assert_eq ! ( NonZeroUsize :: new( usize :: MAX >> 2 ) . unwrap( ) . leading_zeros( ) , 2 ) ;
183
- assert_eq ! ( NonZeroIsize :: new( ( usize :: MAX >> 2 ) as isize ) . unwrap( ) . leading_zeros( ) , 2 ) ;
184
-
185
- assert_eq ! ( NonZeroU8 :: new( u8 :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
186
- assert_eq ! ( NonZeroI8 :: new( -1i8 ) . unwrap( ) . leading_zeros( ) , 0 ) ;
187
- assert_eq ! ( NonZeroU16 :: new( u16 :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
188
- assert_eq ! ( NonZeroI16 :: new( -1i16 ) . unwrap( ) . leading_zeros( ) , 0 ) ;
189
- assert_eq ! ( NonZeroU32 :: new( u32 :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
190
- assert_eq ! ( NonZeroI32 :: new( -1i32 ) . unwrap( ) . leading_zeros( ) , 0 ) ;
191
- assert_eq ! ( NonZeroU64 :: new( u64 :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
192
- assert_eq ! ( NonZeroI64 :: new( -1i64 ) . unwrap( ) . leading_zeros( ) , 0 ) ;
193
- assert_eq ! ( NonZeroU128 :: new( u128 :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
194
- assert_eq ! ( NonZeroI128 :: new( -1i128 ) . unwrap( ) . leading_zeros( ) , 0 ) ;
195
- assert_eq ! ( NonZeroUsize :: new( usize :: MAX ) . unwrap( ) . leading_zeros( ) , 0 ) ;
196
- assert_eq ! ( NonZeroIsize :: new( -1isize ) . unwrap( ) . leading_zeros( ) , 0 ) ;
197
-
198
- const LEADING_ZEROS : u32 = NonZeroU16 :: new ( 1 ) . unwrap ( ) . leading_zeros ( ) ;
199
- assert_eq ! ( LEADING_ZEROS , 15 ) ;
158
+
159
+ assert_eq ! ( NonZeroU8 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
160
+ assert_eq ! ( NonZeroI8 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
161
+ assert_eq ! ( NonZeroU16 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
162
+ assert_eq ! ( NonZeroI16 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
163
+ assert_eq ! ( NonZeroU32 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
164
+ assert_eq ! ( NonZeroI32 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
165
+ assert_eq ! ( NonZeroU64 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
166
+ assert_eq ! ( NonZeroI64 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
167
+ assert_eq ! ( NonZeroU128 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
168
+ assert_eq ! ( NonZeroI128 :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
169
+ assert_eq ! ( NonZeroUsize :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
170
+ assert_eq ! ( NonZeroIsize :: new( 1 ) . unwrap( ) . trailing_zeros( ) , 0 ) ;
171
+
172
+ assert_eq ! ( NonZeroU8 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
173
+ assert_eq ! ( NonZeroI8 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
174
+ assert_eq ! ( NonZeroU16 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
175
+ assert_eq ! ( NonZeroI16 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
176
+ assert_eq ! ( NonZeroU32 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
177
+ assert_eq ! ( NonZeroI32 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
178
+ assert_eq ! ( NonZeroU64 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
179
+ assert_eq ! ( NonZeroI64 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
180
+ assert_eq ! ( NonZeroU128 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
181
+ assert_eq ! ( NonZeroI128 :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
182
+ assert_eq ! ( NonZeroUsize :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
183
+ assert_eq ! ( NonZeroIsize :: new( 1 << 2 ) . unwrap( ) . trailing_zeros( ) , 2 ) ;
184
+
185
+ assert_eq ! ( NonZeroU8 :: new( 1 << 7 ) . unwrap( ) . trailing_zeros( ) , 7 ) ;
186
+ assert_eq ! ( NonZeroI8 :: new( 1 << 7 ) . unwrap( ) . trailing_zeros( ) , 7 ) ;
187
+ assert_eq ! ( NonZeroU16 :: new( 1 << 15 ) . unwrap( ) . trailing_zeros( ) , 15 ) ;
188
+ assert_eq ! ( NonZeroI16 :: new( 1 << 15 ) . unwrap( ) . trailing_zeros( ) , 15 ) ;
189
+ assert_eq ! ( NonZeroU32 :: new( 1 << 31 ) . unwrap( ) . trailing_zeros( ) , 31 ) ;
190
+ assert_eq ! ( NonZeroI32 :: new( 1 << 31 ) . unwrap( ) . trailing_zeros( ) , 31 ) ;
191
+ assert_eq ! ( NonZeroU64 :: new( 1 << 63 ) . unwrap( ) . trailing_zeros( ) , 63 ) ;
192
+ assert_eq ! ( NonZeroI64 :: new( 1 << 63 ) . unwrap( ) . trailing_zeros( ) , 63 ) ;
193
+ assert_eq ! ( NonZeroU128 :: new( 1 << 127 ) . unwrap( ) . trailing_zeros( ) , 127 ) ;
194
+ assert_eq ! ( NonZeroI128 :: new( 1 << 127 ) . unwrap( ) . trailing_zeros( ) , 127 ) ;
195
+
196
+ assert_eq ! (
197
+ NonZeroUsize :: new( 1 << ( usize :: BITS - 1 ) ) . unwrap( ) . trailing_zeros( ) ,
198
+ usize :: BITS - 1
199
+ ) ;
200
+ assert_eq ! (
201
+ NonZeroIsize :: new( 1 << ( usize :: BITS - 1 ) ) . unwrap( ) . trailing_zeros( ) ,
202
+ usize :: BITS - 1
203
+ ) ;
204
+
205
+ const TRAILING_ZEROS : u32 = NonZeroU16 :: new ( 1 << 2 ) . unwrap ( ) . trailing_zeros ( ) ;
206
+ assert_eq ! ( TRAILING_ZEROS , 2 ) ;
200
207
}
0 commit comments