Skip to main content

Posit

Struct Posit 

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

A posit floating point number with N bits and ES exponent bits, optionally with a maximum regime size RS (making it a b-posit).

This is a generic type which can be instantiated with any valid combination of parameters (see below). It implements the functions described in the 2022 standard (and more), either via the usual arithmetic operations (addition, negation, comparison, etc) or via named functions. Rounding conversions to and from other types (integers, IEEE floats, etc) are done via the RoundFrom and RoundInto traits, which need to be in scope.

Refer to the documentation for specific items for more detail, examples, and links to the definitions in the 2022 standard, if applicable.

If you are looking for the types prescribed in the 2022 standard, see p8, p16, p32, and p64, which are simply type aliases for Posit<X, 2, iX>.

§Parameters

The N and ES parameters are mandatory, and the RS parameter is optional. The parameter Int is the underlying physical storage used for the posit, which must be one of the primitive types i8 to i128.

If Int = iX, then

  • N, the number of bits, must be in the range 3 ..= X,
  • ES, the number of exponent bits, must be in the range 0 .. N.
  • RS, the maximum number of regime bits, if supplied, must be in the range 1 ..= N, otherwise it will default to N(unbounded).

If any parameter is invalid, a compile-time error will be raised.

§Example

// A 32-bit posit with 2-bit exponent field, represented in a 32-bit machine type.
type Foo = Posit<32, 2, i32>;
// A 6-bit posit with 1-bit exponent field, represented in an 8-bit machine type.
type Bar = Posit<6, 1, i8>;
// A 32-bit b-posit with 3-bit exponent field and at most a 6-bit regime field, represented in a 32-bit machine type.
type Baz = Posit<32, 3, i32, 6>;

Note that Posit will have the same size (and alignment) as its Int parameter, so it’s currently not possible to create e.g. a 4-bit posit that only actually takes 4 bits in memory.

These are examples of invalid parameters which will not compile.

type Foo = Posit<40, 2, i32>;   // N=40 too big for i32
type Bar = Posit<1, 0, i8>;     // N=1 can't be ≤ 2
type Baz = Posit<32, 33, i32>;  // ES=33 too big for N=32
type Qux = Posit<32, 2, 33, i32>;  // RS=33 too big for N=32

Implementations§

Source§

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

Source

pub const BITS: u32

The size of this Posit type in bits (i.e. parameter N).

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

§Example
assert_eq!(p16::BITS, 16);                  // Standard posit
assert_eq!(Posit::<20, 1, i32>::BITS, 20);  // Non-standard posit
Source

pub const ES: u32

The number of exponent bits (i.e. parameter ES).

§Example
assert_eq!(p16::ES, 2);                  // Standard posit
assert_eq!(Posit::<20, 1, i32>::ES, 1);  // Non-standard posit
Source

pub const RS: u32

The maximum number of regime bits (i.e. parameter RS).

If this is not a b-posit (i.e. no non-default RS parameter is given), there is no bound on the number of regime bits, and this is equal to BITS.

§Example
assert_eq!(p16::RS, 16);                     // Standard posit, no cap on regime bits
assert_eq!(Posit::<20, 1, i32>::RS, 20);     // Non-standard posit, no cap on regime bits
assert_eq!(Posit::<32, 5, i32, 6>::RS, 6);   // Non-standard b-posit, regime bits capped at 6
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 bits, if any, are set as equal to the N-1th bit (i.e. sign-extended).

§Example
assert_eq!(0b00000000, p8::ZERO.to_bits());
assert_eq!(0b01000000, p8::ONE.to_bits());
assert_eq!(0b01111111, p8::MAX.to_bits());
assert_eq!(0b00000001, p8::MIN_POSITIVE.to_bits());
assert_eq!(0b11000000, p8::MINUS_ONE.to_bits());
assert_eq!(0b10000001, p8::MIN.to_bits());
assert_eq!(0b11111111, p8::MAX_NEGATIVE.to_bits());
assert_eq!(0b10000000, p8::NAR.to_bits());
Source

pub fn from_bits(bits: Int) -> Self

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

