Trait Float

Source
pub trait Float {
    type Payload: PrimInt + UpperHex + LowerHex;

    const EXPONENT_BIT: Self::Payload;
    const FRACTION_BIT: Self::Payload;
    const SIGN_POS: usize;
    const EXPONENT_POS: usize;
Show 63 methods // Required methods fn set_payload(&mut self, x: Self::Payload); fn from_bits(v: Self::Payload) -> Self; fn to_bits(&self) -> Self::Payload; fn bits(&self) -> Self::Payload; fn add<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self; fn sub<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self; fn mul<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self; fn fused_mul_add<T: Borrow<Self>>( &self, x: T, y: T, rnd: RoundingMode, ) -> Self; fn div<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self; fn rem<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self; fn sqrt(&self, rnd: RoundingMode) -> Self; fn eq<T: Borrow<Self>>(&self, x: T) -> bool; fn lt<T: Borrow<Self>>(&self, x: T) -> bool; fn le<T: Borrow<Self>>(&self, x: T) -> bool; fn lt_quiet<T: Borrow<Self>>(&self, x: T) -> bool; fn le_quiet<T: Borrow<Self>>(&self, x: T) -> bool; fn eq_signaling<T: Borrow<Self>>(&self, x: T) -> bool; fn is_signaling_nan(&self) -> bool; fn from_u32(x: u32, rnd: RoundingMode) -> Self; fn from_u64(x: u64, rnd: RoundingMode) -> Self; fn from_i32(x: i32, rnd: RoundingMode) -> Self; fn from_i64(x: i64, rnd: RoundingMode) -> Self; fn to_u32(&self, rnd: RoundingMode, exact: bool) -> u32; fn to_u64(&self, rnd: RoundingMode, exact: bool) -> u64; fn to_i32(&self, rnd: RoundingMode, exact: bool) -> i32; fn to_i64(&self, rnd: RoundingMode, exact: bool) -> i64; fn to_f16(&self, rnd: RoundingMode) -> F16; fn to_bf16(&self, rnd: RoundingMode) -> BF16; fn to_f32(&self, rnd: RoundingMode) -> F32; fn to_f64(&self, rnd: RoundingMode) -> F64; fn to_f128(&self, rnd: RoundingMode) -> F128; fn round_to_integral(&self, rnd: RoundingMode) -> Self; // Provided methods fn compare<T: Borrow<Self>>(&self, x: T) -> Option<Ordering> { ... } fn from_u8(x: u8, rnd: RoundingMode) -> Self where Self: Sized { ... } fn from_u16(x: u16, rnd: RoundingMode) -> Self where Self: Sized { ... } fn from_i8(x: i8, rnd: RoundingMode) -> Self where Self: Sized { ... } fn from_i16(x: i16, rnd: RoundingMode) -> Self where Self: Sized { ... } fn neg(&self) -> Self where Self: Sized { ... } fn abs(&self) -> Self where Self: Sized { ... } fn sign(&self) -> Self::Payload { ... } fn exponent(&self) -> Self::Payload { ... } fn fraction(&self) -> Self::Payload { ... } fn is_positive(&self) -> bool { ... } fn is_positive_zero(&self) -> bool { ... } fn is_positive_subnormal(&self) -> bool { ... } fn is_positive_normal(&self) -> bool { ... } fn is_positive_infinity(&self) -> bool { ... } fn is_negative(&self) -> bool { ... } fn is_negative_zero(&self) -> bool { ... } fn is_negative_subnormal(&self) -> bool { ... } fn is_negative_normal(&self) -> bool { ... } fn is_negative_infinity(&self) -> bool { ... } fn is_nan(&self) -> bool { ... } fn is_zero(&self) -> bool { ... } fn is_subnormal(&self) -> bool { ... } fn set_sign(&mut self, x: Self::Payload) { ... } fn set_exponent(&mut self, x: Self::Payload) { ... } fn set_fraction(&mut self, x: Self::Payload) { ... } fn positive_infinity() -> Self where Self: Sized { ... } fn positive_zero() -> Self where Self: Sized { ... } fn negative_infinity() -> Self where Self: Sized { ... } fn negative_zero() -> Self where Self: Sized { ... } fn quiet_nan() -> Self where Self: Sized { ... }
}
Expand description

arbitrary floting-point type

§Examples

Float can be used for generic functions.

use softfloat_wrapper::{Float, RoundingMode, F16, F32};

fn rsqrt<T: Float>(x: T) -> T {
    let ret = x.sqrt(RoundingMode::TiesToEven);
    let one = T::from_u8(1, RoundingMode::TiesToEven);
    one.div(ret, RoundingMode::TiesToEven)
}

let a = F16::from_bits(0x1234);
let a = rsqrt(a);
let a = F32::from_bits(0x12345678);
let a = rsqrt(a);

Required Associated Constants§

Required Associated Types§

Required Methods§

Source

fn set_payload(&mut self, x: Self::Payload)

Source

fn from_bits(v: Self::Payload) -> Self

Source

fn to_bits(&self) -> Self::Payload

Source

fn bits(&self) -> Self::Payload

👎Deprecated since 0.3.0: Please use to_bits instead
Source

fn add<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self

Source

fn sub<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self

Source

fn mul<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self

Source

fn fused_mul_add<T: Borrow<Self>>(&self, x: T, y: T, rnd: RoundingMode) -> Self

Source

fn div<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self

Source

fn rem<T: Borrow<Self>>(&self, x: T, rnd: RoundingMode) -> Self

Source

