Trait ethnum::AsI256

source ·
pub trait AsI256 {
    // Required method
    fn as_i256(self) -> I256;
}
Expand description

This trait defines as conversions (casting) from primitive types to I256.

Examples

Casting a floating point value to an integer is a saturating operation, with NaN converting to 0. So:

assert_eq!((-1i32).as_i256(), -I256::ONE);
assert_eq!(u32::MAX.as_i256(), 0xffffffff);

assert_eq!(-13.37f64.as_i256(), -13);
assert_eq!(42.0f64.as_i256(), 42);
assert_eq!(
    f32::MAX.as_i256(),
    0xffffff00000000000000000000000000u128.as_i256(),
);
assert_eq!(
    f32::MIN.as_i256(),
    -0xffffff00000000000000000000000000u128.as_i256(),
);

assert_eq!(f64::NEG_INFINITY.as_i256(), I256::MIN);
assert_eq!((-2.0f64.powi(256)).as_i256(), I256::MIN);
assert_eq!(f64::INFINITY.as_i256(), I256::MAX);
assert_eq!(2.0f64.powi(256).as_i256(), I256::MAX);
assert_eq!(f64::NAN.as_i256(), 0);

Required Methods§

source

fn as_i256(self) -> I256

Perform an as conversion to a I256.

Implementations on Foreign Types§

source§

impl AsI256 for bool

source§

fn as_i256(self) -> I256

source§

impl AsI256 for f32

source§

fn as_i256(self) -> I256

source§

impl AsI256 for f64

source§

fn as_i256(self) -> I256

source§

impl AsI256 for i8

source§

fn as_i256(self) -> I256

source§

impl AsI256 for i16

source§

fn as_i256(self) -> I256

source§

impl AsI256 for i32

source§

fn as_i256(self) -> I256

source§

impl AsI256 for i64

source§

fn as_i256(self) -> I256

source§

impl AsI256 for i128

source§

fn as_i256(self) -> I256

source§

impl AsI256 for isize

source§

fn as_i256(self) -> I256

source§

impl AsI256 for u8

source§

fn as_i256(self) -> I256

source§

impl AsI256 for u16

source§

fn as_i256(self) -> I256

source§

impl AsI256 for u32

source§

fn as_i256(self) -> I256

source§

impl AsI256 for u64

source§

fn as_i256(self) -> I256

source§

impl AsI256 for u128

source§

fn as_i256(self) -> I256

source§

impl AsI256 for usize

source§

fn as_i256(self) -> I256

Implementors§