File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ jobs:
142142 runs-on : ubuntu-latest
143143 steps :
144144 - uses : actions/checkout@v3
145- - uses : EmbarkStudios/cargo-deny-action@v1
145+ - uses : EmbarkStudios/cargo-deny-action@v2
146146 with :
147147 command : check license
148148
Original file line number Diff line number Diff line change @@ -29,3 +29,4 @@ private/
2929/perf. *
3030/flamegraph.svg
3131
32+ .DS_Store
Original file line number Diff line number Diff line change @@ -234,12 +234,12 @@ impl NInt for i16 {
234234
235235 #[ inline]
236236 fn add_i64 ( self , i : i64 ) -> Option < Self > {
237- i . try_into ( ) . ok ( ) . and_then ( |i| self . checked_add ( i ) )
237+ self . as_i64 ( ) . checked_add ( i ) . and_then ( |v| v . try_into ( ) . ok ( ) )
238238 }
239239
240240 #[ inline]
241241 fn sub_i64 ( self , i : i64 ) -> Option < Self > {
242- i . try_into ( ) . ok ( ) . and_then ( |i| self . checked_sub ( i ) )
242+ self . as_i64 ( ) . checked_sub ( i ) . and_then ( |v| v . try_into ( ) . ok ( ) )
243243 }
244244
245245 #[ inline]
@@ -268,12 +268,12 @@ impl NInt for i32 {
268268
269269 #[ inline]
270270 fn add_i64 ( self , i : i64 ) -> Option < Self > {
271- i . try_into ( ) . ok ( ) . and_then ( |i| self . checked_add ( i ) )
271+ self . as_i64 ( ) . checked_add ( i ) . and_then ( |v| v . try_into ( ) . ok ( ) )
272272 }
273273
274274 #[ inline]
275275 fn sub_i64 ( self , i : i64 ) -> Option < Self > {
276- i . try_into ( ) . ok ( ) . and_then ( |i| self . checked_sub ( i ) )
276+ self . as_i64 ( ) . checked_sub ( i ) . and_then ( |v| v . try_into ( ) . ok ( ) )
277277 }
278278
279279 #[ inline]
Original file line number Diff line number Diff line change @@ -286,4 +286,30 @@ mod tests {
286286 }
287287 assert_eq ! ( expected, out) ;
288288 }
289+
290+ #[ test]
291+ fn test_i32_add_sub_i64 ( ) {
292+ let v = i32:: MIN ;
293+ let i = ( i32:: MAX as i64 ) * 2 ;
294+ let add_result = v. add_i64 ( i) ;
295+ assert_eq ! ( add_result, Some ( 2147483646 ) ) ;
296+
297+ let v = i32:: MIN ;
298+ let i = -( i32:: MAX as i64 ) * 2 ;
299+ let sub_result = v. sub_i64 ( i) ;
300+ assert_eq ! ( sub_result, Some ( 2147483646 ) ) ;
301+ }
302+
303+ #[ test]
304+ fn test_i16_add_sub_i64 ( ) {
305+ let v = i16:: MIN ;
306+ let i = ( i16:: MAX as i64 ) * 2 ;
307+ let add_result = v. add_i64 ( i) ;
308+ assert_eq ! ( add_result, Some ( 32766i16 ) ) ;
309+
310+ let v = i16:: MIN ;
311+ let i = -( i16:: MAX as i64 ) * 2 ;
312+ let sub_result = v. sub_i64 ( i) ;
313+ assert_eq ! ( sub_result, Some ( 32766i16 ) ) ;
314+ }
289315}
You can’t perform that action at this time.
0 commit comments