fn sqrt(&self, rnd: RoundingMode) -> Self

Source

fn eq<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn lt<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn le<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn lt_quiet<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn le_quiet<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn eq_signaling<T: Borrow<Self>>(&self, x: T) -> bool

Source

fn is_signaling_nan(&self) -> bool

Source

fn from_u32(x: u32, rnd: RoundingMode) -> Self

Source

fn from_u64(x: u64, rnd: RoundingMode) -> Self

Source

fn from_i32(x: i32, rnd: RoundingMode) -> Self

Source

fn from_i64(x: i64, rnd: RoundingMode) -> Self

Source

fn to_u32(&self, rnd: RoundingMode, exact: bool) -> u32

Source

fn to_u64(&self, rnd: RoundingMode, exact: bool) -> u64

Source

fn to_i32(&self, rnd: RoundingMode, exact: bool) -> i32

Source

fn to_i64(&self, rnd: RoundingMode, exact: bool) -> i64

Source

fn to_f16(&self, rnd: RoundingMode) -> F16

Source

fn to_bf16(&self, rnd: RoundingMode) -> BF16

Source

fn to_f32(&self, rnd: RoundingMode) -> F32

Source

fn to_f64(&self, rnd: RoundingMode) -> F64

Source

fn to_f128(&self, rnd: RoundingMode) -> F128

Source

fn round_to_integral(&self, rnd: RoundingMode) -> Self

Provided Methods§

Source

fn compare<T: Borrow<Self>>(&self, x: T) -> Option<Ordering>

Source

fn from_u8(x: u8, rnd: RoundingMode) -> Self
where Self: Sized,

Source

fn from_u16(x: u16, rnd: RoundingMode) -> Self
where Self: Sized,

Source

fn from_i8(x: i8, rnd: RoundingMode) -> Self
where Self: Sized,

Source

fn from_i16(x: i16, rnd: RoundingMode) -> Self
where Self: Sized,

Source

fn neg(&self) -> Self
where Self: Sized,

Source

fn abs(&self) -> Self
where Self: Sized,

Source

fn sign(&self) -> Self::Payload

Source

fn exponent(&self) -> Self::Payload

Source

fn fraction(&self) -> Self::Payload

Source

fn is_positive(&self) -> bool

Source

fn is_positive_zero(&self) -> bool

Source

fn is_positive_subnormal(&self) -> bool

Source

fn is_positive_normal(&self) -> bool

Source

fn is_positive_infinity(&self) -> bool

Source

fn is_negative(&self) -> bool

Source

fn is_negative_zero(&self) -> bool

Source

fn is_negative_subnormal(&self) -> bool

Source

fn is_negative_normal(&self) -> bool

Source

fn is_negative_infinity(&self) -> bool

Source

fn is_nan(&self) -> bool

Source

fn is_zero(&self) -> bool

Source

fn is_subnormal(&self) -> bool

Source

fn set_sign(&mut self, x: Self::Payload)

Source

fn set_exponent(&mut self, x: Self::Payload)

Source

fn set_fraction(&mut self, x: Self::Payload)

Source

fn positive_infinity() -> Self
where Self: Sized,

Source

fn positive_zero() -> Self
where Self: Sized,

Source

fn negative_infinity() -> Self
where Self: Sized,

Source

fn negative_zero() -> Self
where Self: Sized,

Source

fn quiet_nan() -> Self
where Self: Sized,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Float for BF16

Source§

const EXPONENT_BIT: Self::Payload = {transmute(0x00ff): <bf16::BF16 as Float>::Payload}

Source§

const FRACTION_BIT: Self::Payload = {transmute(0x007f): <bf16::BF16 as Float>::Payload}

Source§

const SIGN_POS: usize = 15usize

Source§

const EXPONENT_POS: usize = 7usize

Source§

type Payload = u16

Source§

impl Float for F16

Source§

const EXPONENT_BIT: Self::Payload = {transmute(0x001f): <f16::F16 as Float>::Payload}

Source§

const FRACTION_BIT: Self::Payload = {transmute(0x03ff): <f16::F16 as Float>::Payload}

Source§

const SIGN_POS: usize = 15usize

Source§

const EXPONENT_POS: usize = 10usize

Source§

type Payload = u16

Source§

impl Float for F32

Source§

const EXPONENT_BIT: Self::Payload = {transmute(0x000000ff): <f32::F32 as Float>::Payload}

Source§

const FRACTION_BIT: Self::Payload = {transmute(0x007fffff): <f32::F32 as Float>::Payload}

Source§

const SIGN_POS: usize = 31usize

Source§

const EXPONENT_POS: usize = 23usize

Source§

type Payload = u32

Source§

impl Float for F64

Source§

const EXPONENT_BIT: Self::Payload = {transmute(0x00000000000007ff): <f64::F64 as Float>::Payload}

Source§

const FRACTION_BIT: Self::Payload = {transmute(0x000fffffffffffff): <f64::F64 as Float>::Payload}

Source§

const SIGN_POS: usize = 63usize

Source§

const EXPONENT_POS: usize = 52usize

Source§

type Payload = u64

Source§

impl Float for F128

Source§

const EXPONENT_BIT: Self::Payload = {transmute(0x00000000000000000000000000007fff): <f128::F128 as Float>::Payload}

Source§

const FRACTION_BIT: Self::Payload = {transmute(0x0000ffffffffffffffffffffffffffff): <f128::F128 as Float>::Payload}

Source§

const SIGN_POS: usize = 127usize

Source§

const EXPONENT_POS: usize = 112usize

Source§

type Payload = u128