Posit

Struct Posit 

Source
pub struct Posit<const N: u32, const ES: u32, Int: Int>(/* private fields */);
Expand description

A posit floating point number with N bits and ES exponent bits, using Int as its underlying type.

§Examples:

type Foo = Posit::<32, 2, i32>;  // A 32-bit posit with 2-bit exponent field, represented in a
                                 // 32-bit machine type
type Bar = Posit::<6, 1, i8>;  // A 6-bit posit with 1-bit exponent field, represented in an
                               // 8-bit machine type.

Type aliases are provided at the crate root for the posit types defined in the standard.

Implementations§

Source§

impl<const N: u32, const ES: u32, Int: Int> Posit<N, ES, Int>

Source

pub const BITS: u32

The size of this Posit type in bits.

Note: this is the logical size, not necessarily the size of the underlying type.

Source

pub const ES: u32

The number of exponent bits.

Source

pub fn from_bits(x: Int) -> Self

Construct a posit from its raw bit representation. Bits higher (more significant) than the lowest N (Self::BITS) bits, if any, are ignored.

Source

pub const unsafe fn from_bits_unchecked(x: Int) -> Self

As Self::from_bits, but if x is not a result of a Self::to_bits call, then calling this function is undefined behaviour.

Source

pub const fn to_bits(self) -> Int

Return the underlying bit representation of self as a machine int. Bits higher (more significant) than the lowest N (Self::BITS) bits, if any, are set as equal to the N-1th bit (i.e. sign-extended).

Source§

impl<const N: u32, const ES: u32, Int: Int> Posit<N, ES, Int>

Source

pub const ZERO: Self

Zero (0), the additive identity element.

Source

pub const NAR: Self

Not-a-real (NaR).

Source

pub const ONE: Self

One (1), the additive identity element.

Source

pub const MINUS_ONE: Self

Negative one (-1).

Source

pub const MAX: Self

Largest representable value, equal to -MIN.

Source

pub const MIN: Self

Smallest representable value, equal to -MAX.

Not to be confused with the smallest absolute value, i.e. Self::MIN_POSITIVE.

Source

pub const MIN_POSITIVE: Self

Smallest positive value, equal to -MAX_NEGATIVE.

Source

pub const MAX_NEGATIVE: Self

Largest negative value, equal to -MIN_POSITIVE.

Source

pub const MIN_EXP: Int

The minimum exponent; Self::MIN_POSITIVE = 2 Self::MIN_EXP.

Source

pub const MAX_EXP: Int

The maximum exponent; Self::MAX_NEGATIVE = 2 Self::MAX_EXP.

Source§

impl<const N: u32, const ES: u32, Int: Int> Posit<N, ES, Int>

Source

pub fn next(self) -> Self

Returns the posit value of the lexicographic successor of self’s representation.

Standard: “next”.

Source

pub fn prior(self) -> Self

Returns the posit value of the lexicographic predecessor of self’s representation.

Standard: “prior”.

Trait Implementations§

Source§

impl<const N: u32, const ES: u32, Int: Int> Add<&Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Posit<N, ES, Int>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Add<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Add<Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Posit<N, ES, Int>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Add for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> AddAssign<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

fn add_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the += operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

fn add_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the += operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

fn add_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the += operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> AddAssign for Posit<N, ES, Int>

Source§

fn add_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the += operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Clone + Int> Clone for Posit<N, ES, Int>

Source§

fn clone(&self) -> Posit<N, ES, Int>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Debug for Posit<N, ES, Int>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: u32, const ES: u32, Int: Default + Int> Default for Posit<N, ES, Int>

Source§

fn default() -> Posit<N, ES, Int>

Returns the “default value” for a type. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Div<&Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Posit<N, ES, Int>) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Div<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Div<Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Posit<N, ES, Int>) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Div for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> DivAssign<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

fn div_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the /= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> DivAssign for Posit<N, ES, Int>

Source§

fn div_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the /= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> From<Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

