pub struct FloatConv(/* private fields */);Expand description
The modifier byte of Inst::F32ToInt and
Inst::F64ToInt: the destination integer type
and the float_to_int policy for NaN and out-of-range values.
Layout: bits 0–2 the destination IntTy, bit 3 FloatToInt; bits
4–7 are zero.
§Examples
use bytecode_lang::{FloatConv, FloatToInt, IntTy};
let c = FloatConv::new(IntTy::I32).with_float_to_int(FloatToInt::Saturate);
assert_eq!((c.ty(), c.float_to_int()), (IntTy::I32, FloatToInt::Saturate));
assert_eq!(c.to_string(), "i32.sat");
assert_eq!(FloatConv::from_bits(c.bits()), Some(c));
assert_eq!(FloatConv::from_bits(0b1_0000), None);Implementations§
Source§impl FloatConv
impl FloatConv
Sourcepub const fn new(ty: IntTy) -> Self
pub const fn new(ty: IntTy) -> Self
A conversion to ty with the default policy (float_to_int = error).
§Examples
use bytecode_lang::{FloatConv, IntTy};
assert_eq!(FloatConv::new(IntTy::U8).to_string(), "u8");Sourcepub const fn with_float_to_int(self, float_to_int: FloatToInt) -> Self
pub const fn with_float_to_int(self, float_to_int: FloatToInt) -> Self
This conversion with its float_to_int policy replaced.
§Examples
use bytecode_lang::{FloatConv, FloatToInt, IntTy};
let c = FloatConv::new(IntTy::I64).with_float_to_int(FloatToInt::Saturate);
assert_eq!(c.float_to_int(), FloatToInt::Saturate);Sourcepub const fn with_policy(self, policy: Policy) -> Self
pub const fn with_policy(self, policy: Policy) -> Self
This conversion with the float_to_int part of policy (the one
policy a float-to-integer conversion consults), so a code generator
can stamp its language’s Policy everywhere.
§Examples
use bytecode_lang::{FloatConv, FloatToInt, IntTy, Policy};
let p = Policy::new().with_float_to_int(FloatToInt::Saturate);
assert_eq!(FloatConv::new(IntTy::I8).with_policy(p).to_string(), "i8.sat");Sourcepub const fn ty(self) -> IntTy
pub const fn ty(self) -> IntTy
The destination integer type.
§Examples
use bytecode_lang::{FloatConv, IntTy};
assert_eq!(FloatConv::new(IntTy::U16).ty(), IntTy::U16);Sourcepub const fn float_to_int(self) -> FloatToInt
pub const fn float_to_int(self) -> FloatToInt
The float_to_int policy.
§Examples
use bytecode_lang::{FloatConv, FloatToInt, IntTy};
assert_eq!(FloatConv::new(IntTy::I8).float_to_int(), FloatToInt::Error);Trait Implementations§
impl Copy for FloatConv
impl Eq for FloatConv
Source§impl Ord for FloatConv
impl Ord for FloatConv
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for FloatConv
impl PartialOrd for FloatConv
impl StructuralPartialEq for FloatConv
Auto Trait Implementations§
impl Freeze for FloatConv
impl RefUnwindSafe for FloatConv
impl Send for FloatConv
impl Sync for FloatConv
impl Unpin for FloatConv
impl UnsafeUnpin for FloatConv
impl UnwindSafe for FloatConv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more