soroban_env_common::num

Trait 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§