fn from(value: Posit<N, ES, Int>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32, const ES: u32, Int: Hash + Int> Hash for Posit<N, ES, Int>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Mul<&Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Posit<N, ES, Int>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Mul<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Mul<Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Posit<N, ES, Int>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Mul for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> MulAssign<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

fn mul_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the *= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> MulAssign for Posit<N, ES, Int>

Source§

fn mul_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the *= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Neg for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Neg for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Ord + Int> Ord for Posit<N, ES, Int>

Source§

fn cmp(&self, other: &Posit<N, ES, Int>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: u32, const ES: u32, Int: PartialEq + Int> PartialEq for Posit<N, ES, Int>

Source§

fn eq(&self, other: &Posit<N, ES, Int>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: u32, const ES: u32, Int: PartialOrd + Int> PartialOrd for Posit<N, ES, Int>

Source§

fn partial_cmp(&self, other: &Posit<N, ES, Int>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<f32> for Posit<N, ES, Int>

Source§

fn round_from(value: f32) -> Self

Convert an f32 into a Posit, rounding according to the standard:

  • If the value is any infinity or any NaN, it converts to NaR.
  • Otherwise, the float value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<f64> for Posit<N, ES, Int>

Source§

fn round_from(value: f64) -> Self

Convert an f64 into a Posit, rounding according to the standard:

  • If the value is any infinity or any NaN, it converts to NaR.
  • Otherwise, the float value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<i128> for Posit<N, ES, Int>

Source§

fn round_from(value: i128) -> Self

Convert an i128 into a Posit, rounding according to the standard:

  • If the value is i128::MIN (i.e. the value where the most significant bit is 1 and the rest are 0), it converts to NaR.
  • Otherwise, the integer value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<i16> for Posit<N, ES, Int>

Source§

fn round_from(value: i16) -> Self

Convert an i16 into a Posit, rounding according to the standard:

  • If the value is i16::MIN (i.e. the value where the most significant bit is 1 and the rest are 0), it converts to NaR.
  • Otherwise, the integer value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<i32> for Posit<N, ES, Int>

Source§

fn round_from(value: i32) -> Self

Convert an i32 into a Posit, rounding according to the standard:

  • If the value is i32::MIN (i.e. the value where the most significant bit is 1 and the rest are 0), it converts to NaR.
  • Otherwise, the integer value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<i64> for Posit<N, ES, Int>

Source§

fn round_from(value: i64) -> Self

Convert an i64 into a Posit, rounding according to the standard:

  • If the value is i64::MIN (i.e. the value where the most significant bit is 1 and the rest are 0), it converts to NaR.
  • Otherwise, the integer value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> RoundFrom<i8> for Posit<N, ES, Int>

Source§

fn round_from(value: i8) -> Self

Convert an i8 into a Posit, rounding according to the standard:

  • If the value is i8::MIN (i.e. the value where the most significant bit is 1 and the rest are 0), it converts to NaR.
  • Otherwise, the integer value is rounded (if necessary).
Source§

impl<const N: u32, const ES: u32, Int: Int> Sub<&Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Posit<N, ES, Int>) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Sub<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Sub<Posit<N, ES, Int>> for &Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Posit<N, ES, Int>) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> Sub for Posit<N, ES, Int>

Source§

type Output = Posit<N, ES, Int>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> SubAssign<&Posit<N, ES, Int>> for Posit<N, ES, Int>

Source§

fn sub_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the -= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> SubAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

fn sub_assign(&mut self, rhs: &Posit<N, ES, Int>)

Performs the -= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> SubAssign<Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

fn sub_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the -= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Int> SubAssign for Posit<N, ES, Int>

Source§

fn sub_assign(&mut self, rhs: Posit<N, ES, Int>)

Performs the -= operation. Read more
Source§

impl<const N: u32, const ES: u32, Int: Copy + Int> Copy for Posit<N, ES, Int>

Source§

impl<const N: u32, const ES: u32, Int: Eq + Int> Eq for Posit<N, ES, Int>

Source§

impl<const N: u32, const ES: u32, Int: Int> StructuralPartialEq for Posit<N, ES, Int>

Auto Trait Implementations§

§

impl<const N: u32, const ES: u32, Int> Freeze for Posit<N, ES, Int>
where Int: Freeze,

§

impl<const N: u32, const ES: u32, Int> RefUnwindSafe for Posit<N, ES, Int>
where Int: RefUnwindSafe,

§

impl<const N: u32, const ES: u32, Int> Send for Posit<N, ES, Int>
where Int: Send,

§

impl<const N: u32, const ES: u32, Int> Sync for Posit<N, ES, Int>
where Int: Sync,

§

impl<const N: u32, const ES: u32, Int> Unpin for Posit<N, ES, Int>
where Int: Unpin,

§

impl<const N: u32, const ES: u32, Int> UnwindSafe for Posit<N, ES, Int>
where Int: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RoundFrom<T> for T

Source§

fn round_from(value: T) -> T

Converts to this type from the input type, rounding according to the posit standard if necessary (round to nearest, ties to even, never over- or under-flow). Read more
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Converts this type into the (usually inferred) input type, rounding according to the posit standard if necessary (round to nearest, ties to even, never over- or under-flow). Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.