pub trait AsI256 {
    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

Perform an as conversion to a I256.

Implementations on Foreign Types

Implementors