§Example
assert_eq!(p8::from_bits(0), p8::ZERO);
assert_eq!(p8::from_bits(1), p8::MIN_POSITIVE);
assert_eq!(p8::from_bits(i8::MAX), p8::MAX);
assert_eq!(p8::from_bits(0b0_10_01_011), 2.75.round_into());
assert_eq!(p8::from_bits(0b1_110_00_01), (-0.0546875).round_into());
Source

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

As Self::from_bits, but does not check that bits is a valid bit pattern for Self.

§Safety

bits has to be a result of a Self::to_bits call, i.e. it has to be in the range -1 << (N-1) ..= 1 << (N-1) - 1, or calling this function is undefined behaviour. Note that if Int::BITS == Self::BITS this always holds.

§Example
type Posit4 = Posit<4, 1, i8>;
assert_eq!(Posit4::from_bits(0b0000_0100), Posit4::ONE);
assert_eq!(Posit4::from_bits(0b1111_1000), Posit4::NAR);

but the following would not be valid as the bits are not in a valid range (i.e. not sign-extended past 4 bits).

Posit4::from_bits(0b0110_0100);  // Undefined behaviour!
Source§

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

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

Greatest 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 INT_MAX: Int

The largest consecutive integer value, that is: integers in the range 0 ..= Self::INT_MAX are exactly representable as a posit of this type.

Standard: “pIntMax”.

§Example
assert_eq!(p8::INT_MAX, 1 << 4);
assert_eq!(p16::INT_MAX, 1 << 10);
assert_eq!(p32::INT_MAX, 1 << 23);
assert_eq!(p64::INT_MAX, 1 << 48);
Source§

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

Source

pub fn next(self) -> Self

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

Note that, unlike every other function of a posit, next and prior do not produce a NaR output on a NaR input.

Standard: “next”.

§Example
assert_eq!(p8::round_from(1.).next(), p8::round_from(1.125));
assert_eq!(p8::round_from(128.).next(), p8::round_from(160.));
assert_eq!(p8::MAX.next(), p8::NAR);
assert_eq!(p8::NAR.next(), p8::MIN);
Source

pub fn prior(self) -> Self

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

Note that, unlike every other function of a posit, next and prior do not produce a NaR output on a NaR input.

Standard: “prior”.

§Example
assert_eq!(p8::round_from(1.).prior(), p8::round_from(0.9375));
assert_eq!(p8::round_from(128.).prior(), p8::round_from(112.));
assert_eq!(p8::MIN.prior(), p8::NAR);
assert_eq!(p8::NAR.prior(), p8::MAX);
Source§

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

Source

pub fn abs(self) -> Self

Return the absolute value of self.

Standard: “abs”.

§Example
assert_eq!(p16::ONE.abs(), p16::MINUS_ONE.abs())
Source

pub fn sign(self) -> Self

Return 1 if self > 0, -1 if self < 0, 0 if self == 0, and NaR if self == NaR.

Standard: “sign”.

§Example
assert_eq!(p16::round_from(2).sign(), p16::round_from(1));
assert_eq!(p16::round_from(-3).sign(), p16::round_from(-1));
assert_eq!(p16::round_from(0).sign(), p16::round_from(0));
assert_eq!(p16::NAR.sign(), p16::NAR);
Source§

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

Source

pub fn nearest_int(self) -> Self

Returns the integer-valued posit nearest to self, and the nearest even integer-valued posit if two integers are equally near.

Standard: “nearestInt”.

§Example
assert_eq!(p32::round_from(3.1).nearest_int(), p32::round_from(3));
assert_eq!(p32::round_from(3.5).nearest_int(), p32::round_from(4));
assert_eq!(p32::round_from(3.9).nearest_int(), p32::round_from(4));
Source

pub fn floor(self) -> Self

Returns the largest integer-valued posit less than or equal to self.

Standard: “floor”.

§Example
assert_eq!(p32::round_from(3.1).floor(), p32::round_from(3));
assert_eq!(p32::round_from(3.5).floor(), p32::round_from(3));
assert_eq!(p32::round_from(3.9).floor(), p32::round_from(3));
Source

pub fn ceil(self) -> Self

Returns the smallest integer-valued posit greater than or equal to self.

Standard: “ceil”.

