#[repr(transparent)]
pub struct FixedI16<const FRAC: i32> { /* private fields */ }
Expand description

A 16-bit signed number with FRAC fractional bits.

The number has 16 bits, of which f = FRAC are fractional bits and 16 − f are integer bits. The value x can lie in the range −215/2f ≤ x < 215/2f. The difference between successive numbers is constant throughout the range: Δ = 1/2f.

For FixedI16<0>, f = 0 and Δ = 1, and the fixed-point number behaves like an i16 with the value lying in the range −215 ≤ x < 215. For FixedI16<16>, f = 16 and Δ = 1/216, and the value lies in the range −1/2 ≤ x < 1/2.

FixedI16<FRAC> has the same size, alignment and ABI as i16; it is #[repr(transparent)] with i16 as the only non-zero-sized field.

Examples

#![feature(generic_const_exprs)]

use fixed::FixedI16;
let eleven = FixedI16::<3>::from_num(11);
assert_eq!(eleven, FixedI16::<3>::from_bits(11 << 3));
assert_eq!(eleven, 11);
assert_eq!(eleven.to_string(), "11");
let two_point_75 = eleven / 4;
assert_eq!(two_point_75, FixedI16::<3>::from_bits(11 << 1));
assert_eq!(two_point_75, 2.75);
assert_eq!(two_point_75.to_string(), "2.8");

Implementations

The items in this block are implemented for all values of FRAC.

Zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ZERO, Fix::from_bits(0));

The difference between any two successive representable numbers, Δ.

If the number has f = FRAC fractional bits, then Δ = 1/2f.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::DELTA, Fix::from_bits(1));
// binary 0.0001 is decimal 0.0625
assert_eq!(Fix::DELTA, 0.0625);

The smallest value that can be represented.

If the number has f = FRAC fractional bits, then the minimum is −215/2f.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MIN, Fix::from_bits(i16::MIN));

The largest value that can be represented.

If the number has f = FRAC fractional bits, then the maximum is (215 − 1)/2f.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MAX, Fix::from_bits(i16::MAX));

true because the FixedI16 type is signed.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert!(Fix::IS_SIGNED);

The number of integer bits.

Note that INT_BITS + FRAC_BITS = 16. Both INT_BITS and FRAC_BITS can be negative.

  • When INT_BITS < 0 and FRAC_BITS > 16, the magnitude can be very large and DELTA > 1.
  • When INT_BITS > 16 and FRAC_BITS < 0, the magnitude can be very small and DELTA < 2−16.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<6>;
assert_eq!(Fix::INT_BITS, 16 - 6);

The number of fractional bits.

Note that INT_BITS + FRAC_BITS = 16. Both INT_BITS and FRAC_BITS can be negative.

  • When INT_BITS < 0 and FRAC_BITS > 16, DELTA > 1. That is, the magnitude can be very large.
  • When INT_BITS > 16 and FRAC_BITS < 0, DELTA < 2−16. That is, the magnitude can be very small.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<6>;
assert_eq!(Fix::FRAC_BITS, 6);

Creates a fixed-point number that has a bitwise representation identical to the given integer.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 0010.0000 = 2
assert_eq!(Fix::from_bits(0b10_0000), 2);

Creates an integer that has a bitwise representation identical to the given fixed-point number.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 2 is 0010.0000
assert_eq!(Fix::from_num(2).to_bits(), 0b10_0000);

Converts a fixed-point number from big endian to the target’s endianness.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0x1234);
if cfg!(target_endian = "big") {
    assert_eq!(Fix::from_be(f), f);
} else {
    assert_eq!(Fix::from_be(f), f.swap_bytes());
}

Converts a fixed-point number from little endian to the target’s endianness.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0x1234);
if cfg!(target_endian = "little") {
    assert_eq!(Fix::from_le(f), f);
} else {
    assert_eq!(Fix::from_le(f), f.swap_bytes());
}

Converts self to big endian from the target’s endianness.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0x1234);
if cfg!(target_endian = "big") {
    assert_eq!(f.to_be(), f);
} else {
    assert_eq!(f.to_be(), f.swap_bytes());
}

Converts self to little endian from the target’s endianness.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0x1234);
if cfg!(target_endian = "little") {
    assert_eq!(f.to_le(), f);
} else {
    assert_eq!(f.to_le(), f.swap_bytes());
}

Reverses the byte order of the fixed-point number.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0x1234);
let swapped = Fix::from_bits(0x3412);
assert_eq!(f.swap_bytes(), swapped);

Creates a fixed-point number from its representation as a byte array in big endian.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_be_bytes([0x12, 0x34]),
    Fix::from_bits(0x1234)
);

Creates a fixed-point number from its representation as a byte array in little endian.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_le_bytes([0x34, 0x12]),
    Fix::from_bits(0x1234)
);

Creates a fixed-point number from its representation as a byte array in native endian.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    if cfg!(target_endian = "big") {
        Fix::from_ne_bytes([0x12, 0x34])
    } else {
        Fix::from_ne_bytes([0x34, 0x12])
    },
    Fix::from_bits(0x1234)
);

Returns the memory representation of this fixed-point number as a byte array in big-endian byte order.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let val = Fix::from_bits(0x1234);
assert_eq!(
    val.to_be_bytes(),
    [0x12, 0x34]
);

Returns the memory representation of this fixed-point number as a byte array in little-endian byte order.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let val = Fix::from_bits(0x1234);
assert_eq!(
    val.to_le_bytes(),
    [0x34, 0x12]
);

Returns the memory representation of this fixed-point number as a byte array in native byte order.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let val = Fix::from_bits(0x1234);
assert_eq!(
    val.to_ne_bytes(),
    if cfg!(target_endian = "big") {
        [0x12, 0x34]
    } else {
        [0x34, 0x12]
    }
);

Creates a fixed-point number from another number.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.to_fixed().
Panics

For floating-point numbers, panics if the value is not finite.

When debug assertions are enabled, panics if the value does not fit. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_from_num instead.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(Fix::from_num(src), Fix::from_bits(0b111 << (4 - 2)));

assert_eq!(Fix::from_num(3i32), Fix::from_bits(3 << 4));
assert_eq!(Fix::from_num(-3i64), Fix::from_bits(-3 << 4));

assert_eq!(Fix::from_num(1.75f32), Fix::from_bits(0b111 << (4 - 2)));
assert_eq!(Fix::from_num(-1.75f64), Fix::from_bits(-0b111 << (4-2)));

Converts a fixed-point number to another number.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::from_fixed(self).
Panics

When debug assertions are enabled, panics if the value does not fit. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_to_num instead.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I30F2, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(src.to_num::<I30F2>(), I30F2::from_bits(0b111));
// src >> 2 is 0.0111, which for I30F2 is truncated to 0.01
assert_eq!((src >> 2u32).to_num::<I30F2>(), I30F2::from_bits(0b1));

// 2.5 is 10.1 in binary
let two_point_5 = Fix::from_bits(0b101 << (4 - 1));
assert_eq!(two_point_5.to_num::<i32>(), 2);
assert_eq!((-two_point_5).to_num::<i64>(), -3);

// 1.625 is 1.101 in binary
let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.to_num::<f32>(), 1.625f32);
assert_eq!((-one_point_625).to_num::<f64>(), -1.625f64);

Creates a fixed-point number from another number if it fits, otherwise returns None.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.checked_to_fixed().
Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(Fix::checked_from_num(src), Some(Fix::from_bits(0b111 << (4 - 2))));
let too_large = FixedI16::<2>::MAX;
assert!(Fix::checked_from_num(too_large).is_none());

assert_eq!(Fix::checked_from_num(3), Some(Fix::from_bits(3 << 4)));
let too_large = i16::MAX;
assert!(Fix::checked_from_num(too_large).is_none());
let too_small = i16::MIN;
assert!(Fix::checked_from_num(too_small).is_none());

// 1.75 is 1.11 in binary
let expected = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(Fix::checked_from_num(1.75f32), Some(expected));
assert_eq!(Fix::checked_from_num(-1.75f64), Some(-expected));
assert!(Fix::checked_from_num(2e38).is_none());
assert!(Fix::checked_from_num(std::f64::NAN).is_none());

Converts a fixed-point number to another number if it fits, otherwise returns None.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::checked_from_fixed(self).
Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
let expected = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(src.checked_to_num::<I16F16>(), Some(expected));
type TooFewIntBits = FixedI16<6>;
assert!(Fix::MAX.checked_to_num::<TooFewIntBits>().is_none());

// 2.5 is 10.1 in binary
let two_point_5 = Fix::from_bits(0b101 << (4 - 1));
assert_eq!(two_point_5.checked_to_num::<i32>(), Some(2));
assert_eq!((-two_point_5).checked_to_num::<i64>(), Some(-3));
type AllInt = FixedI16<0>;
assert!(AllInt::from_bits(-1).checked_to_num::<u16>().is_none());

// 1.625 is 1.101 in binary
let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.checked_to_num::<f32>(), Some(1.625f32));

Creates a fixed-point number from another number, saturating if it does not fit.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.saturating_to_fixed().
Panics

This method panics if the value is a floating-point NaN.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(Fix::saturating_from_num(src), Fix::from_bits(0b111 << (4 - 2)));
let too_large = FixedI16::<2>::MAX;
assert_eq!(Fix::saturating_from_num(too_large), Fix::MAX);

assert_eq!(Fix::saturating_from_num(3), Fix::from_bits(3 << 4));
let too_small = i16::MIN;
assert_eq!(Fix::saturating_from_num(too_small), Fix::MIN);

// 1.75 is 1.11 in binary
let expected = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(Fix::saturating_from_num(1.75f32), expected);
assert_eq!(Fix::saturating_from_num(-1.75f64), -expected);
assert_eq!(Fix::saturating_from_num(2e38), Fix::MAX);
assert_eq!(Fix::saturating_from_num(std::f64::NEG_INFINITY), Fix::MIN);

Converts a fixed-point number to another number, saturating the value if it does not fit.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::saturating_from_fixed(self).
Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
let expected = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(src.saturating_to_num::<I16F16>(), expected);
type TooFewIntBits = FixedI16<6>;
let saturated = Fix::MAX.saturating_to_num::<TooFewIntBits>();
assert_eq!(saturated, TooFewIntBits::MAX);

// 2.5 is 10.1 in binary
let two_point_5 = Fix::from_bits(0b101 << (4 - 1));
assert_eq!(two_point_5.saturating_to_num::<i32>(), 2);
type AllInt = FixedI16<0>;
assert_eq!(AllInt::from_bits(-1).saturating_to_num::<u16>(), 0);

// 1.625 is 1.101 in binary
let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.saturating_to_num::<f32>(), 1.625f32);

Creates a fixed-point number from another number, wrapping the value on overflow.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.wrapping_to_fixed().
Panics

For floating-point numbers, panics if the value is not finite.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(Fix::wrapping_from_num(src), Fix::from_bits(0b111 << (4 - 2)));
// integer 0b1101 << (16 - 7) will wrap to fixed-point 1010...
let too_large = FixedI16::<0>::from_bits(0b1101 << (16 - 7));
let wrapped = Fix::from_bits(0b1010 << (16 - 4));
assert_eq!(Fix::wrapping_from_num(too_large), wrapped);

// integer 0b1101 << (16 - 7) will wrap to fixed-point 1010...
let large: i16 = 0b1101 << (16 - 7);
let wrapped = Fix::from_bits(0b1010 << (16 - 4));
assert_eq!(Fix::wrapping_from_num(large), wrapped);

// 1.75 is 1.11 in binary
let expected = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(Fix::wrapping_from_num(1.75f32), expected);
// 1.75 << (16 - 4) wraps to binary 11000...
let large = 1.75 * 2f32.powi(16 - 4);
let wrapped = Fix::from_bits(0b1100 << (16 - 4));
assert_eq!(Fix::wrapping_from_num(large), wrapped);

Converts a fixed-point number to another number, wrapping the value on overflow.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::wrapping_from_fixed(self).
Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
let expected = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(src.wrapping_to_num::<I16F16>(), expected);
type TooFewIntBits = FixedI16<6>;
let wrapped = TooFewIntBits::from_bits(Fix::MAX.to_bits() << 2);
assert_eq!(Fix::MAX.wrapping_to_num::<TooFewIntBits>(), wrapped);

// 2.5 is 10.1 in binary
let two_point_5 = Fix::from_bits(0b101 << (4 - 1));
assert_eq!(two_point_5.wrapping_to_num::<i32>(), 2);
type AllInt = FixedI16<0>;
assert_eq!(AllInt::from_bits(-1).wrapping_to_num::<u16>(), u16::MAX);

// 1.625 is 1.101 in binary
let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.wrapping_to_num::<f32>(), 1.625f32);

Creates a fixed-point number from another number, panicking on overflow.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.unwrapped_to_fixed().
Panics

Panics if the value does not fit.

For floating-point numbers, also panics if the value is not finite.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(Fix::unwrapped_from_num(src), Fix::from_bits(0b111 << (4 - 2)));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let too_large = FixedI16::<0>::from_bits(0b1101 << (16 - 7));
let _overflow = Fix::unwrapped_from_num(too_large);

Converts a fixed-point number to another number, panicking on overflow.

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::unwrapped_from_fixed(self).
Panics

Panics if the value does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
let expected = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(src.unwrapped_to_num::<I16F16>(), expected);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
type TooFewIntBits = FixedI16<6>;
let _overflow = Fix::MAX.unwrapped_to_num::<TooFewIntBits>();

Creates a fixed-point number from another number.

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

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other number src for which ToFixed is implemented, in which case this method returns src.overflowing_to_fixed().
Panics

For floating-point numbers, panics if the value is not finite.

Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = I16F16::from_bits(0b111 << (16 - 2));
let expected = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(Fix::overflowing_from_num(src), (expected, false));
// integer 0b1101 << (16 - 7) will wrap to fixed-point 1010...
let too_large = FixedI16::<0>::from_bits(0b1101 << (16 - 7));
let wrapped = Fix::from_bits(0b1010 << (16 - 4));
assert_eq!(Fix::overflowing_from_num(too_large), (wrapped, true));

assert_eq!(Fix::overflowing_from_num(3), (Fix::from_bits(3 << 4), false));
// integer 0b1101 << (16 - 7) will wrap to fixed-point 1010...
let large: i16 = 0b1101 << (16 - 7);
let wrapped = Fix::from_bits(0b1010 << (16 - 4));
assert_eq!(Fix::overflowing_from_num(large), (wrapped, true));

// 1.75 is 1.11 in binary
let expected = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(Fix::overflowing_from_num(1.75f32), (expected, false));
// 1.75 << (16 - 4) wraps to binary 11000...
let large = 1.75 * 2f32.powi(16 - 4);
let wrapped = Fix::from_bits(0b1100 << (16 - 4));
assert_eq!(Fix::overflowing_from_num(large), (wrapped, true));

Converts a fixed-point number to another number.

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

