| 1 | use easy_castrust-analyzer cargo easy-cast 0.4.4 crate/::*; |
| 2 | |
| 3 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4 | fn int_castsrust-analyzer cargo easy-cast 0.4.4 int_casts().() { |
| 5 | let a: i32 = 213; |
| 6 | let b: u128 = a.castrust-analyzer cargo easy-cast 0.4.4 impl#[S][`Cast<T>`]cast().(); |
| 7 | let c = u8::convrust-analyzer cargo easy-cast 0.4.4 impl#[u8][`Conv<u128>`]conv().(b); |
| 8 | let d = c.castrust-analyzer cargo easy-cast 0.4.4 impl#[S][`Cast<T>`]cast().(); |
| 9 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(a, d); |
| 10 | } |
| 11 | |
| 12 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 13 | fn signed_to_unsignedrust-analyzer cargo easy-cast 0.4.4 signed_to_unsigned().() { |
| 14 | u32::convrust-analyzer cargo easy-cast 0.4.4 impl#[u32][`Conv<i32>`]conv().(0i32); |
| 15 | u32::convrust-analyzer cargo easy-cast 0.4.4 impl#[u32][`Conv<i32>`]conv().(1i32); |
| 16 | u32::convrust-analyzer cargo easy-cast 0.4.4 impl#[u32][`Conv<i32>`]conv().(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::i32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/i32/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/i32/MAX.); |
| 17 | } |
| 18 | |
| 19 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 20 | #[should_panic] |
| 21 | fn signed_to_unsigned_n1rust-analyzer cargo easy-cast 0.4.4 signed_to_unsigned_n1().() { |
| 22 | u32::convrust-analyzer cargo easy-cast 0.4.4 impl#[u32][`Conv<i32>`]conv().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1i32); |
| 23 | } |
| 24 | |
| 25 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 26 | fn unsigned_to_signedrust-analyzer cargo easy-cast 0.4.4 unsigned_to_signed().() { |
| 27 | i32::convrust-analyzer cargo easy-cast 0.4.4 impl#[i32][`Conv<u32>`]conv().(0u32); |
| 28 | i32::convrust-analyzer cargo easy-cast 0.4.4 impl#[i32][`Conv<u32>`]conv().(1u32); |
| 29 | i16::convrust-analyzer cargo easy-cast 0.4.4 impl#[i16][`Conv<usize>`]conv().(1usize); |
| 30 | } |
| 31 | |
| 32 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 33 | #[should_panic] |
| 34 | fn unsigned_to_signed_largerust-analyzer cargo easy-cast 0.4.4 unsigned_to_signed_large().() { |
| 35 | i32::convrust-analyzer cargo easy-cast 0.4.4 impl#[i32][`Conv<u32>`]conv().(0x8000_0000u32); |
| 36 | } |
| 37 | |
| 38 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 39 | fn int_to_floatrust-analyzer cargo easy-cast 0.4.4 int_to_float().() { |
| 40 | f32::convrust-analyzer cargo easy-cast 0.4.4 impl#[f32][`Conv<i32>`]conv().(0); |
| 41 | f32::convrust-analyzer cargo easy-cast 0.4.4 impl#[f32][`Conv<i32>`]conv().(0x00FF_FFFF); |
| 42 | f32::convrust-analyzer cargo easy-cast 0.4.4 impl#[f32][`Conv<i32>`]conv().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().64i32); |
| 43 | } |
| 44 | |
| 45 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 46 | #[should_panic] |
| 47 | fn int_to_float_inexactrust-analyzer cargo easy-cast 0.4.4 int_to_float_inexact().() { |
| 48 | f32::convrust-analyzer cargo easy-cast 0.4.4 impl#[f32][`Conv<i32>`]conv().(0x01FF_FFFF); |
| 49 | } |
| 50 | |
| 51 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 52 | #[cfg(any(feature = "std", feature = "libm"))] |
| 53 | fn float_castsrust-analyzer cargo easy-cast 0.4.4 float_casts().() { |
| 54 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(u64::conv_nearestrust-analyzer cargo easy-cast 0.4.4 impl#[u64][`ConvFloat<f32>`]conv_nearest().(13.2f32), 13); |
| 55 | let x: i128 = 13.5f32.cast_nearestrust-analyzer cargo easy-cast 0.4.4 impl#[S][`CastFloat<T>`]cast_nearest().(); |
| 56 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(x, 14); |
| 57 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(u8::conv_floorrust-analyzer cargo easy-cast 0.4.4 impl#[u8][`ConvFloat<f64>`]conv_floor().(13.8f64), 13); |
| 58 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(u32::conv_ceilrust-analyzer cargo easy-cast 0.4.4 impl#[u32][`ConvFloat<f32>`]conv_ceil().(13.1f32), 14); |
| 59 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i64::conv_floorrust-analyzer cargo easy-cast 0.4.4 impl#[i64][`ConvFloat<f64>`]conv_floor().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3168565.13), -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().3168566); |
| 60 | } |
| 61 | |
| 62 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 63 | #[cfg(any(feature = "std", feature = "libm"))] |
| 64 | fn float_truncrust-analyzer cargo easy-cast 0.4.4 float_trunc().() { |
| 65 | let xx = [-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().32768.0f32, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().32768.99, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().0.99, 0.99, 32767.99]; |
| 66 | let yy = [-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().32768i16, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().32768, 0, 0, 32767]; |
| 67 | for (x, y) in xx[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(yy[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) { |
| 68 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i16::conv_truncrust-analyzer cargo easy-cast 0.4.4 impl#[i16][`ConvFloat<f32>`]conv_trunc().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().x), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().y); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 73 | #[should_panic] |
| 74 | #[cfg(any(feature = "std", feature = "libm"))] |
| 75 | fn float_trunc_fail1rust-analyzer cargo easy-cast 0.4.4 float_trunc_fail1().() { |
| 76 | i16::conv_truncrust-analyzer cargo easy-cast 0.4.4 impl#[i16][`ConvFloat<f32>`]conv_trunc().(32768.0f32); |
| 77 | } |
| 78 | |
| 79 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 80 | #[should_panic] |
| 81 | fn u32_max_f32rust-analyzer cargo easy-cast 0.4.4 u32_max_f32().() { |
| 82 | f32::convrust-analyzer cargo easy-cast 0.4.4 impl#[f32][`Conv<u32>`]conv().(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u32/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u32/MAX.); |
| 83 | } |