§Example
assert_eq!(p32::round_from(3.1).ceil(), p32::round_from(4));
assert_eq!(p32::round_from(3.5).ceil(), p32::round_from(4));
assert_eq!(p32::round_from(3.9).ceil(), p32::round_from(4));
Source§

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

Source

pub fn sqrt(self) -> Self

Returns the square root of self, rounded. If self is negative or NaR, returns NaR.

Standard: “sqrt”.

§Example
assert_eq!(p16::sqrt((4. * PI).round_into()), p16::round_from(3.5449));
assert_eq!(p16::MINUS_ONE.sqrt(), p16::NAR);
Source§

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

Source

pub fn convert<const N2: u32, const ES2: u32, Int2: Int, const RS2: u32>( self, ) -> Posit<N2, ES2, Int2, RS2>

Convert a posit into a different one, rounding according to the standard.

If the source and target types have the same ES (i.e. ES == ES2), such as is the case with the standard types, this is especially fast. This enables easy and seamless mixed-precision arithmetic.

§Examples
let pi: p64 = core::f64::consts::PI.round_into();
let two: p8 = 2.round_into();
let tau: p64 = pi * two.convert();
assert_eq!(tau, core::f64::consts::TAU.round_into())

Trait Implementations§

Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> Add<Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const SIZE: usize> AddAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

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

Standard: “qAddP”.

§Example
let mut quire = q16::from(p16::ONE);
quire += p16::round_from(0.42);
assert_eq!(p16::round_from(1.42), (&quire).round_into())
Source§

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

Source§

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

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

Standard: “qAddP”.

§Example
let mut quire = q16::from(p16::ONE);
quire += p16::round_from(0.42);
assert_eq!(p16::round_from(1.42), (&quire).round_into())
Source§

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

Source§

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

Performs the += operation. Read more
Source§

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

Source§

fn clone(&self) -> Self

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, const RS: u32> Debug for Posit<N, ES, Int, RS>

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, const RS: u32, Int: Int> Default for Posit<N, ES, Int, RS>

Source§

fn default() -> Self

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

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

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> Div<Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> DivAssign<&Posit<N, ES, Int, RS>> for Posit<N, ES, Int, RS>

Source§

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

Performs the /= operation. Read more
Source§

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

Source§

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

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

Create a quire from a posit value.

Standard: “pToQ”.

§Example
let posit = p16::round_from(123);
let quire = q16::from(posit);
Source§

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

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, const RS: u32> Mul<&Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> Mul<Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> MulAssign<&Posit<N, ES, Int, RS>> for Posit<N, ES, Int, RS>

Source§

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

Performs the *= operation. Read more
Source§

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

Source§

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

Performs the *= operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> Neg for Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32, Int: Int> Ord for Posit<N, ES, Int, RS>

Source§

fn cmp(&self, other: &Self) -> 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, const RS: u32, Int: Int> PartialEq for Posit<N, ES, Int, RS>

Note that, unlike IEEE floats, NaR is equal to itself (and different from any other value).

§Example

assert!(p32::NAR == p32::NAR);
assert!(f32::NAN != f32::NAN);

assert!(p32::NAR != 3.round_into());
assert!(f32::NAN != 3.);
Source§

fn eq(&self, other: &Self) -> 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, const RS: u32, Int: Int> PartialOrd for Posit<N, ES, Int, RS>

Note that, unlike IEEE floats, posits have a total order (i.e. implement Ord). NaR is always smaller than any other value, and equal to itself.

§Example

assert_eq!(p32::NAR.partial_cmp(&p32::NAR), Some(Ordering::Equal));
assert_eq!(f32::NAN.partial_cmp(&f32::NAN), None);

assert!(p32::NAR < p32::round_from(-3));
assert!(!(f32::NAN < -3.) && !(f32::NAN >= -3.));
Source§

fn partial_cmp(&self, other: &Self) -> 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, const SIZE: usize> RoundFrom<&Quire<N, ES, SIZE>> for Posit<N, ES, Int>

Source§

fn round_from(value: &Quire<N, ES, SIZE>) -> Self

Round a quire back to a posit. This is the final step to do after a series of calculations in the quire, and the only step that actually rounds.

Standard: “qToP”.

§Example
let mut quire = q16::from(p16::MAX);
quire += p16::round_from(0.1);
quire -= p16::MAX;
let result: p16 = (&quire).round_into();
assert_eq!(result, p16::round_from(0.1))
Source§

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