The other number can be:

  • Another fixed-point number. Any extra fractional bits are discarded, which rounds towards −∞.
  • An integer of type i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, or usize. Any fractional bits are discarded, which rounds towards −∞.
  • A floating-point number of type f16, bf16, f32, f64 or F128. For this conversion, the method rounds to the nearest, with ties rounding to even.
  • Any other type Dst for which FromFixed is implemented, in which case this method returns Dst::overflowing_from_fixed(self).
Examples
#![feature(generic_const_exprs)]

use fixed::{types::I16F16, FixedI16};
type Fix = FixedI16<4>;

// 1.75 is 1.11 in binary
let src = Fix::from_bits(0b111 << (4 - 2));
let expected = I16F16::from_bits(0b111 << (16 - 2));
assert_eq!(src.overflowing_to_num::<I16F16>(), (expected, false));
type TooFewIntBits = FixedI16<6>;
let wrapped = TooFewIntBits::from_bits(Fix::MAX.to_bits() << 2);
assert_eq!(Fix::MAX.overflowing_to_num::<TooFewIntBits>(), (wrapped, true));

// 2.5 is 10.1 in binary
let two_point_5 = Fix::from_bits(0b101 << (4 - 1));
assert_eq!(two_point_5.overflowing_to_num::<i32>(), (2, false));
let does_not_fit = FixedI16::<0>::from_bits(-1);
let wrapped = 1u16.wrapping_neg();
assert_eq!(does_not_fit.overflowing_to_num::<u16>(), (wrapped, true));

// 1.625 is 1.101 in binary
let one_point_625 = Fix::from_bits(0b1101 << (4 - 3));
assert_eq!(one_point_625.overflowing_to_num::<f32>(), (1.625f32, false));

Returns the integer part.

Note that since the numbers are stored in two’s complement, negative numbers with non-zero fractional parts will be rounded towards −∞, except in the case where there are no integer bits, that is FixedI16<U16>, where the return value is always zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 0010.0000
let two = Fix::from_num(2);
// 0010.0100
let two_and_quarter = two + two / 8;
assert_eq!(two_and_quarter.int(), two);
// 1101.0000
let three = Fix::from_num(3);
// 1101.1100
assert_eq!((-two_and_quarter).int(), -three);

Returns the fractional part.

Note that since the numbers are stored in two’s complement, the returned fraction will be non-negative for negative numbers, except in the case where there are no integer bits, that is FixedI16<U16> where the return value is always equal to self.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 0000.0100
let quarter = Fix::ONE / 4;
// 0010.0100
let two_and_quarter = quarter * 9;
assert_eq!(two_and_quarter.frac(), quarter);
// 0000.1100
let three_quarters = quarter * 3;
// 1101.1100
assert_eq!((-two_and_quarter).frac(), three_quarters);

Rounds to the next integer towards 0.

Note that for negative numbers, this is different from truncating/discarding the fractional bits. This is because in two’s-complement representations, the value of all the bits except for the most significant bit is positive; discarding positive bits would round towards −∞ unlike this method which rounds towards zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.1).round_to_zero(), Fix::from_num(2));
assert_eq!(Fix::from_num(2.9).round_to_zero(), Fix::from_num(2));
assert_eq!(Fix::from_num(-2.1).round_to_zero(), Fix::from_num(-2));
assert_eq!(Fix::from_num(-2.9).round_to_zero(), Fix::from_num(-2));

Rounds to the next integer towards +∞.

Panics

When debug assertions are enabled, panics if the result does not fit. When debug assertions are not enabled, the wrapped result can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_ceil instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).ceil(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).ceil(), Fix::from_num(-2));

Rounds to the next integer towards −∞.

Panics

When debug assertions are enabled, panics if the result does not fit. When debug assertions are not enabled, the wrapped result can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_floor instead.

Overflow can only occur when there are zero integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).floor(), Fix::from_num(2));
assert_eq!(Fix::from_num(-2.5).floor(), Fix::from_num(-3));

Rounds to the nearest integer, with ties rounded away from zero.

Panics

When debug assertions are enabled, panics if the result does not fit. When debug assertions are not enabled, the wrapped result can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_round instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).round(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).round(), Fix::from_num(-3));

Rounds to the nearest integer, with ties rounded to even.

Panics

When debug assertions are enabled, panics if the result does not fit. When debug assertions are not enabled, the wrapped result can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_round_ties_to_even instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).round_ties_to_even(), Fix::from_num(2));
assert_eq!(Fix::from_num(3.5).round_ties_to_even(), Fix::from_num(4));

Checked ceil. Rounds to the next integer towards +∞, returning None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).checked_ceil(), Some(Fix::from_num(3)));
assert_eq!(Fix::from_num(-2.5).checked_ceil(), Some(Fix::from_num(-2)));
assert!(Fix::MAX.checked_ceil().is_none());

Checked floor. Rounds to the next integer towards −∞.Returns None on overflow.

Overflow can only occur when there are zero integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).checked_floor(), Some(Fix::from_num(2)));
assert_eq!(Fix::from_num(-2.5).checked_floor(), Some(Fix::from_num(-3)));
type AllFrac = FixedI16<16>;
assert!(AllFrac::MIN.checked_floor().is_none());

Checked round. Rounds to the nearest integer, with ties rounded away from zero, returning None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).checked_round(), Some(Fix::from_num(3)));
assert_eq!(Fix::from_num(-2.5).checked_round(), Some(Fix::from_num(-3)));
assert!(Fix::MAX.checked_round().is_none());

Checked round. Rounds to the nearest integer, with ties rounded to even, returning None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).checked_round_ties_to_even(), Some(Fix::from_num(2)));
assert_eq!(Fix::from_num(3.5).checked_round_ties_to_even(), Some(Fix::from_num(4)));
assert!(Fix::MAX.checked_round_ties_to_even().is_none());

Saturating ceil. Rounds to the next integer towards +∞, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).saturating_ceil(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).saturating_ceil(), Fix::from_num(-2));
assert_eq!(Fix::MAX.saturating_ceil(), Fix::MAX);

Saturating floor. Rounds to the next integer towards −∞, saturating on overflow.

Overflow can only occur when there are zero integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).saturating_floor(), Fix::from_num(2));
assert_eq!(Fix::from_num(-2.5).saturating_floor(), Fix::from_num(-3));
type AllFrac = FixedI16<16>;
assert_eq!(AllFrac::MIN.saturating_floor(), AllFrac::MIN);

Saturating round. Rounds to the nearest integer, with ties rounded away from zero, and saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).saturating_round(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).saturating_round(), Fix::from_num(-3));
assert_eq!(Fix::MAX.saturating_round(), Fix::MAX);

Saturating round. Rounds to the nearest integer, with ties rounded to even, and saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).saturating_round_ties_to_even(), Fix::from_num(2));
assert_eq!(Fix::from_num(3.5).saturating_round_ties_to_even(), Fix::from_num(4));
assert_eq!(Fix::MAX.saturating_round_ties_to_even(), Fix::MAX);

Wrapping ceil. Rounds to the next integer towards +∞, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).wrapping_ceil(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).wrapping_ceil(), Fix::from_num(-2));
assert_eq!(Fix::MAX.wrapping_ceil(), Fix::MIN);

Wrapping floor. Rounds to the next integer towards −∞, wrapping on overflow.

Overflow can only occur when there are zero integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).wrapping_floor(), Fix::from_num(2));
assert_eq!(Fix::from_num(-2.5).wrapping_floor(), Fix::from_num(-3));
type AllFrac = FixedI16<16>;
assert_eq!(AllFrac::MIN.wrapping_floor(), AllFrac::ZERO);

Wrapping round. Rounds to the next integer to the nearest, with ties rounded away from zero, and wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).wrapping_round(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).wrapping_round(), Fix::from_num(-3));
assert_eq!(Fix::MAX.wrapping_round(), Fix::MIN);

Wrapping round. Rounds to the next integer to the nearest, with ties rounded to even, and wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).wrapping_round_ties_to_even(), Fix::from_num(2));
assert_eq!(Fix::from_num(3.5).wrapping_round_ties_to_even(), Fix::from_num(4));
assert_eq!(Fix::MAX.wrapping_round_ties_to_even(), Fix::MIN);

Unwrapped ceil. Rounds to the next integer towards +∞, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).unwrapped_ceil(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).unwrapped_ceil(), Fix::from_num(-2));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_ceil();

Unwrapped floor. Rounds to the next integer towards −∞, panicking on overflow.

Overflow can only occur when there are zero integer bits.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).unwrapped_floor(), Fix::from_num(2));
assert_eq!(Fix::from_num(-2.5).unwrapped_floor(), Fix::from_num(-3));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type AllFrac = FixedI16<16>;
let _overflow = AllFrac::MIN.unwrapped_floor();

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded away from zero, and panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).unwrapped_round(), Fix::from_num(3));
assert_eq!(Fix::from_num(-2.5).unwrapped_round(), Fix::from_num(-3));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_round();

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded to even, and panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).unwrapped_round_ties_to_even(), Fix::from_num(2));
assert_eq!(Fix::from_num(3.5).unwrapped_round_ties_to_even(), Fix::from_num(4));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_round_ties_to_even();

Overflowing ceil. Rounds to the next integer towards +∞.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).overflowing_ceil(), (Fix::from_num(3), false));
assert_eq!(Fix::from_num(-2.5).overflowing_ceil(), (Fix::from_num(-2), false));
assert_eq!(Fix::MAX.overflowing_ceil(), (Fix::MIN, true));

Overflowing floor. Rounds to the next integer towards −∞.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value isreturned. Overflow can only occur when there are zero integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).overflowing_floor(), (Fix::from_num(2), false));
assert_eq!(Fix::from_num(-2.5).overflowing_floor(), (Fix::from_num(-3), false));
type AllFrac = FixedI16<16>;
assert_eq!(AllFrac::MIN.overflowing_floor(), (AllFrac::ZERO, true));

Overflowing round. Rounds to the next integer to the nearest, with ties rounded away from zero.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).overflowing_round(), (Fix::from_num(3), false));
assert_eq!(Fix::from_num(-2.5).overflowing_round(), (Fix::from_num(-3), false));
assert_eq!(Fix::MAX.overflowing_round(), (Fix::MIN, true));

Overflowing round. Rounds to the next integer to the nearest, with ties rounded to even.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2.5).overflowing_round_ties_to_even(), (Fix::from_num(2), false));
assert_eq!(Fix::from_num(3.5).overflowing_round_ties_to_even(), (Fix::from_num(4), false));
assert_eq!(Fix::MAX.overflowing_round_ties_to_even(), (Fix::MIN, true));

Returns the number of ones in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0b11_0010);
assert_eq!(f.count_ones(), 3);

Returns the number of zeros in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(!0b11_0010);
assert_eq!(f.count_zeros(), 3);

Returns the number of leading ones in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let all_ones = !Fix::ZERO;
let f = all_ones - Fix::from_bits(0b10_0000);
assert_eq!(f.leading_ones(), 16 - 6);

Returns the number of leading zeros in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0b10_0000);
assert_eq!(f.leading_zeros(), 16 - 6);

Returns the number of trailing ones in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0b101_1111);
assert_eq!(f.trailing_ones(), 5);

Returns the number of trailing zeros in the binary representation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let f = Fix::from_bits(0b10_0000);
assert_eq!(f.trailing_zeros(), 5);

Returns the number of bits required to represent the value.

The number of bits required includes an initial one for negative numbers, and an initial zero for non-negative numbers.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-3).signed_bits(), 7);      // “_101.0000”
assert_eq!(Fix::from_num(-1).signed_bits(), 5);      // “___1.0000”
assert_eq!(Fix::from_num(-0.0625).signed_bits(), 1); // “____.___1”
assert_eq!(Fix::from_num(0).signed_bits(), 1);       // “____.___0”
assert_eq!(Fix::from_num(0.0625).signed_bits(), 2);  // “____.__01”
assert_eq!(Fix::from_num(1).signed_bits(), 6);       // “__01.0000”
assert_eq!(Fix::from_num(3).signed_bits(), 7);       // “_011.0000”

Integer base-2 logarithm, rounded down.

Panics

Panics if the fixed-point number is ≤ 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(4).int_log2(), 2);
assert_eq!(Fix::from_num(3.9375).int_log2(), 1);
assert_eq!(Fix::from_num(0.25).int_log2(), -2);
assert_eq!(Fix::from_num(0.1875).int_log2(), -3);

Checked integer base-2 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ZERO.checked_int_log2(), None);
assert_eq!(Fix::from_num(4).checked_int_log2(), Some(2));
assert_eq!(Fix::from_num(3.9375).checked_int_log2(), Some(1));
assert_eq!(Fix::from_num(0.25).checked_int_log2(), Some(-2));
assert_eq!(Fix::from_num(0.1875).checked_int_log2(), Some(-3));

Reverses the order of the bits of the fixed-point number.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let bits = 0x1234_i16;
let rev_bits = bits.reverse_bits();
assert_eq!(Fix::from_bits(bits).reverse_bits(), Fix::from_bits(rev_bits));

Shifts to the left by n bits, wrapping the truncated bits to the right end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let bits: i16 = (0b111 << (16 - 3)) | 0b1010;
let rot = 0b1010111;
assert_eq!(bits.rotate_left(3), rot);
assert_eq!(Fix::from_bits(bits).rotate_left(3), Fix::from_bits(rot));

Shifts to the right by n bits, wrapping the truncated bits to the left end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let bits: i16 = 0b1010111;
let rot = (0b111 << (16 - 3)) | 0b1010;
assert_eq!(bits.rotate_right(3), rot);
assert_eq!(Fix::from_bits(bits).rotate_right(3), Fix::from_bits(rot));

Returns true if the number is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert!(Fix::ZERO.is_zero());
assert!(!Fix::from_num(5).is_zero());

Returns true if the number is > 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert!(Fix::from_num(5).is_positive());
assert!(!Fix::ZERO.is_positive());
assert!(!Fix::from_num(-5).is_positive());

Returns true if the number is < 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert!(!Fix::from_num(5).is_negative());
assert!(!Fix::ZERO.is_negative());
assert!(Fix::from_num(-5).is_negative());

Multiplies two fixed-point numbers and returns a wider type to retain all precision.

If self has f fractional bits and 16 − f integer bits, and rhs has g fractional bits and 16 − g integer bits, then the returned fixed-point number will have f + g fractional bits and 32 − f − g integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
// decimal: 1.25 × 1.0625 = 1.328_125
// binary: 1.01 × 1.0001 = 1.010101
let a = FixedI16::<2>::from_num(1.25);
let b = FixedI16::<4>::from_num(1.0625);
assert_eq!(a.wide_mul(b), 1.328_125);

Multiplies an unsigned fixed-point number and returns a wider signed type to retain all precision.

If self has f fractional bits and 16 − f integer bits, and rhs has g fractional bits and 16 − g integer bits, then the returned fixed-point number will have f + g fractional bits and 32 − f − g integer bits.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
// decimal: -1.25 × 1.0625 = -1.328_125
// binary: -1.01 × 1.0001 = -1.010101
let a = FixedI16::<2>::from_num(-1.25);
let b = FixedU16::<4>::from_num(1.0625);
assert_eq!(a.wide_mul_unsigned(b), -1.328_125);

