Trait softfloat_wrapper::Float[][src]

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;

    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_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; 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
, { ... } }

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);

Associated Types

Loading content...

Associated Constants

Loading content...

Required methods

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

fn from_bits(v: Self::Payload) -> Self[src]

fn to_bits(&self) -> Self::Payload[src]

fn bits(&self) -> Self::Payload[src]

👎 Deprecated since 0.3.0:

Please use to_bits instead

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

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

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

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

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

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

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

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

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

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

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

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

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

fn is_signaling_nan(&self) -> bool[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading content...

Provided methods

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

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

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

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

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

fn neg(&self) -> Self where
    Self: Sized
[src]

fn abs(&self) -> Self where
    Self: Sized
[src]

fn sign(&self) -> Self::Payload[src]

fn exponent(&self) -> Self::Payload[src]

fn fraction(&self) -> Self::Payload[src]

fn is_positive(&self) -> bool[src]

fn is_positive_zero(&self) -> bool[src]

fn is_positive_subnormal(&self) -> bool[src]

fn is_positive_normal(&self) -> bool[src]

fn is_positive_infinity(&self) -> bool[src]

fn is_negative(&self) -> bool[src]

fn is_negative_zero(&self) -> bool[src]

fn is_negative_subnormal(&self) -> bool[src]

fn is_negative_normal(&self) -> bool[src]

fn is_negative_infinity(&self) -> bool[src]

fn is_nan(&self) -> bool[src]

fn is_zero(&self) -> bool[src]

fn is_subnormal(&self) -> bool[src]

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

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

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

fn positive_infinity() -> Self where
    Self: Sized
[src]

fn positive_zero() -> Self where
    Self: Sized
[src]

fn negative_infinity() -> Self where
    Self: Sized
[src]

fn negative_zero() -> Self where
    Self: Sized
[src]

fn quiet_nan() -> Self where
    Self: Sized
[src]

Loading content...

Implementors

impl Float for F16[src]

type Payload = u16

impl Float for F32[src]

type Payload = u32

impl Float for F64[src]

type Payload = u64

impl Float for F128[src]

type Payload = u128

Loading content...