Trait fixed::traits::FixedSigned[][src]

pub trait FixedSigned: Fixed + Neg<Output = Self> {
    type Unsigned: FixedUnsigned;
Show methods fn signed_bits(self) -> u32;
fn is_positive(self) -> bool;
fn is_negative(self) -> bool;
fn abs(self) -> Self;
fn unsigned_abs(self) -> Self::Unsigned;
fn signum(self) -> Self;
fn checked_abs(self) -> Option<Self>;
fn checked_signum(self) -> Option<Self>;
fn saturating_abs(self) -> Self;
fn saturating_signum(self) -> Self;
fn wrapping_abs(self) -> Self;
fn wrapping_signum(self) -> Self;
fn unwrapped_abs(self) -> Self;
fn unwrapped_signum(self) -> Self;
fn overflowing_abs(self) -> (Self, bool);
fn overflowing_signum(self) -> (Self, bool);
}

This trait provides methods common to all signed fixed-point numbers.

Methods common to all fixed-point numbers including unsigned fixed-point numbers are provided by the Fixed supertrait.

This trait is sealed and cannot be implemented for more types; it is implemented for FixedI8, FixedI16, FixedI32, FixedI64, and FixedI128.

Associated Types

type Unsigned: FixedUnsigned[src]

An unsigned fixed-point number type with the same number of integer and fractional bits as Self.

Loading content...

Required methods

fn signed_bits(self) -> u32[src]

Returns the number of bits required to represent the value.

See also FixedI32::signed_bits.

fn is_positive(self) -> bool[src]

Returns true if the number is > 0.

See also FixedI32::is_positive.

fn is_negative(self) -> bool[src]

Returns true if the number is < 0.

See also FixedI32::is_negative.

fn abs(self) -> Self[src]

Returns the absolute value.

See also FixedI32::abs.

fn unsigned_abs(self) -> Self::Unsigned[src]

Returns the absolute value using an unsigned type without any wrapping or panicking.

See also FixedI32::unsigned_abs.

fn signum(self) -> Self[src]

Returns a number representing the sign of self.

See also FixedI32::signum.

Panics

When debug assertions are enabled, this method panics

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

When debug assertions are not enabled, the wrapped value can be returned in those cases, but it is not considered a breaking change if in the future it panics; using this method when 1 and −1 cannot be represented is almost certainly a bug.

fn checked_abs(self) -> Option<Self>[src]

Checked absolute value. Returns the absolute value, or None on overflow.

Overflow can only occur when trying to find the absolute value of the minimum value.

See also FixedI32::checked_abs.

fn checked_signum(self) -> Option<Self>[src]

Checked signum. Returns a number representing the sign of self, or None on overflow.

Overflow can only occur

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

See also FixedI32::checked_signum.

fn saturating_abs(self) -> Self[src]

Saturating absolute value. Returns the absolute value, saturating on overflow.

Overflow can only occur when trying to find the absolute value of the minimum value.

See also FixedI32::saturating_abs.

fn saturating_signum(self) -> Self[src]

Saturating signum. Returns a number representing the sign of self, saturating on overflow.

Overflow can only occur

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

See also FixedI32::saturating_signum.

fn wrapping_abs(self) -> Self[src]

Wrapping absolute value. Returns the absolute value, wrapping on overflow.

Overflow can only occur when trying to find the absolute value of the minimum value.

See also FixedI32::wrapping_abs.

fn wrapping_signum(self) -> Self[src]

Wrapping signum. Returns a number representing the sign of self, wrapping on overflow.

Overflow can only occur

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

See also FixedI32::wrapping_signum.

fn unwrapped_abs(self) -> Self[src]

Unwrapped absolute value. Returns the absolute value, panicking on overflow.

Overflow can only occur when trying to find the absolute value of the minimum value.

See also FixedI32::unwrapped_abs.

Panics

Panics if the result does not fit.

fn unwrapped_signum(self) -> Self[src]

Unwrapped signum. Returns a number representing the sign of self, panicking on overflow.

Overflow can only occur

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

See also FixedI32::unwrapped_signum.

Panics

Panics if the result does not fit.

fn overflowing_abs(self) -> (Self, bool)[src]

Overflowing absolute value.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

See also FixedI32::overflowing_abs.

fn overflowing_signum(self) -> (Self, bool)[src]

Overflowing signum.

Returns a tuple of the signum and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Overflow can only occur

  • if the value is positive and the fixed-point number has zero or one integer bits such that it cannot hold the value 1.
  • if the value is negative and the fixed-point number has zero integer bits, such that it cannot hold the value −1.

See also FixedI32::overflowing_signum.

Loading content...

Implementors

impl<Frac: LeEqU8> FixedSigned for FixedI8<Frac>[src]

type Unsigned = FixedU8<Frac>

impl<Frac: LeEqU16> FixedSigned for FixedI16<Frac>[src]

type Unsigned = FixedU16<Frac>

impl<Frac: LeEqU32> FixedSigned for FixedI32<Frac>[src]

type Unsigned = FixedU32<Frac>

impl<Frac: LeEqU64> FixedSigned for FixedI64<Frac>[src]

type Unsigned = FixedU64<Frac>

impl<Frac: LeEqU128> FixedSigned for FixedI128<Frac>[src]

type Unsigned = FixedU128<Frac>

Loading content...