Divides two fixed-point numbers and returns a wider type to retain more precision.

If self has f fractional bits and 16 − f integer bits, and rhs has g fractional bits and 16 − g integer bits, then the returned fixed-point number will have 16 + f − g fractional bits and 16 − f + g integer bits.

Warning: While most cases of overflow are avoided using this method, dividing MIN by -DELTA will still result in panic due to overflow. The alternative wide_sdiv method avoids this by sacrificing one fractional bit in the return type.

Panics

Panics if the divisor is zero or on overflow. Overflow can only occur when dividing MIN by -DELTA.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedI32};
// decimal: 4.625 / 0.03125 = 148
// binary: 100.101 / 0.00001 = 10010100
let a = FixedI16::<3>::from_num(4.625);
let b = FixedI16::<5>::from_num(0.03125);
let ans: FixedI32<14> = a.wide_div(b);
assert_eq!(ans, 148);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.wide_div(-Fix::DELTA);

Divides two fixed-point numbers and returns a wider type to retain more precision.

If self has f fractional bits and 16 − f integer bits, and rhs has g fractional bits and 16 − g integer bits, then the returned fixed-point number will have 15 + f − g fractional bits and 17 − f + g integer bits.

This is similar to the wide_div method but sacrifices one fractional bit to avoid overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedI32};
// decimal: 4.625 / 0.03125 = 148
// binary: 100.101 / 0.00001 = 10010100
let a = FixedI16::<4>::from_num(4.625);
let b = FixedI16::<5>::from_num(0.03125);
let ans: FixedI32<14> = a.wide_sdiv(b);
assert_eq!(ans, 148);

Unlike wide_div, dividing MIN by -DELTA does not overflow.

#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedI32};
type Fix = FixedI16<4>;
type DFix = FixedI32<15>;
assert_eq!(Fix::MIN.wide_sdiv(-Fix::DELTA), (DFix::MIN / 2).abs());

Divides by an unsigned fixed-point number and returns a wider signed type to retain more precision.

If self has f fractional bits and 16 − f integer bits, and rhs has g fractional bits and 16 − g integer bits, then the returned fixed-point number will have 16 + f − g fractional bits and 16 − f + g integer bits.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedI32, FixedU16};
// decimal: -4.625 / 0.03125 = -148
// binary: -100.101 / 0.00001 = -10010100
let a = FixedI16::<3>::from_num(-4.625);
let b = FixedU16::<5>::from_num(0.03125);
let ans: FixedI32<14> = a.wide_div_unsigned(b);
assert_eq!(ans, -148);

Multiply and add. Returns self × mul + add.

For some cases, the product self × mul would overflow on its own, but the final result self × mul + add is representable; in these cases this method returns the correct result without overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_mul_add instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).mul_add(Fix::from_num(0.5), Fix::from_num(3)),
    Fix::from_num(5)
);
// MAX × 1.5 - MAX = MAX / 2, which does not overflow
assert_eq!(Fix::MAX.mul_add(Fix::from_num(1.5), -Fix::MAX), Fix::MAX / 2);

Adds self to the product a × b.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method returns the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

The mul_acc method performs the same operation as this method but mutates self instead of returning the result.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_add_prod instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).add_prod(Fix::from_num(4), Fix::from_num(0.5)), 5);
// -MAX + MAX × 1.5 = MAX / 2, which does not overflow
assert_eq!((-Fix::MAX).add_prod(Fix::MAX, Fix::from_num(1.5)), Fix::MAX / 2);

Multiply and accumulate. Adds (a × b) to self.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method saves the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

The add_prod method performs the same operation as this method but returns the result instead of mutating self.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_mul_acc instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
acc.mul_acc(Fix::from_num(4), Fix::from_num(0.5));
assert_eq!(acc, 5);

// MAX × 1.5 - MAX = MAX / 2, which does not overflow
acc = -Fix::MAX;
acc.mul_acc(Fix::MAX, Fix::from_num(1.5));
assert_eq!(acc, Fix::MAX / 2);

Remainder for Euclidean division.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).rem_euclid(Fix::from_num(2)), Fix::from_num(1.5));
assert_eq!(Fix::from_num(-7.5).rem_euclid(Fix::from_num(2)), Fix::from_num(0.5));

Returns the absolute value.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let five = Fix::from_num(5);
let minus_five = Fix::from_num(-5);
assert_eq!(five.abs(), five);
assert_eq!(minus_five.abs(), five);

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

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(-5).unsigned_abs(), UFix::from_num(5));
// min_as_unsigned has only highest bit set
let min_as_unsigned = UFix::ONE << (UFix::INT_BITS - 1);
assert_eq!(Fix::MIN.unsigned_abs(), min_as_unsigned);

Returns the distance from self to other.

The distance is the absolute value of the difference.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_dist instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.dist(Fix::from_num(5)), Fix::from_num(4));
assert_eq!(Fix::NEG_ONE.dist(Fix::from_num(2)), Fix::from_num(3));

Returns the distance from self to other using an unsigned type without any wrapping or panicking.

The distance is the absolute value of the difference.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::NEG_ONE.unsigned_dist(Fix::from_num(2)), UFix::from_num(3));
assert_eq!(Fix::MIN.unsigned_dist(Fix::MAX), UFix::MAX);

Returns a number representing the sign of self.

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.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).signum(), 1);
assert_eq!(Fix::ZERO.signum(), 0);
assert_eq!(Fix::from_num(-5).signum(), -1);

Returns the absolute value of the difference between self and other using an unsigned type without any wrapping or panicking.

This method is the same as unsigned_dist for signed fixed-point numbers.

Returns the mean of self and other.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).mean(Fix::from_num(4)), Fix::from_num(3.5));
assert_eq!(Fix::from_num(-3).mean(Fix::from_num(4)), Fix::from_num(0.5));

Returns the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Panics

Panics if other is zero.

When debug assertions are enabled, this method also panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_next_multiple_of instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).next_multiple_of(Fix::from_num(1.5)),
    Fix::from_num(4.5)
);
assert_eq!(
    Fix::from_num(4).next_multiple_of(Fix::from_num(-1.5)),
    Fix::from_num(3)
);

Inverse linear interpolation between start and end.

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Returns (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Panics

Panics when start = end.

When debug assertions are enabled, this method also panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_inv_lerp instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let start = Fix::from_num(2);
let end = Fix::from_num(3.5);
assert_eq!(Fix::from_num(0.5).inv_lerp::<4>(start, end), -1);
assert_eq!(Fix::from_num(2).inv_lerp::<4>(start, end), 0);
assert_eq!(Fix::from_num(2.75).inv_lerp::<4>(start, end), 0.5);
assert_eq!(Fix::from_num(3.5).inv_lerp::<4>(start, end), 1);
assert_eq!(Fix::from_num(5).inv_lerp::<4>(start, end), 2);

Addition with an unsigned fixed-point number.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_add_unsigned instead.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(-5).add_unsigned(UFix::from_num(3)), -2);

Subtraction with an unsigned fixed-point number.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_sub_unsigned instead.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(3).sub_unsigned(UFix::from_num(5)), -2);

Bitwise NOT. Usable in constant context.

This is equivalent to the ! operator and Not::not, but can also be used in constant context. Unless required in constant context, use the operator or trait instead.

Planned deprecation

This method will be deprecated when the ! operator and the Not trait are usable in constant context.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
const A: Fix = Fix::from_bits(0x3E);
const NOT_A: Fix = A.const_not();
assert_eq!(NOT_A, !A);

Bitwise AND. Usable in constant context.

This is equivalent to the & operator and BitAnd::bitand, but can also be used in constant context. Unless required in constant context, use the operator or trait instead.

Planned deprecation

This method will be deprecated when the & operator and the BitAnd trait are usable in constant context.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
const A: Fix = Fix::from_bits(0x3E);
const B: Fix = Fix::from_bits(0x55);
const A_BITAND_B: Fix = A.const_bitand(B);
assert_eq!(A_BITAND_B, A & B);

Bitwise OR. Usable in constant context.

This is equivalent to the | operator and BitOr::bitor, but can also be used in constant context. Unless required in constant context, use the operator or trait instead.

Planned deprecation

This method will be deprecated when the | operator and the BitOr trait are usable in constant context.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
const A: Fix = Fix::from_bits(0x3E);
const B: Fix = Fix::from_bits(0x55);
const A_BITOR_B: Fix = A.const_bitor(B);
assert_eq!(A_BITOR_B, A | B);

Bitwise XOR. Usable in constant context.

This is equivalent to the ^ operator and BitXor::bitxor, but can also be used in constant context. Unless required in constant context, use the operator or trait instead.

Planned deprecation

This method will be deprecated when the ^ operator and the BitXor trait are usable in constant context.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
const A: Fix = Fix::from_bits(0x3E);
const B: Fix = Fix::from_bits(0x55);
const A_BITXOR_B: Fix = A.const_bitxor(B);
assert_eq!(A_BITXOR_B, A ^ B);

Checked negation. Returns the negated value, or None on overflow.

Overflow can only occur when negating the minimum value.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).checked_neg(), Some(Fix::from_num(-5)));
assert_eq!(Fix::MIN.checked_neg(), None);

Checked addition. Returns the sum, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::MAX - Fix::ONE).checked_add(Fix::ONE), Some(Fix::MAX));
assert_eq!(Fix::MAX.checked_add(Fix::ONE), None);

Checked subtraction. Returns the difference, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::MIN + Fix::ONE).checked_sub(Fix::ONE), Some(Fix::MIN));
assert_eq!(Fix::MIN.checked_sub(Fix::ONE), None);

Checked multiplication. Returns the product, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MAX.checked_mul(Fix::ONE), Some(Fix::MAX));
assert_eq!(Fix::MAX.checked_mul(Fix::from_num(2)), None);

Checked remainder. Returns the remainder, or None if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(1.5).checked_rem(Fix::ONE), Some(Fix::from_num(0.5)));
assert_eq!(Fix::from_num(1.5).checked_rem(Fix::ZERO), None);

Checked multiply and add. Returns self × mul + add, or None on overflow.

For some cases, the product self × mul would overflow on its own, but the final result self × mul + add is representable; in these cases this method returns the correct result without overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).checked_mul_add(Fix::from_num(0.5), Fix::from_num(3)),
    Some(Fix::from_num(5))
);
assert_eq!(Fix::MAX.checked_mul_add(Fix::ONE, Fix::ZERO), Some(Fix::MAX));
assert_eq!(Fix::MAX.checked_mul_add(Fix::ONE, Fix::DELTA), None);
// MAX × 1.5 - MAX = MAX / 2, which does not overflow
assert_eq!(Fix::MAX.checked_mul_add(Fix::from_num(1.5), -Fix::MAX), Some(Fix::MAX / 2));

Adds self to the product a × b, returning None on overflow.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method returns the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(3).checked_add_prod(Fix::from_num(4), Fix::from_num(0.5)),
    Some(Fix::from_num(5))
);
assert_eq!(Fix::DELTA.checked_add_prod(Fix::MAX, Fix::ONE), None);
// -MAX + MAX × 1.5 = MAX / 2, which does not overflow
assert_eq!(
    (-Fix::MAX).checked_add_prod(Fix::MAX, Fix::from_num(1.5)),
    Some(Fix::MAX / 2)
);

Checked multiply and accumulate. Adds (a × b) to self, or returns None on overflow.

Like all other checked methods, this method wraps the successful return value in an Option. Since the unchecked mul_acc method does not return a value, which is equivalent to returning (), this method wraps () into Some(()) on success.

When overflow occurs, self is not modified and retains its previous value.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method saves the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
let check = acc.checked_mul_acc(Fix::from_num(4), Fix::from_num(0.5));
assert_eq!(check, Some(()));
assert_eq!(acc, 5);

acc = Fix::DELTA;
let check = acc.checked_mul_acc(Fix::MAX, Fix::ONE);
assert_eq!(check, None);
// acc is unchanged on error
assert_eq!(acc, Fix::DELTA);

// MAX × 1.5 - MAX = MAX / 2, which does not overflow
acc = -Fix::MAX;
let check = acc.checked_mul_acc(Fix::MAX, Fix::from_num(1.5));
assert_eq!(check, Some(()));
assert_eq!(acc, Fix::MAX / 2);

Checked multiplication by an integer. Returns the product, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MAX.checked_mul_int(1), Some(Fix::MAX));
assert_eq!(Fix::MAX.checked_mul_int(2), None);

Checked division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MAX.checked_div_int(1), Some(Fix::MAX));
assert_eq!(Fix::ONE.checked_div_int(0), None);
assert_eq!(Fix::MIN.checked_div_int(-1), None);

Checked remainder for Euclidean division. Returns the remainder, or None if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let num = Fix::from_num(7.5);
assert_eq!(num.checked_rem_euclid(Fix::from_num(2)), Some(Fix::from_num(1.5)));
assert_eq!(num.checked_rem_euclid(Fix::ZERO), None);
assert_eq!((-num).checked_rem_euclid(Fix::from_num(2)), Some(Fix::from_num(0.5)));

Checked shift left. Returns the shifted number, or None if rhs ≥ 16.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::ONE / 2).checked_shl(3), Some(Fix::from_num(4)));
assert_eq!((Fix::ONE / 2).checked_shl(16), None);

Checked shift right. Returns the shifted number, or None if rhs ≥ 16.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(4).checked_shr(3), Some(Fix::ONE / 2));
assert_eq!(Fix::from_num(4).checked_shr(16), None);

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.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-5).checked_abs(), Some(Fix::from_num(5)));
assert_eq!(Fix::MIN.checked_abs(), None);

Checked distance. Returns the distance from self to other, or None on overflow.

The distance is the absolute value of the difference.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.checked_dist(Fix::from_num(5)), Some(Fix::from_num(4)));
assert_eq!(Fix::MIN.checked_dist(Fix::ZERO), None);

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.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).checked_signum(), Some(Fix::ONE));
assert_eq!(Fix::ZERO.checked_signum(), Some(Fix::ZERO));
assert_eq!(Fix::from_num(-5).checked_signum(), Some(Fix::NEG_ONE));

type OneIntBit = FixedI16<15>;
type ZeroIntBits = FixedI16<16>;
assert_eq!(OneIntBit::from_num(0.5).checked_signum(), None);
assert_eq!(ZeroIntBits::from_num(0.25).checked_signum(), None);
assert_eq!(ZeroIntBits::from_num(-0.5).checked_signum(), None);

Checked next multiple of other. Returns the next multiple, or None if other is zero or on overflow.

The next multiple is the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).checked_next_multiple_of(Fix::from_num(1.5)),
    Some(Fix::from_num(4.5))
);
assert_eq!(Fix::from_num(4).checked_next_multiple_of(Fix::ZERO), None);
assert_eq!(Fix::MAX.checked_next_multiple_of(Fix::from_num(2)), None);