Source§

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

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

  • If the value is 0, the result is +0.0.
  • If the value is NaR, the result is a quiet NaN.
  • Otherwise, the posit value is rounded to a float (if necessary) using the “roundTiesToEven” rule in the IEEE 754 standard (in short: underflow to ±0, overflow to ±∞, otherwise round to nearest, in case of a tie round to nearest even bit pattern).
Source§

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

Source§

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

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

  • If the value is 0, the result is +0.0.
  • If the value is NaR, the result is a quiet NaN.
  • Otherwise, the posit value is rounded to a float (if necessary) using the “roundTiesToEven” rule in the IEEE 754 standard (in short: underflow to ±0, overflow to ±∞, otherwise round to nearest, in case of a tie round to nearest even bit pattern).
Source§

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

Source§

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

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

  • If the value is NaR, or if overflows the target type, then it converts to i128::MIN (i.e. the value where the most significant bit is 1 and the rest are 0).
  • Otherwise, it returns the nearest integer to value, rounding ties to even.
Source§

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

Source§

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

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

  • If the value is NaR, or if overflows the target type, then it converts to i16::MIN (i.e. the value where the most significant bit is 1 and the rest are 0).
  • Otherwise, it returns the nearest integer to value, rounding ties to even.
Source§

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

Source§

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

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

  • If the value is NaR, or if overflows the target type, then it converts to i32::MIN (i.e. the value where the most significant bit is 1 and the rest are 0).
  • Otherwise, it returns the nearest integer to value, rounding ties to even.
Source§

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

Source§

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

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

  • If the value is NaR, or if overflows the target type, then it converts to i64::MIN (i.e. the value where the most significant bit is 1 and the rest are 0).
  • Otherwise, it returns the nearest integer to value, rounding ties to even.
Source§

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

Source§

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

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

  • If the value is NaR, or if overflows the target type, then it converts to i8::MIN (i.e. the value where the most significant bit is 1 and the rest are 0).
  • Otherwise, it returns the nearest integer to value, rounding ties to even.
Source§

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

Source§

fn round_from(value: Quire<N, ES, SIZE>) -> Self

Round a quire back to a posit. This is the final step to do after a series of calculations in the quire, and the only step that actually rounds.

Standard: “qToP”.

§Example
let mut quire = q16::from(p16::MAX);
quire += p16::round_from(0.1);
quire -= p16::MAX;
let result: p16 = quire.round_into();
assert_eq!(result, p16::round_from(0.1))
Source§

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

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, const RS: u32> RoundFrom<f64> for Posit<N, ES, Int, RS>

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, const RS: u32> RoundFrom<i128> for Posit<N, ES, Int, RS>

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, const RS: u32> RoundFrom<i16> for Posit<N, ES, Int, RS>

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, const RS: u32> RoundFrom<i32> for Posit<N, ES, Int, RS>

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, const RS: u32> RoundFrom<i64> for Posit<N, ES, Int, RS>

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, const RS: u32> RoundFrom<i8> for Posit<N, ES, Int, RS>

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, const RS: u32> Sub<&Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const RS: u32> Sub<Posit<N, ES, Int, RS>> for &Posit<N, ES, Int, RS>

Source§

type Output = Posit<N, ES, Int, RS>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

type Output = Posit<N, ES, Int, RS>

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, const SIZE: usize> SubAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>

Source§

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

Standard: “qSubP”.

§Example
let mut quire = q16::from(p16::ONE);
quire -= p16::round_from(0.42);
assert_eq!(p16::round_from(0.58), (&quire).round_into())
Source§

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

Source§

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

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

Standard: “qSubP”.

§Example
let mut quire = q16::from(p16::ONE);
quire -= p16::round_from(0.42);
assert_eq!(p16::round_from(0.58), (&quire).round_into())
Source§

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

Source§

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

Performs the -= operation. Read more
Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<const N: u32, const ES: u32, Int, const RS: u32> UnwindSafe for Posit<N, ES, Int, RS>
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, according to the rules prescribed in the posit standard for this particular conversion. 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, according to the rules prescribed in the posit standard for this particular conversion. 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.