Checked inverse linear interpolation between start and end. Returns None on overflow or when start = end.

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Returns (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let four = Fix::from_num(4);
assert_eq!(Fix::from_num(3).checked_inv_lerp::<4>(two, four), Some(Fix::from_num(0.5)));
assert_eq!(Fix::from_num(2).checked_inv_lerp::<4>(two, two), None);
assert_eq!(Fix::MAX.checked_inv_lerp::<4>(Fix::ZERO, Fix::from_num(0.5)), None);

Checked addition with an unsigned fixed-point number. Returns the sum, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(
    Fix::from_num(-5).checked_add_unsigned(UFix::from_num(3)),
    Some(Fix::from_num(-2))
);
assert_eq!(Fix::MAX.checked_add_unsigned(UFix::DELTA), None);

Checked subtraction with an unsigned fixed-point number. Returns the difference, or None on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(
    Fix::from_num(3).checked_sub_unsigned(UFix::from_num(5)),
    Some(Fix::from_num(-2))
);
assert_eq!(Fix::MIN.checked_sub_unsigned(UFix::DELTA), None);

Saturating negation. Returns the negated value, saturating on overflow.

Overflow can only occur when negating the minimum value.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).saturating_neg(), Fix::from_num(-5));
assert_eq!(Fix::MIN.saturating_neg(), Fix::MAX);

Saturating addition. Returns the sum, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).saturating_add(Fix::from_num(2)), Fix::from_num(5));
assert_eq!(Fix::MAX.saturating_add(Fix::ONE), Fix::MAX);

Saturating subtraction. Returns the difference, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.saturating_sub(Fix::from_num(3)), Fix::from_num(-2));
assert_eq!(Fix::MIN.saturating_sub(Fix::ONE), Fix::MIN);

Saturating multiplication. Returns the product, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).saturating_mul(Fix::from_num(2)), Fix::from_num(6));
assert_eq!(Fix::MAX.saturating_mul(Fix::from_num(2)), Fix::MAX);

Saturating multiply and add. Returns self × mul + add, saturating on overflow.

For some cases, the product self × mul would overflow on its own, but the final result self × mul + add is representable; in these cases this method returns the correct result without overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).saturating_mul_add(Fix::from_num(0.5), Fix::from_num(3)),
    Fix::from_num(5)
);
let half_max = Fix::MAX / 2;
assert_eq!(half_max.saturating_mul_add(Fix::from_num(3), half_max), Fix::MAX);
assert_eq!(half_max.saturating_mul_add(Fix::from_num(-5), half_max), Fix::MIN);
// MAX × 1.5 - MAX = MAX / 2, which does not overflow
assert_eq!(Fix::MAX.saturating_mul_add(Fix::from_num(1.5), -Fix::MAX), half_max);

Adds self to the product a × b, saturating on overflow.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method returns the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(3).saturating_add_prod(Fix::from_num(4), Fix::from_num(0.5)),
    5
);
assert_eq!(Fix::ONE.saturating_add_prod(Fix::MAX, Fix::from_num(3)), Fix::MAX);
// -MAX + MAX × 1.5 = MAX / 2, which does not overflow
assert_eq!(
    (-Fix::MAX).saturating_add_prod(Fix::MAX, Fix::from_num(1.5)),
    Fix::MAX / 2
);

Saturating multiply and accumulate. Adds (a × b) to self, saturating on overflow.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method saves the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
acc.saturating_mul_acc(Fix::from_num(4), Fix::from_num(0.5));
assert_eq!(acc, 5);

acc = Fix::MAX / 2;
acc.saturating_mul_acc(Fix::MAX / 2, Fix::from_num(3));
assert_eq!(acc, Fix::MAX);

// MAX × 1.5 - MAX = MAX / 2, which does not overflow
acc = -Fix::MAX;
acc.saturating_mul_acc(Fix::MAX, Fix::from_num(1.5));
assert_eq!(acc, Fix::MAX / 2);

Saturating multiplication by an integer. Returns the product, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).saturating_mul_int(2), Fix::from_num(6));
assert_eq!(Fix::MAX.saturating_mul_int(2), Fix::MAX);

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.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-5).saturating_abs(), Fix::from_num(5));
assert_eq!(Fix::MIN.saturating_abs(), Fix::MAX);

Saturating distance. Returns the distance from self to other, saturating on overflow.

The distance is the absolute value of the difference.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.saturating_dist(Fix::from_num(5)), Fix::from_num(4));
assert_eq!(Fix::MIN.saturating_dist(Fix::MAX), Fix::MAX);

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.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).saturating_signum(), 1);
assert_eq!(Fix::ZERO.saturating_signum(), 0);
assert_eq!(Fix::from_num(-5).saturating_signum(), -1);

type OneIntBit = FixedI16<15>;
type ZeroIntBits = FixedI16<16>;
assert_eq!(OneIntBit::from_num(0.5).saturating_signum(), OneIntBit::MAX);
assert_eq!(ZeroIntBits::from_num(0.25).saturating_signum(), ZeroIntBits::MAX);
assert_eq!(ZeroIntBits::from_num(-0.5).saturating_signum(), ZeroIntBits::MIN);

Saturating next multiple of other.

The next multiple is the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Panics

Panics if other is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).saturating_next_multiple_of(Fix::from_num(1.5)),
    Fix::from_num(4.5)
);
assert_eq!(Fix::MAX.saturating_next_multiple_of(Fix::from_num(2)), Fix::MAX);

Inverse linear interpolation between start and end, saturating on overflow.

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Returns (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Panics

Panics when start = end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let four = Fix::from_num(4);
assert_eq!(Fix::from_num(3).saturating_inv_lerp::<4>(two, four), 0.5);
assert_eq!(Fix::MAX.saturating_inv_lerp::<4>(Fix::ZERO, Fix::from_num(0.5)), Fix::MAX);
assert_eq!(Fix::MAX.saturating_inv_lerp::<4>(Fix::from_num(0.5), Fix::ZERO), Fix::MIN);

Saturating addition with an unsigned fixed-point number. Returns the sum, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(-5).saturating_add_unsigned(UFix::from_num(3)), -2);
assert_eq!(Fix::from_num(-5).saturating_add_unsigned(UFix::MAX), Fix::MAX);

Saturating subtraction with an unsigned fixed-point number. Returns the difference, saturating on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(3).saturating_sub_unsigned(UFix::from_num(5)), -2);
assert_eq!(Fix::from_num(5).saturating_sub_unsigned(UFix::MAX), Fix::MIN);

Wrapping negation. Returns the negated value, wrapping on overflow.

Overflow can only occur when negating the minimum value.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).wrapping_neg(), Fix::from_num(-5));
assert_eq!(Fix::MIN.wrapping_neg(), Fix::MIN);

Wrapping addition. Returns the sum, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_minus_delta = Fix::ONE - Fix::DELTA;
assert_eq!(Fix::from_num(3).wrapping_add(Fix::from_num(2)), Fix::from_num(5));
assert_eq!(Fix::MAX.wrapping_add(Fix::ONE), Fix::MIN + one_minus_delta);

Wrapping subtraction. Returns the difference, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_minus_delta = Fix::ONE - Fix::DELTA;
assert_eq!(Fix::from_num(3).wrapping_sub(Fix::from_num(5)), Fix::from_num(-2));
assert_eq!(Fix::MIN.wrapping_sub(Fix::ONE), Fix::MAX - one_minus_delta);

Wrapping multiplication. Returns the product, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).wrapping_mul(Fix::from_num(2)), Fix::from_num(6));
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.wrapping_mul(Fix::from_num(4)), wrapped);

Wrapping multiply and add. Returns self × mul + add, wrapping on overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).wrapping_mul_add(Fix::from_num(0.5), Fix::from_num(3)),
    Fix::from_num(5)
);
assert_eq!(Fix::MAX.wrapping_mul_add(Fix::ONE, Fix::from_num(0)), Fix::MAX);
assert_eq!(Fix::MAX.wrapping_mul_add(Fix::ONE, Fix::from_bits(1)), Fix::MIN);
let wrapped = Fix::MAX.wrapping_mul_int(4);
assert_eq!(Fix::MAX.wrapping_mul_add(Fix::from_num(3), Fix::MAX), wrapped);

Adds self to the product a × b, wrapping on overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(3).wrapping_add_prod(Fix::from_num(4), Fix::from_num(0.5)),
    5
);
assert_eq!(
    Fix::MAX.wrapping_add_prod(Fix::MAX, Fix::from_num(3)),
    Fix::MAX.wrapping_mul_int(4)
);

Wrapping multiply and accumulate. Adds (a × b) to self, wrapping on overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
acc.wrapping_mul_acc(Fix::from_num(4), Fix::from_num(0.5));
assert_eq!(acc, 5);

acc = Fix::MAX;
acc.wrapping_mul_acc(Fix::MAX, Fix::from_num(3));
assert_eq!(acc, Fix::MAX.wrapping_mul_int(4));

Wrapping multiplication by an integer. Returns the product, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).wrapping_mul_int(2), Fix::from_num(6));
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.wrapping_mul_int(4), wrapped);

Wrapping division by an integer. Returns the quotient, wrapping on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.5 is binary 1.1
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).wrapping_div_int(2), one_point_5);
assert_eq!(Fix::MIN.wrapping_div_int(-1), Fix::MIN);

Wrapping shift left. Wraps rhs if rhs ≥ 16, then shifts and returns the number.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::ONE / 2).wrapping_shl(3), Fix::from_num(4));
assert_eq!((Fix::ONE / 2).wrapping_shl(3 + 16), Fix::from_num(4));

Wrapping shift right. Wraps rhs if rhs ≥ 16, then shifts and returns the number.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::from_num(4)).wrapping_shr(3), Fix::ONE / 2);
assert_eq!((Fix::from_num(4)).wrapping_shr(3 + 16), Fix::ONE / 2);

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.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-5).wrapping_abs(), Fix::from_num(5));
assert_eq!(Fix::MIN.wrapping_abs(), Fix::MIN);

Wrapping distance. Returns the distance from self to other, wrapping on overflow.

The distance is the absolute value of the difference.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.wrapping_dist(Fix::from_num(5)), Fix::from_num(4));
assert_eq!(Fix::MIN.wrapping_dist(Fix::MAX), -Fix::DELTA);

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.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).wrapping_signum(), 1);
assert_eq!(Fix::ZERO.wrapping_signum(), 0);
assert_eq!(Fix::from_num(-5).wrapping_signum(), -1);

type OneIntBit = FixedI16<15>;
type ZeroIntBits = FixedI16<16>;
assert_eq!(OneIntBit::from_num(0.5).wrapping_signum(), -1);
assert_eq!(ZeroIntBits::from_num(0.25).wrapping_signum(), 0);
assert_eq!(ZeroIntBits::from_num(-0.5).wrapping_signum(), 0);

Wrapping next multiple of other.

The next multiple is the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Panics

Panics if other is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).wrapping_next_multiple_of(Fix::from_num(1.5)),
    Fix::from_num(4.5)
);
let max_minus_delta = Fix::MAX - Fix::DELTA;
assert_eq!(
    Fix::MAX.wrapping_next_multiple_of(max_minus_delta),
    max_minus_delta.wrapping_mul_int(2)
);

Inverse linear interpolation between start and end, wrapping on overflow.

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Returns (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Panics

Panics when start = end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let four = Fix::from_num(4);
assert_eq!(Fix::from_num(3).wrapping_inv_lerp::<4>(two, four), 0.5);
assert_eq!(
    Fix::MAX.wrapping_inv_lerp::<4>(Fix::ZERO, Fix::from_num(0.5)),
    Fix::MAX.wrapping_mul_int(2)
);

Wrapping addition with an unsigned fixed-point number. Returns the sum, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(-5).wrapping_add_unsigned(UFix::from_num(3)), -2);
assert_eq!(Fix::ZERO.wrapping_add_unsigned(UFix::MAX), -Fix::DELTA);

Wrapping subtraction with an unsigned fixed-point number. Returns the difference, wrapping on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(3).wrapping_sub_unsigned(UFix::from_num(5)), -2);
assert_eq!(Fix::ZERO.wrapping_sub_unsigned(UFix::MAX), Fix::DELTA);

Unwrapped negation. Returns the negated value, panicking on overflow.

Overflow can only occur when negating the minimum value.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).unwrapped_neg(), Fix::from_num(-5));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_neg();

Unwrapped addition. Returns the sum, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).unwrapped_add(Fix::from_num(2)), Fix::from_num(5));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_add(Fix::DELTA);

Unwrapped subtraction. Returns the difference, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).unwrapped_sub(Fix::from_num(5)), Fix::from_num(-2));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_sub(Fix::DELTA);

Unwrapped multiplication. Returns the product, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).unwrapped_mul(Fix::from_num(2)), Fix::from_num(6));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_mul(Fix::from_num(4));

Unwrapped remainder. Returns the remainder, panicking if the divisor is zero.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(1.5).unwrapped_rem(Fix::ONE), Fix::from_num(0.5));

The following panics because the divisor is zero.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _divisor_is_zero = Fix::from_num(1.5).unwrapped_rem(Fix::ZERO);

Unwrapped multiply and add. Returns self × mul + add, panicking on overflow.

For some cases, the product self × mul would overflow on its own, but the final result self × mul + add is representable; in these cases this method returns the correct result without overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).unwrapped_mul_add(Fix::from_num(0.5), Fix::from_num(3)),
    Fix::from_num(5)
);
// MAX × 1.5 - MAX = MAX / 2, which does not overflow
assert_eq!(Fix::MAX.unwrapped_mul_add(Fix::from_num(1.5), -Fix::MAX), Fix::MAX / 2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_mul_add(Fix::ONE, Fix::DELTA);

Adds self to the product a × b, panicking on overflow.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method returns the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(3).unwrapped_add_prod(Fix::from_num(4), Fix::from_num(0.5)),
    5
);
// -MAX + MAX × 1.5 = MAX / 2, which does not overflow
assert_eq!(
    (-Fix::MAX).unwrapped_add_prod(Fix::MAX, Fix::from_num(1.5)),
    Fix::MAX / 2
);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::DELTA.unwrapped_add_prod(Fix::MAX, Fix::ONE);

Unwrapped multiply and accumulate. Adds (a × b) to self, panicking on overflow.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method saves the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
acc.unwrapped_mul_acc(Fix::from_num(4), Fix::from_num(0.5));
assert_eq!(acc, 5);

// MAX × 1.5 - MAX = MAX / 2, which does not overflow
acc = -Fix::MAX;
acc.unwrapped_mul_acc(Fix::MAX, Fix::from_num(1.5));
assert_eq!(acc, Fix::MAX / 2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::DELTA;
acc.unwrapped_mul_acc(Fix::MAX, Fix::ONE);

Unwrapped multiplication by an integer. Returns the product, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).unwrapped_mul_int(2), Fix::from_num(6));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_mul_int(4);

Unwrapped division by an integer. Returns the quotient, panicking on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.5 is binary 1.1
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).unwrapped_div_int(2), one_point_5);

The following panics because the divisor is zero.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _divisor_is_zero = Fix::from_num(3).unwrapped_div_int(0);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_div_int(-1);

Unwrapped remainder for Euclidean division. Returns the remainder, panicking if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let num = Fix::from_num(7.5);
assert_eq!(num.unwrapped_rem_euclid(Fix::from_num(2)), Fix::from_num(1.5));

The following panics because the divisor is zero.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _divisor_is_zero = Fix::from_num(3).unwrapped_rem_euclid(Fix::ZERO);

Unwrapped shift left. Panics if rhs ≥ 16.

Panics

Panics if rhs ≥ 16.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::ONE / 2).unwrapped_shl(3), Fix::from_num(4));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::ONE.unwrapped_shl(16);

Unwrapped shift right. Panics if rhs ≥ 16.

Panics

Panics if rhs ≥ 16.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::from_num(4)).unwrapped_shr(3), Fix::ONE / 2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::ONE.unwrapped_shr(16);

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.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-5).unwrapped_abs(), Fix::from_num(5));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_abs();

Unwrapped distance. Returns the distance from self to other, panicking on overflow.

The distance is the absolute value of the difference.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE.unwrapped_dist(Fix::from_num(5)), Fix::from_num(4));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_dist(Fix::ZERO);

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.
Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).unwrapped_signum(), 1);
assert_eq!(Fix::ZERO.unwrapped_signum(), 0);
assert_eq!(Fix::from_num(-5).unwrapped_signum(), -1);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type OneIntBit = FixedI16<15>;
let _overflow = OneIntBit::from_num(0.5).unwrapped_signum();

Returns the next multiple of other, panicking on overflow.

The next multiple is the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Panics

Panics if other is zero or on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).unwrapped_next_multiple_of(Fix::from_num(1.5)),
    Fix::from_num(4.5)
);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_next_multiple_of(Fix::from_num(2));

Inverse linear interpolation between start and end, panicking on overflow.

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Returns (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Panics

Panics when start = end or when the results overflows.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let four = Fix::from_num(4);
assert_eq!(Fix::from_num(3).unwrapped_inv_lerp::<4>(two, four), 0.5);

The following panics because start = end.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let _zero_range = two.unwrapped_inv_lerp::<4>(two, two);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_inv_lerp::<4>(Fix::ZERO, Fix::from_num(0.5));

Unwrapped addition with an unsigned fixed-point number. Returns the sum, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(-5).unwrapped_add_unsigned(UFix::from_num(3)), -2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
let _overflow = Fix::MAX.unwrapped_add_unsigned(UFix::DELTA);

Unwrapped subtraction with an unsigned fixed-point number. Returns the difference, panicking on overflow.

Panics

Panics if the result does not fit.

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(Fix::from_num(3).unwrapped_sub_unsigned(UFix::from_num(5)), -2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
let _overflow = Fix::MIN.unwrapped_sub_unsigned(UFix::DELTA);

Overflowing negation.

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

Overflow can only occur when negating the minimum value.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).overflowing_neg(), (Fix::from_num(-5), false));
assert_eq!(Fix::MIN.overflowing_neg(), (Fix::MIN, true));

Overflowing addition.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_minus_delta = Fix::ONE - Fix::DELTA;
assert_eq!(Fix::from_num(3).overflowing_add(Fix::from_num(2)), (Fix::from_num(5), false));
assert_eq!(Fix::MAX.overflowing_add(Fix::ONE), (Fix::MIN + one_minus_delta, true));

Overflowing subtraction.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_minus_delta = Fix::ONE - Fix::DELTA;
assert_eq!(Fix::from_num(3).overflowing_sub(Fix::from_num(5)), (Fix::from_num(-2), false));
assert_eq!(Fix::MIN.overflowing_sub(Fix::ONE), (Fix::MAX - one_minus_delta, true));

Overflowing multiplication.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).overflowing_mul(Fix::from_num(2)), (Fix::from_num(6), false));
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.overflowing_mul(Fix::from_num(4)), (wrapped, true));

Overflowing multiply and add.

Returns a tuple of self × mul + add and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

For some cases, the product self × mul would overflow on its own, but the final result self × mul + add is representable; in these cases this method returns the correct result without overflow.

The mul parameter can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::MAX.overflowing_mul_add(Fix::ONE, Fix::ZERO),
    (Fix::MAX, false)
);
assert_eq!(
    Fix::MAX.overflowing_mul_add(Fix::ONE, Fix::DELTA),
    (Fix::MIN, true)
);
assert_eq!(
    Fix::MAX.overflowing_mul_add(Fix::from_num(3), Fix::MAX),
    Fix::MAX.overflowing_mul_int(4)
);
// MAX × 1.5 - MAX = MAX / 2, which does not overflow
assert_eq!(
    Fix::MAX.overflowing_mul_add(Fix::from_num(1.5), -Fix::MAX),
    (Fix::MAX / 2, false)
);

Adds self to the product a × b.

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

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method returns the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(3).overflowing_add_prod(Fix::from_num(4), Fix::from_num(0.5)),
    (Fix::from_num(5), false)
);
assert_eq!(
    Fix::MAX.overflowing_add_prod(Fix::MAX, Fix::from_num(3)),
    (Fix::MAX.wrapping_mul_int(4), true)
);
// -MAX + MAX × 1.5 = MAX / 2, which does not overflow
assert_eq!(
    (-Fix::MAX).overflowing_add_prod(Fix::MAX, Fix::from_num(1.5)),
    (Fix::MAX / 2, false)
);

Overflowing multiply and accumulate. Adds (a × b) to self, wrapping and returning true if overflow occurs.

For some cases, the product a × b would overflow on its own, but the final result self + a × b is representable; in these cases this method saves the correct result without overflow.

The a and b parameters can have a fixed-point type like self but with a different number of fractional bits.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let mut acc = Fix::from_num(3);
assert!(!acc.overflowing_mul_acc(Fix::from_num(4), Fix::from_num(0.5)));
assert_eq!(acc, 5);

acc = Fix::MAX;
assert!(acc.overflowing_mul_acc(Fix::MAX, Fix::from_num(3)));
assert_eq!(acc, Fix::MAX.wrapping_mul_int(4));

// MAX × 1.5 - MAX = MAX / 2, which does not overflow
acc = -Fix::MAX;
assert!(!acc.overflowing_mul_acc(Fix::MAX, Fix::from_num(1.5)));
assert_eq!(acc, Fix::MAX / 2);

Overflowing multiplication by an integer.

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3).overflowing_mul_int(2), (Fix::from_num(6), false));
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.overflowing_mul_int(4), (wrapped, true));

Overflowing division by an integer.

Returns a tuple of the quotient and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned. Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.5 is binary 1.1
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).overflowing_div_int(2), (one_point_5, false));
assert_eq!(Fix::MIN.overflowing_div_int(-1), (Fix::MIN, true));

Overflowing shift left.

Returns a tuple of the shifted value and a bool indicating whether an overflow has occurred. Overflow occurs when rhs ≥ 16. On overflow rhs is wrapped before the shift operation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::ONE / 2).overflowing_shl(3), (Fix::from_num(4), false));
assert_eq!((Fix::ONE / 2).overflowing_shl(3 + 16), (Fix::from_num(4), true));

Overflowing shift right.

Returns a tuple of the shifted value and a bool indicating whether an overflow has occurred. Overflow occurs when rhs ≥ 16. On overflow rhs is wrapped before the shift operation.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!((Fix::from_num(4)).overflowing_shr(3), (Fix::ONE / 2, false));
assert_eq!((Fix::from_num(4)).overflowing_shr(3 + 16), (Fix::ONE / 2, true));

Overflowing absolute value.

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

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

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(-5).overflowing_abs(), (Fix::from_num(5), false));
assert_eq!(Fix::MIN.overflowing_abs(), (Fix::MIN, true));

Overflowing distance.

Returns a tuple of the distance from self to other and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

The distance is the absolute value of the difference.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::ONE.overflowing_dist(Fix::from_num(5)),
    (Fix::from_num(4), false)
);
assert_eq!(
    Fix::MIN.overflowing_dist(Fix::MAX),
    (-Fix::DELTA, true)
);

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.
Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(5).overflowing_signum(), (Fix::ONE, false));
assert_eq!(Fix::ZERO.overflowing_signum(), (Fix::ZERO, false));
assert_eq!(Fix::from_num(-5).overflowing_signum(), (Fix::NEG_ONE, false));

type OneIntBit = FixedI16<15>;
type ZeroIntBits = FixedI16<16>;
assert_eq!(OneIntBit::from_num(0.5).overflowing_signum(), (OneIntBit::NEG_ONE, true));
assert_eq!(ZeroIntBits::from_num(0.25).overflowing_signum(), (ZeroIntBits::ZERO, true));
assert_eq!(ZeroIntBits::from_num(-0.5).overflowing_signum(), (ZeroIntBits::ZERO, true));

Overflowing next multiple of other.

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

The next multiple is the smallest multiple of other that is ≥ self if other is positive, and the largest multiple of other that is ≤ self if other is negative.

Panics

Panics if other is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(4).overflowing_next_multiple_of(Fix::from_num(1.5)),
    (Fix::from_num(4.5), false)
);
let max_minus_delta = Fix::MAX - Fix::DELTA;
assert_eq!(
    Fix::MAX.overflowing_next_multiple_of(max_minus_delta),
    (max_minus_delta.wrapping_mul_int(2), true)
);

Overflowing inverse linear interpolation between start and end.

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

The computed value can have a fixed-point type like self but with a different number of fractional bits.

Computes (self − start) / (end − start). This is 0 when self = start, and 1 when self = end.

Panics

Panics when start = end.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let two = Fix::from_num(2);
let four = Fix::from_num(4);
assert_eq!(
    Fix::from_num(3).overflowing_inv_lerp::<4>(two, four),
    (Fix::from_num(0.5), false)
);
assert_eq!(
    Fix::MAX.overflowing_inv_lerp::<4>(Fix::ZERO, Fix::from_num(0.5)),
    (Fix::MAX.wrapping_mul_int(2), true)
);

Overflowing addition with an unsigned fixed-point number.

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

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(
    Fix::from_num(-5).overflowing_add_unsigned(UFix::from_num(3)),
    (Fix::from_num(-2), false)
);
assert_eq!(
    Fix::ZERO.overflowing_add_unsigned(UFix::MAX),
    (-Fix::DELTA, true)
);

Overflowing subtraction with an unsigned fixed-point number.

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

Examples
#![feature(generic_const_exprs)]

use fixed::{FixedI16, FixedU16};
type Fix = FixedI16<4>;
type UFix = FixedU16<4>;
assert_eq!(
    Fix::from_num(3).overflowing_sub_unsigned(UFix::from_num(5)),
    (Fix::from_num(-2), false)
);
assert_eq!(
    Fix::ZERO.overflowing_sub_unsigned(UFix::MAX),
    (Fix::DELTA, true)
);

The items in this block are implemented for FRAC in the range 0 ≤ FRAC ≤ 16.

Parses a string slice containing decimal digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary
let f = Fix::from_str("1.75");
let check = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(f, Ok(check));
let neg = Fix::from_str("-1.75");
assert_eq!(neg, Ok(-check));

Parses a string slice containing binary digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary
let f = Fix::from_str_binary("1.11");
let check = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(f, Ok(check));
let neg = Fix::from_str_binary("-1.11");
assert_eq!(neg, Ok(-check));

Parses a string slice containing octal digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary, 1.6 in octal
let f = Fix::from_str_octal("1.6");
let check = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(f, Ok(check));
let neg = Fix::from_str_octal("-1.6");
assert_eq!(neg, Ok(-check));

Parses a string slice containing hexadecimal digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary, 1.C in hexadecimal
let f = Fix::from_str_hex("1.C");
let check = Fix::from_bits(0b111 << (4 - 2));
assert_eq!(f, Ok(check));
let neg = Fix::from_str_hex("-1.C");
assert_eq!(neg, Ok(-check));

Parses a string slice containing decimal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
assert_eq!(I8F8::saturating_from_str("9999"), Ok(I8F8::MAX));
assert_eq!(I8F8::saturating_from_str("-9999"), Ok(I8F8::MIN));

Parses a string slice containing binary digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
assert_eq!(I8F8::saturating_from_str_binary("101100111000"), Ok(I8F8::MAX));
assert_eq!(I8F8::saturating_from_str_binary("-101100111000"), Ok(I8F8::MIN));

Parses a string slice containing octal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
assert_eq!(I8F8::saturating_from_str_octal("7777"), Ok(I8F8::MAX));
assert_eq!(I8F8::saturating_from_str_octal("-7777"), Ok(I8F8::MIN));

Prases a string slice containing hexadecimal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
assert_eq!(I8F8::saturating_from_str_hex("FFFF"), Ok(I8F8::MAX));
assert_eq!(I8F8::saturating_from_str_hex("-FFFF"), Ok(I8F8::MIN));

Parses a string slice containing decimal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
// 9999.5 = 15.5 + 256 × n
assert_eq!(I8F8::wrapping_from_str("9999.5"), Ok(I8F8::from_num(15.5)));
assert_eq!(I8F8::wrapping_from_str("-9999.5"), Ok(I8F8::from_num(-15.5)));

Parses a string slice containing binary digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0b1110001 << (8 - 1));
assert_eq!(I8F8::wrapping_from_str_binary("101100111000.1"), Ok(check));
assert_eq!(I8F8::wrapping_from_str_binary("-101100111000.1"), Ok(-check));

Parses a string slice containing octal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0o1654 << (8 - 3));
assert_eq!(I8F8::wrapping_from_str_octal("7165.4"), Ok(check));
assert_eq!(I8F8::wrapping_from_str_octal("-7165.4"), Ok(-check));

Parses a string slice containing hexadecimal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0xFFE);
assert_eq!(I8F8::wrapping_from_str_hex("C0F.FE"), Ok(check));
assert_eq!(I8F8::wrapping_from_str_hex("-C0F.FE"), Ok(-check));

Parses a string slice containing decimal digits to return a fixed-point number, panicking on overflow.

Rounding is to the nearest, with ties rounded to even.

Panics

Panics if the value does not fit or if there is a parsing error.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary
let f = Fix::unwrapped_from_str("1.75");
assert_eq!(f, Fix::from_bits(0b111 << (4 - 2)));

The following panics because of a parsing error.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _error = Fix::unwrapped_from_str("1.75.");

Parses a string slice containing binary digits to return a fixed-point number, panicking on overflow.

Rounding is to the nearest, with ties rounded to even.

Panics

Panics if the value does not fit or if there is a parsing error.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary
let f = Fix::unwrapped_from_str_binary("1.11");
assert_eq!(f, Fix::from_bits(0b111 << (4 - 2)));

The following panics because of a parsing error.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _error = Fix::unwrapped_from_str_binary("1.2");

Parses a string slice containing octal digits to return a fixed-point number, panicking on overflow.

Rounding is to the nearest, with ties rounded to even.

Panics

Panics if the value does not fit or if there is a parsing error.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary, 1.6 in octal
let f = Fix::unwrapped_from_str_octal("1.6");
assert_eq!(f, Fix::from_bits(0b111 << (4 - 2)));

The following panics because of a parsing error.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _error = Fix::unwrapped_from_str_octal("1.8");

Parses a string slice containing hexadecimal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

Panics

Panics if the value does not fit or if there is a parsing error.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// 1.75 is 1.11 in binary, 1.C in hexadecimal
let f = Fix::unwrapped_from_str_hex("1.C");
assert_eq!(f, Fix::from_bits(0b111 << (4 - 2)));

The following panics because of a parsing error.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _error = Fix::unwrapped_from_str_hex("1.G");

Parses a string slice containing decimal digits to return a fixed-point number.

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

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
assert_eq!(I8F8::overflowing_from_str("99.5"), Ok((I8F8::from_num(99.5), false)));
// 9999.5 = 15.5 + 256 × n
assert_eq!(I8F8::overflowing_from_str("-9999.5"), Ok((I8F8::from_num(-15.5), true)));

Parses a string slice containing binary digits to return a fixed-point number.

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

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0b1110001 << (8 - 1));
assert_eq!(I8F8::overflowing_from_str_binary("111000.1"), Ok((check, false)));
assert_eq!(I8F8::overflowing_from_str_binary("-101100111000.1"), Ok((-check, true)));

Parses a string slice containing octal digits to return a fixed-point number.

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

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0o1654 << (8 - 3));
assert_eq!(I8F8::overflowing_from_str_octal("165.4"), Ok((check, false)));
assert_eq!(I8F8::overflowing_from_str_octal("-7165.4"), Ok((-check, true)));

Parses a string slice containing hexadecimal digits to return a fixed-point number.

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

Rounding is to the nearest, with ties rounded to even.

Examples
#![feature(generic_const_exprs)]

use fixed::types::I8F8;
let check = I8F8::from_bits(0xFFE);
assert_eq!(I8F8::overflowing_from_str_hex("F.FE"), Ok((check, false)));
assert_eq!(I8F8::overflowing_from_str_hex("-C0F.FE"), Ok((-check, true)));

Integer base-10 logarithm, rounded down.

Panics

Panics if the fixed-point number is ≤ 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
assert_eq!(FixedI16::<2>::from_num(10).int_log10(), 1);
assert_eq!(FixedI16::<2>::from_num(9.75).int_log10(), 0);
assert_eq!(FixedI16::<6>::from_num(0.109375).int_log10(), -1);
assert_eq!(FixedI16::<6>::from_num(0.09375).int_log10(), -2);

Checked integer base-10 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
assert_eq!(FixedI16::<2>::ZERO.checked_int_log10(), None);
assert_eq!(FixedI16::<2>::from_num(10).checked_int_log10(), Some(1));
assert_eq!(FixedI16::<2>::from_num(9.75).checked_int_log10(), Some(0));
assert_eq!(FixedI16::<6>::from_num(0.109375).checked_int_log10(), Some(-1));
assert_eq!(FixedI16::<6>::from_num(0.09375).checked_int_log10(), Some(-2));

Returns the reciprocal (inverse) of the fixed-point number, 1/self.

Panics

Panics if the fixed-point number is zero.

When debug assertions are enabled, this method also panics if the reciprocal overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_recip instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2).recip(), Fix::from_num(0.5));

Euclidean division.

Panics

Panics if the divisor is zero.

When debug assertions are enabled, this method also panics if the division overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_div_euclid instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).div_euclid(Fix::from_num(2)), Fix::from_num(3));
assert_eq!(Fix::from_num(-7.5).div_euclid(Fix::from_num(2)), Fix::from_num(-4));

Euclidean division by an integer.

Panics

Panics if the divisor is zero.

When debug assertions are enabled, this method also panics if the division overflows. Overflow can only occur when dividing the minimum value by −1. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_div_euclid_int instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).div_euclid_int(2), Fix::from_num(3));
assert_eq!(Fix::from_num(-7.5).div_euclid_int(2), Fix::from_num(-4));

Remainder for Euclidean division by an integer.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).rem_euclid_int(2), Fix::from_num(1.5));
assert_eq!(Fix::from_num(-7.5).rem_euclid_int(2), Fix::from_num(0.5));

Linear interpolation between start and end.

Returns start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Panics

When debug assertions are enabled, this method panics if the result overflows. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_lerp instead.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let start = Fix::from_num(2);
let end = Fix::from_num(3.5);
assert_eq!(Fix::from_num(-1.0).lerp(start, end), 0.5);
assert_eq!(Fix::from_num(0.0).lerp(start, end), 2);
assert_eq!(Fix::from_num(0.5).lerp(start, end), 2.75);
assert_eq!(Fix::from_num(1.0).lerp(start, end), 3.5);
assert_eq!(Fix::from_num(2.0).lerp(start, end), 5);

Checked division. Returns the quotient, or None if the divisor is zero or on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::MAX.checked_div(Fix::ONE), Some(Fix::MAX));
assert_eq!(Fix::MAX.checked_div(Fix::ONE / 2), None);

Checked reciprocal. Returns the reciprocal, or None if self is zero or on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(2).checked_recip(), Some(Fix::from_num(0.5)));
assert_eq!(Fix::ZERO.checked_recip(), None);

Checked Euclidean division. Returns the quotient, or None if the divisor is zero or on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).checked_div_euclid(Fix::from_num(2)), Some(Fix::from_num(3)));
assert_eq!(Fix::from_num(7.5).checked_div_euclid(Fix::ZERO), None);
assert_eq!(Fix::MAX.checked_div_euclid(Fix::from_num(0.25)), None);
assert_eq!(Fix::from_num(-7.5).checked_div_euclid(Fix::from_num(2)), Some(Fix::from_num(-4)));

Checked fixed-point remainder for division by an integer. Returns the remainder, or None if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3.75).checked_rem_int(2), Some(Fix::from_num(1.75)));
assert_eq!(Fix::from_num(3.75).checked_rem_int(0), None);
assert_eq!(Fix::from_num(-3.75).checked_rem_int(2), Some(Fix::from_num(-1.75)));

Checked Euclidean division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).checked_div_euclid_int(2), Some(Fix::from_num(3)));
assert_eq!(Fix::from_num(7.5).checked_div_euclid_int(0), None);
assert_eq!(Fix::MIN.checked_div_euclid_int(-1), None);

Checked remainder for Euclidean division by an integer. Returns the remainder, or None if the divisor is zero or if the remainder results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
assert_eq!(Fix::from_num(7.5).checked_rem_euclid_int(2), Some(Fix::from_num(1.5)));
assert_eq!(Fix::from_num(7.5).checked_rem_euclid_int(0), None);
assert_eq!(Fix::from_num(-7.5).checked_rem_euclid_int(2), Some(Fix::from_num(0.5)));
// -8 ≤ Fix < 8, so the answer 12.5 overflows
assert_eq!(Fix::from_num(-7.5).checked_rem_euclid_int(20), None);

Checked linear interpolation between start and end. Returns None on overflow.

The interpolted value is start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(0.5).checked_lerp(Fix::ZERO, Fix::MAX), Some(Fix::MAX / 2));
assert_eq!(Fix::from_num(1.5).checked_lerp(Fix::ZERO, Fix::MAX), None);

Saturating division. Returns the quotient, saturating on overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_half = Fix::ONE / 2;
assert_eq!(Fix::ONE.saturating_div(Fix::from_num(2)), one_half);
assert_eq!(Fix::MAX.saturating_div(one_half), Fix::MAX);

Saturating reciprocal. Returns the reciprocal, saturating on overflow.

Panics

Panics if the fixed-point number is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
// only one integer bit
type Fix = FixedI16<15>;
assert_eq!(Fix::from_num(0.25).saturating_recip(), Fix::MAX);
assert_eq!(Fix::from_num(-0.25).saturating_recip(), Fix::MIN);

Saturating Euclidean division. Returns the quotient, saturating on overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).saturating_div_euclid(Fix::from_num(2)), Fix::from_num(3));
assert_eq!(Fix::MAX.saturating_div_euclid(Fix::from_num(0.25)), Fix::MAX);
assert_eq!(Fix::from_num(-7.5).saturating_div_euclid(Fix::from_num(2)), Fix::from_num(-4));
assert_eq!(Fix::MIN.saturating_div_euclid(Fix::from_num(0.25)), Fix::MIN);

Saturating Euclidean division by an integer. Returns the quotient, saturating on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).saturating_div_euclid_int(2), Fix::from_num(3));
assert_eq!(Fix::from_num(-7.5).saturating_div_euclid_int(2), Fix::from_num(-4));
assert_eq!(Fix::MIN.saturating_div_euclid_int(-1), Fix::MAX);

Saturating remainder for Euclidean division by an integer. Returns the remainder, saturating on overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
assert_eq!(Fix::from_num(7.5).saturating_rem_euclid_int(2), Fix::from_num(1.5));
assert_eq!(Fix::from_num(-7.5).saturating_rem_euclid_int(2), Fix::from_num(0.5));
// -8 ≤ Fix < 8, so the answer 12.5 saturates
assert_eq!(Fix::from_num(-7.5).saturating_rem_euclid_int(20), Fix::MAX);

Linear interpolation between start and end, saturating on overflow.

The interpolated value is start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(0.5).saturating_lerp(Fix::ZERO, Fix::MAX), Fix::MAX / 2);
assert_eq!(Fix::from_num(1.5).saturating_lerp(Fix::ZERO, Fix::MAX), Fix::MAX);
assert_eq!(Fix::from_num(-2.0).saturating_lerp(Fix::ZERO, Fix::MAX), Fix::MIN);
assert_eq!(Fix::from_num(3.0).saturating_lerp(Fix::MAX, Fix::ZERO), Fix::MIN);

Wrapping division. Returns the quotient, wrapping on overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).wrapping_div(Fix::from_num(2)), one_point_5);
let quarter = Fix::ONE / 4;
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.wrapping_div(quarter), wrapped);

Wrapping reciprocal. Returns the reciprocal, wrapping on overflow.

Panics

Panics if the fixed-point number is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
// only one integer bit
type Fix = FixedI16<15>;
assert_eq!(Fix::from_num(0.25).wrapping_recip(), Fix::ZERO);

Wrapping Euclidean division. Returns the quotient, wrapping on overflow.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).wrapping_div_euclid(Fix::from_num(2)), Fix::from_num(3));
let wrapped = Fix::MAX.wrapping_mul_int(4).round_to_zero();
assert_eq!(Fix::MAX.wrapping_div_euclid(Fix::from_num(0.25)), wrapped);

Wrapping Euclidean division by an integer. Returns the quotient, wrapping on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).wrapping_div_euclid_int(2), Fix::from_num(3));
assert_eq!(Fix::from_num(-7.5).wrapping_div_euclid_int(2), Fix::from_num(-4));
let wrapped = Fix::MIN.round_to_zero();
assert_eq!(Fix::MIN.wrapping_div_euclid_int(-1), wrapped);

Wrapping remainder for Euclidean division by an integer. Returns the remainder, wrapping on overflow.

Note that while remainder for Euclidean division cannot be negative, the wrapped value can be negative.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
assert_eq!(Fix::from_num(7.5).wrapping_rem_euclid_int(2), Fix::from_num(1.5));
assert_eq!(Fix::from_num(-7.5).wrapping_rem_euclid_int(2), Fix::from_num(0.5));
// -8 ≤ Fix < 8, so the answer 12.5 wraps to -3.5
assert_eq!(Fix::from_num(-7.5).wrapping_rem_euclid_int(20), Fix::from_num(-3.5));

Linear interpolation between start and end, wrapping on overflow.

The interpolated value is start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(0.5).wrapping_lerp(Fix::ZERO, Fix::MAX), Fix::MAX / 2);
assert_eq!(
    Fix::from_num(1.5).wrapping_lerp(Fix::ZERO, Fix::MAX),
    Fix::MAX.wrapping_add(Fix::MAX / 2)
);

Unwrapped division. Returns the quotient, panicking on overflow.

Panics

Panics if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).unwrapped_div(Fix::from_num(2)), one_point_5);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let quarter = Fix::ONE / 4;
let _overflow = Fix::MAX.unwrapped_div(quarter);

Unwrapped reciprocal. Returns the reciprocal, panicking on overflow.

Panics

Panics if the fixed-point number is zero or on overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(0.25).unwrapped_recip(), Fix::from_num(4));

Unwrapped Euclidean division. Returns the quotient, panicking on overflow.

Panics

Panics if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).unwrapped_div_euclid(Fix::from_num(2)), Fix::from_num(3));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MAX.unwrapped_div_euclid(Fix::from_num(0.25));

Unwrapped fixed-point remainder for division by an integer. Returns the remainder, panicking if the divisor is zero.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(3.75).unwrapped_rem_int(2), Fix::from_num(1.75));

The following panics because the divisor is zero.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _divisor_is_zero = Fix::from_num(3.75).unwrapped_rem_int(0);

Unwrapped Euclidean division by an integer. Returns the quotient, panicking on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).unwrapped_div_euclid_int(2), Fix::from_num(3));
assert_eq!(Fix::from_num(-7.5).unwrapped_div_euclid_int(2), Fix::from_num(-4));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::MIN.unwrapped_div_euclid_int(-1);

Unwrapped remainder for Euclidean division by an integer. Returns the remainder, panicking on overflow.

Note that while remainder for Euclidean division cannot be negative, the wrapped value can be negative.

Panics

Panics if the divisor is zero or if the division results in overflow.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
assert_eq!(Fix::from_num(7.5).unwrapped_rem_euclid_int(2), Fix::from_num(1.5));
assert_eq!(Fix::from_num(-7.5).unwrapped_rem_euclid_int(2), Fix::from_num(0.5));

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
// -8 ≤ Fix < 8, so the answer 12.5 overflows
let _overflow = Fix::from_num(-7.5).unwrapped_rem_euclid_int(20);

Linear interpolation between start and end, panicking on overflow.

The interpolated value is start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Panics

Panics if the result overflows.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(0.5).unwrapped_lerp(Fix::ZERO, Fix::MAX), Fix::MAX / 2);

The following panics because of overflow.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let _overflow = Fix::from_num(1.5).unwrapped_lerp(Fix::ZERO, Fix::MAX);

Overflowing division.

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

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let one_point_5 = Fix::from_bits(0b11 << (4 - 1));
assert_eq!(Fix::from_num(3).overflowing_div(Fix::from_num(2)), (one_point_5, false));
let quarter = Fix::ONE / 4;
let wrapped = Fix::from_bits(!0 << 2);
assert_eq!(Fix::MAX.overflowing_div(quarter), (wrapped, true));

Overflowing reciprocal.

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

Panics

Panics if the fixed-point number is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
// only one integer bit
type Small = FixedI16<15>;
assert_eq!(Fix::from_num(0.25).overflowing_recip(), (Fix::from_num(4), false));
assert_eq!(Small::from_num(0.25).overflowing_recip(), (Small::ZERO, true));

Overflowing Euclidean division.

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

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
let check = Fix::from_num(3);
assert_eq!(Fix::from_num(7.5).overflowing_div_euclid(Fix::from_num(2)), (check, false));
let wrapped = Fix::MAX.wrapping_mul_int(4).round_to_zero();
assert_eq!(Fix::MAX.overflowing_div_euclid(Fix::from_num(0.25)), (wrapped, true));

Overflowing Euclidean division by an integer.

Returns a tuple of the quotient and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned. Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::from_num(7.5).overflowing_div_euclid_int(2), (Fix::from_num(3), false));
assert_eq!(Fix::from_num(-7.5).overflowing_div_euclid_int(2), (Fix::from_num(-4), false));
let wrapped = Fix::MIN.round_to_zero();
assert_eq!(Fix::MIN.overflowing_div_euclid_int(-1), (wrapped, true));

Remainder for Euclidean division by an integer.

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

Note that while remainder for Euclidean division cannot be negative, the wrapped value can be negative.

Panics

Panics if the divisor is zero.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<12>;
assert_eq!(Fix::from_num(7.5).overflowing_rem_euclid_int(2), (Fix::from_num(1.5), false));
assert_eq!(Fix::from_num(-7.5).overflowing_rem_euclid_int(2), (Fix::from_num(0.5), false));
// -8 ≤ Fix < 8, so the answer 12.5 wraps to -3.5
assert_eq!(Fix::from_num(-7.5).overflowing_rem_euclid_int(20), (Fix::from_num(-3.5), true));

Overflowing linear interpolation between start and end.

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

The interpolated value is start + self × (end − start). This is start when self = 0, end when self = 1, and linear interpolation for all other values of self. Linear extrapolation is performed if self is not in the range 0 ≤ x ≤ 1.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(
    Fix::from_num(0.5).overflowing_lerp(Fix::ZERO, Fix::MAX),
    (Fix::MAX / 2, false)
);
assert_eq!(
    Fix::from_num(1.5).overflowing_lerp(Fix::ZERO, Fix::MAX),
    (Fix::MAX.wrapping_add(Fix::MAX / 2), true)
);

This block contains constants in the range 0.125 ≤ x < 0.25.

These constants are not representable in signed fixed-point numbers with less than −1 integer bits.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<17>;
assert_eq!(Fix::FRAC_1_TAU, Fix::from_num(consts::FRAC_1_TAU));

The following example fails to compile, since the maximum representable value with 18 fractional bits and −2 integer bits is < 0.125.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<18>;
let _ = Fix::FRAC_1_TAU;

1/τ = 0.159154…

This block contains constants in the range 0.25 ≤ x < 0.5.

These constants are not representable in signed fixed-point numbers with less than 0 integer bits.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<16>;
assert_eq!(Fix::LOG10_2, Fix::from_num(consts::LOG10_2));

The following example fails to compile, since the maximum representable value with 17 fractional bits and −1 integer bits is < 0.25.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<17>;
let _ = Fix::LOG10_2;

2/τ = 0.318309…

π/8 = 0.392699…

1/π = 0.318309…

log10 2 = 0.301029…

log10 e = 0.434294…

This block contains constants in the range 0.5 ≤ x < 1, and −1.

These constants are not representable in signed fixed-point numbers with less than 1 integer bit.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<15>;
assert_eq!(Fix::LN_2, Fix::from_num(consts::LN_2));
assert!(0.5 <= Fix::LN_2  && Fix::LN_2 < 1);

The following example fails to compile, since the maximum representable value with 16 fractional bits and 0 integer bits is < 0.5.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<16>;
let _ = Fix::LN_2;

Negative one.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<15>;
assert_eq!(Fix::NEG_ONE, Fix::from_num(-1));

The following would fail as FixedI16<15> cannot represent 1, so there is no FixedI16::<15>::ONE.

#![feature(generic_const_exprs)]

use fixed::FixedI16;
const _ERROR: FixedI16<15> = FixedI16::ONE.unwrapped_neg();

τ/8 = 0.785398…

τ/12 = 0.523598…

4/τ = 0.636619…

π/4 = 0.785398…

π/6 = 0.523598…

2/π = 0.636619…

1/√π = 0.564189…

1/√2 = 0.707106…

1/√3 = 0.577350…

ln 2 = 0.693147…

The golden ratio conjugate, Φ = 1/φ = 0.618033…

The Euler-Mascheroni constant, γ = 0.577215…

Catalan’s constant = 0.915965…

This block contains constants in the range 1 ≤ x < 2.

These constants are not representable in signed fixed-point numbers with less than 2 integer bits.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<14>;
assert_eq!(Fix::LOG2_E, Fix::from_num(consts::LOG2_E));
assert!(1 <= Fix::LOG2_E && Fix::LOG2_E < 2);

The following example fails to compile, since the maximum representable value with 15 fractional bits and 1 integer bit is < 1.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<15>;
let _ = Fix::LOG2_E;

One.

Examples
#![feature(generic_const_exprs)]

use fixed::FixedI16;
type Fix = FixedI16<4>;
assert_eq!(Fix::ONE, Fix::from_num(1));

τ/4 = 1.57079…

τ/6 = 1.04719…

π/2 = 1.57079…

π/3 = 1.04719…

√π = 1.77245…

2/√π = 1.12837…

√2 = 1.41421…

√3 = 1.73205…

√e = 1.64872…

log2 e = 1.44269…

The golden ratio, φ = 1.61803…

√φ = 1.27201…

This block contains constants in the range 2 ≤ x < 4.

These constants are not representable in signed fixed-point numbers with less than 3 integer bits.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<13>;
assert_eq!(Fix::E, Fix::from_num(consts::E));
assert!(2 <= Fix::E && Fix::E < 4);

The following example fails to compile, since the maximum representable value with 14 fractional bits and 2 integer bits is < 2.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<14>;
let _ = Fix::E;

τ/2 = 3.14159…

τ/3 = 2.09439…

Archimedes’ constant, π = 3.14159…

Euler’s number, e = 2.71828…

log2 10 = 3.32192…

ln 10 = 2.30258…

This block contains constants in the range 4 ≤ x < 8.

These constants are not representable in signed fixed-point numbers with less than 4 integer bits.

Examples

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<12>;
assert_eq!(Fix::TAU, Fix::from_num(consts::TAU));
assert!(4 <= Fix::TAU && Fix::TAU < 8);

The following example fails to compile, since the maximum representable value with 13 fractional bits and 3 integer bits is < 4.

#![feature(generic_const_exprs)]

use fixed::{consts, FixedI16};
type Fix = FixedI16<13>;
let _ = Fix::TAU;

A turn, τ = 6.28318…

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Generate an arbitrary value of Self from the given unstructured data. Read more

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

Formats the value using the given formatter.

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more

Deserialize this instance from a slice of bytes.

Serialize this instance into a vector of bytes.

Returns the smallest finite number this type can represent

Returns the largest finite number this type can represent

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Adds two numbers, checking for overflow. If overflow happens, None is returned. Read more

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Divides two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned. Read more

Multiplies two numbers, checking for underflow or overflow. If underflow or overflow happens, None is returned. Read more

Negates a number, returning None for results that can’t be represented, like signed MIN values that can’t be positive, or non-zero unsigned values that can’t be negative. Read more

Finds the remainder of dividing two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned. Read more

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self. Read more

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self. Read more

Subtracts two numbers, checking for underflow. If underflow happens, None is returned. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

The primitive integer underlying type. Read more

The non-zero wrapped version of Bits. Read more

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

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

Zero. Read more

The difference between any two successive representable numbers, Δ. Read more

The smallest value that can be represented. Read more

The largest value that can be represented. Read more

true if the type is signed. Read more

The number of integer bits. Read more

The number of fractional bits. Read more

Creates a fixed-point number that has a bitwise representation identical to the given integer. Read more

Creates an integer that has a bitwise representation identical to the given fixed-point number. Read more

Converts a fixed-point number from big endian to the target’s endianness. Read more

Converts a fixed-point number from little endian to the target’s endianness. Read more

Converts this fixed-point number to big endian from the target’s endianness. Read more

Converts this fixed-point number to little endian from the target’s endianness. Read more

Reverses the byte order of the fixed-point number. Read more

Creates a fixed-point number from its representation as a byte array in big endian. Read more

Creates a fixed-point number from its representation as a byte array in little endian. Read more

Creates a fixed-point number from its representation as a byte array in native endian. Read more

Returns the memory representation of this fixed-point number as a byte array in big-endian byte order. Read more

Returns the memory representation of this fixed-point number as a byte array in little-endian byte order. Read more

Returns the memory representation of this fixed-point number as a byte array in native byte order. Read more

Creates a fixed-point number from another number. Read more

Converts a fixed-point number to another number. Read more

Creates a fixed-point number from another number if it fits, otherwise returns None. Read more

Converts a fixed-point number to another number if it fits, otherwise returns None. Read more

Creates a fixed-point number from another number, saturating the value if it does not fit. Read more

Converts a fixed-point number to another number, saturating the value if it does not fit. Read more

Creates a fixed-point number from another number, wrapping the value on overflow. Read more

Converts a fixed-point number to another number, wrapping the value on overflow. Read more

Creates a fixed-point number from another number, panicking on overflow. Read more

Converts a fixed-point number to another number, panicking on overflow. Read more

Creates a fixed-point number from another number. Read more

Converts a fixed-point number to another number. Read more

Returns the integer part. Read more

Returns the fractional part. Read more

Rounds to the next integer towards +∞. Read more

Rounds to the next integer towards −∞. Read more

Rounds to the next integer towards 0. Read more

Rounds to the nearest integer, with ties rounded away from zero. Read more

Rounds to the nearest integer, with ties rounded to even. Read more

Checked ceil. Rounds to the next integer towards +∞, returning None on overflow. Read more

Checked floor. Rounds to the next integer towards −∞, returning None on overflow. Read more

Checked round. Rounds to the nearest integer, with ties rounded away from zero, returning None on overflow. Read more

Checked round. Rounds to the nearest integer, with ties rounded to even, returning None on overflow. Read more

Saturating ceil. Rounds to the next integer towards +∞, saturating on overflow. Read more

Saturating floor. Rounds to the next integer towards −∞, saturating on overflow. Read more

Saturating round. Rounds to the nearest integer, with ties rounded away from zero, and saturating on overflow. Read more

Saturating round. Rounds to the nearest integer, with ties rounded to_even, and saturating on overflow. Read more

Wrapping ceil. Rounds to the next integer towards +∞, wrapping on overflow. Read more

Wrapping floor. Rounds to the next integer towards −∞, wrapping on overflow. Read more

Wrapping round. Rounds to the next integer to the nearest, with ties rounded away from zero, and wrapping on overflow. Read more

Wrapping round. Rounds to the next integer to the nearest, with ties rounded to even, and wrapping on overflow. Read more

Unwrapped ceil. Rounds to the next integer towards +∞, panicking on overflow. Read more

Unwrapped floor. Rounds to the next integer towards −∞, panicking on overflow. Read more

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded away from zero, and panicking on overflow. Read more

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded to even, and panicking on overflow. Read more

Overflowing ceil. Rounds to the next integer towards +∞. Read more

Overflowing floor. Rounds to the next integer towards −∞. Read more

Overflowing round. Rounds to the next integer to the nearest, with ties rounded away from zero. Read more

Overflowing round. Rounds to the next integer to the nearest, with ties rounded to even. Read more

Returns the number of ones in the binary representation. Read more

Returns the number of zeros in the binary representation. Read more

Returns the number of leading ones in the binary representation. Read more

Returns the number of leading zeros in the binary representation. Read more

Returns the number of trailing ones in the binary representation. Read more

Returns the number of trailing zeros in the binary representation. Read more

Integer base-2 logarithm, rounded down. Read more

Checked integer base-2 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0. Read more

Reverses the order of the bits of the fixed-point number. Read more

Shifts to the left by n bits, wrapping the truncated bits to the right end. Read more

Shifts to the right by n bits, wrapping the truncated bits to the left end. Read more

Returns true if the number is zero. Read more

Returns the distance from self to other. Read more

Returns the absolute value of the difference between self and other using an unsigned type without any wrapping or panicking. Read more

Returns the mean of self and other. Read more

Returns the next multiple of other. Read more

Multiply and add. Returns self × mul + add. Read more

Adds self to the product a × b. Read more

Multiply and accumulate. Adds (a × b) to self. Read more

Remainder for Euclidean division. Read more

Checked negation. Returns the negated value, or None on overflow. Read more

Checked addition. Returns the sum, or None on overflow. Read more

Checked subtraction. Returns the difference, or None on overflow. Read more

Checked multiplication. Returns the product, or None on overflow. Read more

Checked remainder. Returns the remainder, or None if the divisor is zero. Read more

Checked next multiple of other. Returns the next multiple, or None if other is zero or on overflow. Read more

Checked multiply and add. Returns self × mul + add, or None on overflow. Read more

Adds self to the product a × b, returning None on overflow. Read more

Checked multiply and accumulate. Adds (a × b) to self, or returns None on overflow. Read more

Checked remainder for Euclidean division. Returns the remainder, or None if the divisor is zero. Read more

Checked multiplication by an integer. Returns the product, or None on overflow. Read more

Checked division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow. Read more

Checked shift left. Returns the shifted number, or None if rhs ≥ the number of bits. Read more

Checked shift right. Returns the shifted number, or None if rhs ≥ the number of bits. Read more

Checked distance. Returns the distance from self to other, or None on overflow. Read more

Saturated negation. Returns the negated value, saturating on overflow. Read more

Saturating addition. Returns the sum, saturating on overflow. Read more

Saturating subtraction. Returns the difference, saturating on overflow. Read more

Saturating multiplication. Returns the product, saturating on overflow. Read more

Saturating next multiple of other. Read more

Saturating multiply and add. Returns self × mul + add, saturating on overflow. Read more

Adds self to the product a × b, saturating on overflow. Read more

Saturating multiply and add. Adds (a × b) to self, saturating on overflow. Read more

Saturating multiplication by an integer. Returns the product, saturating on overflow. Read more

Saturating distance. Returns the distance from self to other, saturating on overflow. Read more

Wrapping negation. Returns the negated value, wrapping on overflow. Read more

Wrapping addition. Returns the sum, wrapping on overflow. Read more

Wrapping subtraction. Returns the difference, wrapping on overflow. Read more

Wrapping multiplication. Returns the product, wrapping on overflow. Read more

Wrapping next multiple of other. Read more

Wrapping multiply and add. Returns self × mul + add, wrapping on overflow. Read more

Adds self to the product a × b, wrapping on overflow. Read more

Wrapping multiply and accumulate. Adds (a × b) to self, wrapping on overflow. Read more

Wrapping multiplication by an integer. Returns the product, wrapping on overflow. Read more

Wrapping division by an integer. Returns the quotient, wrapping on overflow. Read more

Wrapping shift left. Wraps rhs if rhs ≥ the number of bits, then shifts and returns the number. Read more

Wrapping shift right. Wraps rhs if rhs ≥ the number of bits, then shifts and returns the number. Read more

Wrapping distance. Returns the distance from self to other, wrapping on overflow. Read more

Unwrapped negation. Returns the negated value, panicking on overflow. Read more

Unwrapped addition. Returns the sum, panicking on overflow. Read more

Unwrapped subtraction. Returns the difference, panicking on overflow. Read more

Unwrapped multiplication. Returns the product, panicking on overflow. Read more

Unwrapped remainder. Returns the quotient, panicking if the divisor is zero. Read more

Unwrapped next multiple of other. Returns the next multiple, panicking on overflow. Read more

Unwrapped multiply and add. Returns self × mul + add, panicking on overflow. Read more

Adds self to the product a × b, panicking on overflow. Read more

Unwrapped multiply and accumulate. Adds (a × b) to self, panicking on overflow. Read more

Unwrapped remainder for Euclidean division. Returns the remainder, panicking if the divisor is zero. Read more

Unwrapped multiplication by an integer. Returns the product, panicking on overflow. Read more

Unwrapped division by an integer. Returns the quotient, panicking on overflow. Read more

Unwrapped shift left. Panics if rhs ≥ the number of bits. Read more

Unwrapped shift right. Panics if rhs ≥ the number of bits. Read more

Unwrapped distance. Returns the distance from self to other, panicking on overflow. Read more

Overflowing negation. Read more

Overflowing addition. Read more

Overflowing subtraction. Read more

Overflowing multiplication. Read more

Overflowing next multiple of other. Read more

Overflowing multiply and add. Read more

Adds self to the product a × b. Read more

Overflowing multiply and accumulate. Adds (a × b) to self, wrapping and returning true if overflow occurs. Read more

Overflowing multiplication by an integer. Read more

Overflowing division by an integer. Read more

Overflowing shift left. Read more

Overflowing shift right. Read more

Overflowing distance. Read more

Returns a reference to self as FixedSigned if the type is signed, or None if it is unsigned. Read more

Returns a reference to self as FixedUnsigned if the type is unsigned, or None if it is signed. Read more

Returns a mutable reference to self as FixedSigned if the type is signed, or None if it is unsigned. Read more

Returns a mutable reference to self as FixedUnsigned if the type is unsigned, or None if it is signed. Read more

Returns the number of bits required to represent the value. Read more

Returns true if the number is > 0. Read more

Returns true if the number is < 0. Read more

Returns the absolute value. Read more

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

Returns the distance from self to other using an unsigned type without any wrapping or panicking. Read more

Returns a number representing the sign of self. Read more

Addition with an unsigned fixed-point number. Read more

Subtraction with an unsigned fixed-point number. Read more

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

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

Checked addition with an unsigned fixed-point number. Returns the sum, or None on overflow. Read more

Checked subtraction with an unsigned fixed-point number. Returns the difference, or None on overflow. Read more

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

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

Saturating addition with an unsigned fixed-point number. Returns the sum, saturating on overflow. Read more

Saturating subtraction with an unsigned fixed-point number. Returns the difference, saturating on overflow. Read more

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

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

Wrapping addition with an unsigned fixed-point number. Returns the sum, wrapping on overflow. Read more

Wrapping subtraction with an unsigned fixed-point number. Returns the difference, wrapping on overflow. Read more

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

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

Unwrapped addition with an unsigned fixed-point number. Returns the sum, panicking on overflow. Read more

Unwrapped subtraction with an unsigned fixed-point number. Returns the difference, panicking on overflow. Read more

Overflowing absolute value. Read more

Overflowing signum. Read more

Overflowing addition with an unsigned fixed-point number. Read more

Overflowing subtraction with an unsigned fixed-point number. Read more

Parses a string slice containing binary digits to return a fixed-point number. Read more

Parses a string slice containing octal digits to return a fixed-point number. Read more

Parses a string slice containing hexadecimal digits to return a fixed-point number. Read more

Parses a string slice containing decimal digits to return a fixed-point number, saturating on overflow. Read more

Parses a string slice containing binary digits to return a fixed-point number, saturating on overflow. Read more

Parses a string slice containing octal digits to return a fixed-point number, saturating on overflow. Read more

Parses a string slice containing hexadecimal digits to return a fixed-point number, saturating on overflow. Read more

Parses a string slice containing decimal digits to return a fixed-point number, wrapping on overflow. Read more

Parses a string slice containing binary digits to return a fixed-point number, wrapping on overflow. Read more

Parses a string slice containing octal digits to return a fixed-point number, wrapping on overflow. Read more

Parses a string slice containing hexadecimal digits to return a fixed-point number, wrapping on overflow. Read more

Parses a string slice containing decimal digits to return a fixed-point number, panicking on overflow. Read more

Parses a string slice containing binary digits to return a fixed-point number, panicking on overflow. Read more

Parses a string slice containing octal digits to return a fixed-point number, panicking on overflow. Read more

Parses a string slice containing hexadecimal digits to return a fixed-point number, panicking on overflow. Read more

Parses a string slice containing decimal digits to return a fixed-point number. Read more

Parses a string slice containing binary digits to return a fixed-point number. Read more

Parses a string slice containing octal digits to return a fixed-point number. Read more

Parses a string slice containing hexadecimal digits to return a fixed-point number. Read more

Integer base-10 logarithm, rounded down. Read more

Checked integer base-10 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0. Read more

Returns the reciprocal. Read more

Euclidean division by an integer. Read more

Euclidean division by an integer. Read more

Remainder for Euclidean division by an integer. Read more

Linear interpolation between start and end. Read more

Inverse linear interpolation between start and end. Read more

Checked division. Returns the quotient, or None if the divisor is zero or on overflow. Read more

Checked reciprocal. Returns the reciprocal, or None if self is zero or on overflow. Read more

Checked remainder for Euclidean division. Returns the remainder, or None if the divisor is zero or the division results in overflow. Read more

Checked fixed-point remainder for division by an integer. Returns the remainder, or None if the divisor is zero or if the division results in overflow. Read more

Checked Euclidean division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow. Read more

Checked remainder for Euclidean division by an integer. Returns the remainder, or None if the divisor is zero or if the remainder results in overflow. Read more

Checked linear interpolation between start and end. Returns None on overflow. Read more

Checked inverse linear interpolation between start and end. Returns None when start = end or on overflow. Read more

Saturating division. Returns the quotient, saturating on overflow. Read more

Saturating reciprocal. Read more

Saturating Euclidean division. Returns the quotient, saturating on overflow. Read more

Saturating Euclidean division by an integer. Returns the quotient, saturating on overflow. Read more

Saturating remainder for Euclidean division by an integer. Returns the remainder, saturating on overflow. Read more

Linear interpolation between start and end, saturating on overflow. Read more

Inverse linear interpolation between start and end, saturating on overflow. Read more

Wrapping division. Returns the quotient, wrapping on overflow. Read more

Wrapping reciprocal. Read more

Wrapping Euclidean division. Returns the quotient, wrapping on overflow. Read more

Wrapping Euclidean division by an integer. Returns the quotient, wrapping on overflow. Read more

Wrapping remainder for Euclidean division by an integer. Returns the remainder, wrapping on overflow. Read more

Linear interpolation between start and end, wrapping on overflow. Read more

Inverse linear interpolation between start and end, wrapping on overflow. Read more

Unwrapped division. Returns the quotient, panicking on overflow. Read more

Unwrapped reciprocal. Returns reciprocal, panicking on overflow. Read more

Unwrapped Euclidean division. Returns the quotient, panicking on overflow. Read more

Unwrapped remainder for division by an integer. Returns the remainder, panicking if the divisor is zero. Read more

Unwrapped Euclidean division by an integer. Returns the quotient, panicking on overflow. Read more

Unwrapped remainder for Euclidean division by an integer. Returns the remainder, panicking on overflow. Read more

Linear interpolation between start and end, panicking on overflow. Read more

Inverse linear interpolation between start and end, panicking on overflow. Read more

Overflowing division. Read more

Overflowing reciprocal. Read more

Overflowing Euclidean division. Read more

Overflowing Euclidean division by an integer. Read more

Overflowing remainder for Euclidean division by an integer. Read more

Overflowing linear interpolation between start and end. Read more

Overflowing inverse linear interpolation between start and end. Read more

Return Euler’s number.

Return 1.0 / π.

Return 1.0 / sqrt(2.0).

Return 2.0 / π.

Return 2.0 / sqrt(π).

Return π / 2.0.

Return π / 3.0.

Return π / 4.0.

Return π / 6.0.

Return π / 8.0.

Return ln(10.0).

Return ln(2.0).

Return log10(e).

Return log2(e).

Return Archimedes’ constant π.

Return sqrt(2.0).

Return the full circle constant τ.

Return log10(2.0).

Return log2(10.0).

Converts a fixed-point number to an integer.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to an integer.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to an integer.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to an integer.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number to an integer.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a Boolean value to a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts an integer to a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts an integer to a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts an integer to a fixed-point number.

This conversion never fails (infallible) and does not lose any precision (lossless).

Converts a fixed-point number.

Any extra fractional bits are discarded, which rounds towards −∞.

Panics

When debug assertions are enabled, panics if the value does not fit. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_from_fixed instead.

Converts a fixed-point number if it fits, otherwise returns None.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, saturating if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, wrapping if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number.

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

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, panicking if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Panics

Panics if the value does not fit, even when debug assertions are not enabled.

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

Parses a string slice to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

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

The result after applying the operator.

Returns the multiplicative inverse of self. Read more

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number to a floating-point number.

This conversion may fail (fallible) but cannot lose precision (lossless). As a consequency, ∞ are −∞ are never returned, as they would lose precision.

Converts a fixed-point number to a floating-point number.

This conversion may fail (fallible) but cannot lose precision (lossless). As a consequency, ∞ are −∞ are never returned, as they would lose precision.

Converts a fixed-point number to a floating-point number.

This conversion may fail (fallible) but cannot lose precision (lossless). As a consequency, ∞ are −∞ are never returned, as they would lose precision.

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number.

This conversion may fail (fallible) but does not lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number to an integer.

This conversion may fail (fallible) but cannot lose precision (lossless).

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) but may lose precision (lossy). Rounding is to the nearest, with ties rounded to even.

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) but may lose precision (lossy). Rounding is to the nearest, with ties rounded to even.

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) but may lose precision (lossy). Rounding is to the nearest, with ties rounded to even.

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) but may lose precision (lossy). Rounding is to the nearest, with ties rounded to even.

Converts a fixed-point number to a floating-point number.

This conversion never fails (infallible) but may lose precision (lossy). Rounding is to the nearest, with ties rounded to even.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number to an integer.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts a Boolean value to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Converts an integer to a fixed-point number.

This conversion never fails (infallible) but may lose precision (lossy). Any low-significance bits in the source that cannot be represented in the destination are discarded, which rounds towards −∞.

Formats the value using the given formatter.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the fused multiply-add.

Performs the fused multiply-add operation.

Performs the fused multiply-add operation.

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Convert from a string and radix (typically 2..=36). Read more

Formats the value using the given formatter.

Returns the multiplicative identity element of Self, 1. Read more

Sets self to the multiplicative identity element of Self, 1.

Returns true if self is equal to the multiplicative identity. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned. Read more

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Returns a tuple of the product along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned. Read more

Returns a tuple of the difference along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

Saturating addition. Computes self + other, saturating at the relevant high or low boundary of the type. Read more

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Saturating multiplication. Computes self * other, saturating at the relevant high or low boundary of the type. Read more

Saturating subtraction. Computes self - other, saturating at the relevant high or low boundary of the type. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

Performs the <<= operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Performs the >>= operation. Read more

Computes the absolute value. Read more

The positive difference of two numbers. Read more

Returns the sign of the number. Read more

Returns true if the number is positive and false if the number is zero or negative.

Returns true if the number is negative and false if the number is zero or positive.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Converts a fixed-point number.

Any extra fractional bits are discarded, which rounds towards −∞.

Panics

When debug assertions are enabled, panics if the value does not fit. When debug assertions are not enabled, the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_to_fixed instead.

Converts a fixed-point number if it fits, otherwise returns None.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, saturating if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, wrapping if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number.

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

Any extra fractional bits are discarded, which rounds towards −∞.

Converts a fixed-point number, panicking if it does not fit.

Any extra fractional bits are discarded, which rounds towards −∞.

Panics

Panics if the value does not fit, even when debug assertions are not enabled.

Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned. Read more

Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned. Read more

Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned. Read more

Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned. Read more

Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned. Read more

Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned. Read more

Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more

Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned. Read more

Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned. Read more

Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned. Read more

Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned. Read more

Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more

Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32. Read more

Converts the value of self to an f64. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f64. Read more

Convert the inner type into the wrapper type.

Convert a reference to the inner type into a reference to the wrapper type. Read more

Convert a mutable reference to the inner type into a mutable reference to the wrapper type. Read more

Convert a slice to the inner type into a slice to the wrapper type.

Convert a mutable slice to the inner type into a mutable slice to the wrapper type. Read more

Convert the wrapper type into the inner type.

Convert a reference to the wrapper type into a reference to the inner type. Read more

Convert a mutable reference to the wrapper type into a mutable reference to the inner type. Read more

Convert a slice to the wrapped type into a slice to the inner type.

Convert a mutable slice to the wrapped type into a mutable slice to the inner type. Read more

Convert the inner type into the wrapper type.

Convert a reference to the inner type into a reference to the wrapper type. Read more

Convert a mutable reference to the inner type into a mutable reference to the wrapper type. Read more

Convert a slice to the inner type into a slice to the wrapper type.

Convert a mutable slice to the inner type into a mutable slice to the wrapper type. Read more

Convert the wrapper type into the inner type.

Convert a reference to the wrapper type into a reference to the inner type. Read more

Convert a mutable reference to the wrapper type into a mutable reference to the inner type. Read more

Convert a slice to the wrapped type into a slice to the inner type.

Convert a mutable slice to the wrapped type into a mutable slice to the inner type. Read more

Convert the inner type into the wrapper type.

Convert a reference to the inner type into a reference to the wrapper type. Read more

Convert a mutable reference to the inner type into a mutable reference to the wrapper type. Read more

Convert a slice to the inner type into a slice to the wrapper type.

Convert a mutable slice to the inner type into a mutable slice to the wrapper type. Read more

Convert the wrapper type into the inner type.

Convert a reference to the wrapper type into a reference to the inner type. Read more

Convert a mutable reference to the wrapper type into a mutable reference to the inner type. Read more

Convert a slice to the wrapped type into a slice to the inner type.

Convert a mutable slice to the wrapped type into a mutable slice to the inner type. Read more

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Formats the value using the given formatter.

Wrapping (modular) addition. Computes self + other, wrapping around at the boundary of the type. Read more

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Casts the value.

Wrapping (modular) multiplication. Computes self * other, wrapping around at the boundary of the type. Read more

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. Read more

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high order bits of rhs that would cause the shift to exceed the bitwidth of the type. Read more

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high order bits of rhs that would cause the shift to exceed the bitwidth of the type. Read more

Wrapping (modular) subtraction. Computes self - other, wrapping around at the boundary of the type. Read more

Returns the additive identity element of Self, 0. Read more

Returns true if self is equal to the additive identity.

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern. Read more

If this function returns true, then it must be valid to reinterpret bits as &Self. Read more

Casts the value.

Returns the argument unchanged.

Calls U::from(self).

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

Performs the conversion.

Performs the conversion.

Returns the smallest finite number this type can represent

Casts the value.

Casts the value.

Casts the value.

Casts the value.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.

Returns the largest finite number this type can represent

Casts the value.

Casts the value.