f16

Struct f16 

Source
#[repr(C)]
pub struct f16(/* private fields */);
Available on crate feature f16 only.
Expand description

A 16-bit floating point type implementing the IEEE 754-2008 standard binary16 a.k.a “half” format.

This 16-bit floating point type is intended for efficient storage where the full range and precision of a larger floating point value is not required.

Implementations§

Source§

impl f16

Source

pub const DIGITS: u32 = 3u32

Approximate number of f16 significant digits in base 10

Source

pub const EPSILON: f16

f16 machine epsilon value

This is the difference between 1.0 and the next largest representable number.

Source

pub const INFINITY: f16

f16 positive Infinity (+∞)

Source

pub const MANTISSA_DIGITS: u32 = 11u32

Number of f16 significant digits in base 2

Source

pub const MAX: f16

Largest finite f16 value

Source

pub const MAX_10_EXP: i32 = 4i32

Maximum possible f16 power of 10 exponent

Source

pub const MAX_EXP: i32 = 16i32

Maximum possible f16 power of 2 exponent

Source

pub const MIN: f16

Smallest finite f16 value

Source

pub const MIN_10_EXP: i32 = -4i32

Minimum possible normal f16 power of 10 exponent

Source

pub const MIN_EXP: i32 = -13i32

One greater than the minimum possible normal f16 power of 2 exponent

Source

pub const MIN_POSITIVE: f16

Smallest positive normal f16 value

Source

pub const NAN: f16

f16 Not a Number (NaN)

Source

pub const NEG_INFINITY: f16

f16 negative infinity (-∞)

Source

pub const RADIX: u32 = 2u32

The radix or base of the internal representation of f16

Source

pub const MIN_POSITIVE_SUBNORMAL: f16

Minimum positive subnormal f16 value

Source

pub const MAX_SUBNORMAL: f16

Maximum subnormal f16 value

Source

pub const ONE: f16

f16 1

Source

pub const ZERO: f16

f16 0

Source

pub const NEG_ZERO: f16

f16 -0

Source

pub const NEG_ONE: f16

f16 -1

Source

pub const E: f16

f16 Euler’s number (ℯ)

Source

pub const PI: f16

f16 Archimedes’ constant (π)

Source

pub const FRAC_1_PI: f16

f16 1/π

Source

pub const FRAC_1_SQRT_2: f16

f16 1/√2

Source

pub const FRAC_2_PI: f16

f16 2/π

Source

pub const FRAC_2_SQRT_PI: f16

f16 2/√π

Source

pub const FRAC_PI_2: f16

f16 π/2

Source

pub const FRAC_PI_3: f16

f16 π/3

Source

pub const FRAC_PI_4: f16

f16 π/4

Source

pub const FRAC_PI_6: f16

f16 π/6

Source

pub const FRAC_PI_8: f16

f16 π/8

Source

pub const LN_10: f16

f16 𝗅𝗇 10

Source

pub const LN_2: f16

f16 𝗅𝗇 2

Source

pub const LOG10_E: f16

f16 𝗅𝗈𝗀₁₀ℯ

Source

pub const LOG10_2: f16

f16 𝗅𝗈𝗀₁₀2

Source

pub const LOG2_E: f16

f16 𝗅𝗈𝗀₂ℯ

Source

pub const LOG2_10: f16

f16 𝗅𝗈𝗀₂10

Source

pub const SQRT_2: f16

f16 √2

Source

pub const SIGN_MASK: u16 = 32_768u16

Sign bit

Source

pub const EXP_MASK: u16 = 31_744u16

Exponent mask

Source

pub const HIDDEN_BIT_MASK: u16 = 1_024u16

Mask for the hidden bit.

Source

pub const MAN_MASK: u16 = 1_023u16

Mantissa mask

Source

pub const TINY_BITS: u16 = 1u16

Minimum representable positive value (min subnormal)

Source

pub const NEG_TINY_BITS: u16 = 32_769u16

Minimum representable negative value (min negative subnormal)

Source

pub const fn from_bits(bits: u16) -> f16

Constructs a 16-bit floating point value from the raw bits.

Source

pub fn from_f32(value: f32) -> f16

Constructs a 16-bit floating point value from a 32-bit floating point value.

This operation is lossy. If the 32-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 32-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

This will prefer correctness over speed. Currently, this always uses an intrinsic if available.

Source

pub const fn from_f32_const(value: f32) -> f16

Constructs a 16-bit floating point value from a 32-bit floating point value.

This function is identical to from_f32 except it never uses hardware intrinsics, which allows it to be const. from_f32 should be preferred in any non-const context.

This operation is lossy. If the 32-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 32-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

Source

pub fn from_f32_instrinsic(value: f32) -> f16

Constructs a 16-bit floating point value from a 32-bit floating point value.

This operation is lossy. If the 32-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 32-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

Source

pub const fn from_f32_lossless(value: f32) -> Option<f16>

Create a f16 loslessly from an f32.

This is only true if the f32 is non-finite (infinite or NaN), or the exponent can be represented by a normal f16 and no non-zero bits would be truncated.

“Lossless” does not mean the data is represented the same as a decimal number. For example, an f32 and f64 have the significant digits (excluding the hidden bit) for a value closest to 1e35 of:

  • f32: 110100001001100001100
  • f64: 11010000100110000110000000000000000000000000000000

However, the f64 is displayed as 1.0000000409184788e+35, while the value closest to 1e35 in f64 is 11010000100110000101110010110001110100110110000010. This makes it look like precision has been lost but this is due to the approximations used to represent binary values as a decimal.

This does not respect signalling NaNs: if the value is NaN or inf, then it will return that value.

Source

pub fn from_f64(value: f64) -> f16

Constructs a 16-bit floating point value from a 64-bit floating point value.

This operation is lossy. If the 64-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 64-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

This will prefer correctness over speed: on x86 systems, this currently uses a software rather than an instrinsic implementation on x86.

Source

pub const fn from_f64_const(value: f64) -> f16

Constructs a 16-bit floating point value from a 64-bit floating point value.

This function is identical to from_f64 except it never uses hardware intrinsics, which allows it to be const. from_f64 should be preferred in any non-const context.

This operation is lossy. If the 64-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 64-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

Source

pub fn from_f64_instrinsic(value: f64) -> f16

Constructs a 16-bit floating point value from a 64-bit floating point value.

This operation is lossy. If the 64-bit value is to large to fit in 16-bits, ±∞ will result. NaN values are preserved. 64-bit subnormal values are too tiny to be represented in 16-bits and result in ±0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or ±0. All other values are truncated and rounded to the nearest representable 16-bit value.

This prefers to use vendor instrinsics if possible, otherwise, it goes to a fallback. On x86 and x86_64, this can be more lossy than from_f64.

Source

pub const fn from_f64_lossless(value: f64) -> Option<f16>

Create a f16 loslessly from an f64.

This is only true if the f64 is non-finite (infinite or NaN), or the exponent can be represented by a normal f16 and no non-zero bits would be truncated.

“Lossless” does not mean the data is represented the same as a decimal number. For example, an f32 and f64 have the significant digits (excluding the hidden bit) for a value closest to 1e35 of:

  • f32: 110100001001100001100
  • f64: 11010000100110000110000000000000000000000000000000

However, the f64 is displayed as 1.0000000409184788e+35, while the value closest to 1e35 in f64 is 11010000100110000101110010110001110100110110000010. This makes it look like precision has been lost but this is due to the approximations used to represent binary values as a decimal.

This does not respect signalling NaNs: if the value is NaN or inf, then it will return that value.

Source

pub const fn to_bits(self) -> u16

Converts a f16 into the underlying bit representation.

Source

pub const fn to_le_bytes(self) -> [u8; 2]

Returns the memory representation of the underlying bit representation as a byte array in little-endian byte order.

§Examples
let bytes = f16::from_f32(12.5).to_le_bytes();
assert_eq!(bytes, [0x40, 0x4A]);
Source

pub const fn to_be_bytes(self) -> [u8; 2]

Returns the memory representation of the underlying bit representation as a byte array in big-endian (network) byte order.

§Examples
let bytes = f16::from_f32(12.5).to_be_bytes();
assert_eq!(bytes, [0x4A, 0x40]);
Source

pub const fn to_ne_bytes(self) -> [u8; 2]

Returns the memory representation of the underlying bit representation as a byte array in native byte order.

As the target platform’s native endianness is used, portable code should use to_be_bytes or to_le_bytes, as appropriate, instead.

§Examples
let bytes = f16::from_f32(12.5).to_ne_bytes();
assert_eq!(bytes, if cfg!(target_endian = "big") {
    [0x4A, 0x40]
} else {
    [0x40, 0x4A]
});
Source

pub const fn from_le_bytes(bytes: [u8; 2]) -> f16

Creates a floating point value from its representation as a byte array in little endian.

§Examples
let value = f16::from_le_bytes([0x40, 0x4A]);
assert_eq!(value, f16::from_f32(12.5));
Source

pub const fn from_be_bytes(bytes: [u8; 2]) -> f16

Creates a floating point value from its representation as a byte array in big endian.

§Examples
let value = f16::from_be_bytes([0x4A, 0x40]);
assert_eq!(value, f16::from_f32(12.5));
Source

pub const fn from_ne_bytes(bytes: [u8; 2]) -> f16

Creates a floating point value from its representation as a byte array in native endian.

As the target platform’s native endianness is used, portable code likely wants to use from_be_bytes or from_le_bytes, as appropriate instead.

§Examples
let value = f16::from_ne_bytes(if cfg!(target_endian = "big") {
    [0x4A, 0x40]
} else {
    [0x40, 0x4A]
});
assert_eq!(value, f16::from_f32(12.5));
Source

pub fn to_f32(self) -> f32

Converts a f16 value into a f32 value.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 32-bit floating point.

This will prefer correctness over speed. Currently, this always uses an intrinsic if available.

Source

pub const fn to_f32_const(self) -> f32

Converts a f16 value into a f32 value.

This function is identical to to_f32 except it never uses hardware intrinsics, which allows it to be const. to_f32 should be preferred in any non-const context.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 32-bit floating point.

Source

pub fn to_f32_intrinsic(self) -> f32

Converts a f16 value into a f32 value.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 32-bit floating point.

Source

pub fn as_f32(self) -> f32

Convert the data to an f32 type, used for numerical operations.

Source

pub const fn as_f32_const(self) -> f32

Convert the data to an f32 type, used for numerical operations.

Source

pub fn to_f64(self) -> f64

Converts a f16 value into a f64 value.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 64-bit floating point.

This will prefer correctness over speed: on x86 systems, this currently uses a software rather than an instrinsic implementation on x86.

Source

pub const fn to_f64_const(self) -> f64

Converts a f16 value into a f64 value.

This function is identical to to_f64 except it never uses hardware intrinsics, which allows it to be const. to_f64 should be preferred in any non-const context.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 64-bit floating point.

Source

pub fn to_f64_intrinsic(self) -> f64

Converts a f16 value into a f32 value.

This conversion is lossless as all 16-bit floating point values can be represented exactly in 32-bit floating point.

Source

pub fn as_f64(self) -> f64

Convert the data to an f64 type, used for numerical operations.

Source

pub const fn as_f64_const(self) -> f64

Convert the data to an f64 type, used for numerical operations.

Source

pub const fn is_nan(self) -> bool

Returns true if this value is NaN and false otherwise.

§Examples

let nan = f16::NAN;
let f = f16::from_f32(7.0_f32);

assert!(nan.is_nan());
assert!(!f.is_nan());
Source

pub const fn abs(self) -> f16

Computes the absolute value of self.

Source

pub const fn is_infinite(self) -> bool

Returns true if this value is ±∞ and false. otherwise.

§Examples

let f = f16::from_f32(7.0f32);
let inf = f16::INFINITY;
let neg_inf = f16::NEG_INFINITY;
let nan = f16::NAN;

assert!(!f.is_infinite());
assert!(!nan.is_infinite());

assert!(inf.is_infinite());
assert!(neg_inf.is_infinite());
Source

pub const fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

§Examples

let f = f16::from_f32(7.0f32);
let inf = f16::INFINITY;
let neg_inf = f16::NEG_INFINITY;
let nan = f16::NAN;

assert!(f.is_finite());

assert!(!nan.is_finite());
assert!(!inf.is_finite());
assert!(!neg_inf.is_finite());
Source

pub const fn is_subnormal(self) -> bool

Returns true if the number is subnormal.

Source

pub const fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal, or NaN.

§Examples

let min = f16::MIN_POSITIVE;
let max = f16::MAX;
let lower_than_min = f16::from_f32(1.0e-10_f32);
let zero = f16::from_f32(0.0_f32);

assert!(min.is_normal());
assert!(max.is_normal());

assert!(!zero.is_normal());
assert!(!f16::NAN.is_normal());
assert!(!f16::INFINITY.is_normal());
// Values between `0` and `min` are Subnormal.
assert!(!lower_than_min.is_normal());
Source

pub const fn classify(self) -> FpCategory

Returns the floating point category of the number.

If only one property is going to be tested, it is generally faster to use the specific predicate instead.

§Examples
use std::num::FpCategory;

let num = f16::from_f32(12.4_f32);
let inf = f16::INFINITY;

assert_eq!(num.classify(), FpCategory::Normal);
assert_eq!(inf.classify(), FpCategory::Infinite);
Source

pub const fn signum(self) -> f16

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NaN
§Examples

let f = f16::from_f32(3.5_f32);

assert_eq!(f.signum(), f16::from_f32(1.0));
assert_eq!(f16::NEG_INFINITY.signum(), f16::from_f32(-1.0));

assert!(f16::NAN.signum().is_nan());
Source

pub const fn is_sign_positive(self) -> bool

Returns true if and only if self has a positive sign, including +0.0, NaNs with a positive sign bit and +∞.

§Examples

let nan = f16::NAN;
let f = f16::from_f32(7.0_f32);
let g = f16::from_f32(-7.0_f32);

assert!(f.is_sign_positive());
assert!(!g.is_sign_positive());
// `NaN` can be either positive or negative
assert!(nan.is_sign_positive() != nan.is_sign_negative());
Source

pub const fn is_sign_negative(self) -> bool

Returns true if and only if self has a negative sign, including -0.0, NaNs with a negative sign bit and −∞.

§Examples

let nan = f16::NAN;
let f = f16::from_f32(7.0f32);
let g = f16::from_f32(-7.0f32);

assert!(!f.is_sign_negative());
assert!(g.is_sign_negative());
// `NaN` can be either positive or negative
assert!(nan.is_sign_positive() != nan.is_sign_negative());
Source

pub const fn copysign(self, sign: f16) -> f16

Returns a number composed of the magnitude of self and the sign of sign.

Equal to self if the sign of self and sign are the same, otherwise equal to -self. If self is NaN, then NaN with the sign of sign is returned.

§Examples
let f = f16::from_f32(3.5);

assert_eq!(f.copysign(f16::from_f32(0.42)), f16::from_f32(3.5));
assert_eq!(f.copysign(f16::from_f32(-0.42)), f16::from_f32(-3.5));
assert_eq!((-f).copysign(f16::from_f32(0.42)), f16::from_f32(3.5));
assert_eq!((-f).copysign(f16::from_f32(-0.42)), f16::from_f32(-3.5));

assert!(f16::NAN.copysign(f16::from_f32(1.0)).is_nan());
Source

pub fn recip(self) -> f16

Takes the reciprocal (inverse) of a number, 1/x.

Source

pub fn to_degrees(self) -> f16

Converts radians to degrees.

Source

pub fn to_radians(self) -> f16

Converts degrees to radians.

Source

pub const fn max(self, other: f16) -> f16

Returns the maximum of the two numbers.

If one of the arguments is NaN, then the other argument is returned.

§Examples
let x = f16::from_f32(1.0);
let y = f16::from_f32(2.0);

assert_eq!(x.max(y), y);
Source

pub const fn min(self, other: f16) -> f16

Returns the minimum of the two numbers.

If one of the arguments is NaN, then the other argument is returned.

§Examples
let x = f16::from_f32(1.0);
let y = f16::from_f32(2.0);

assert_eq!(x.min(y), x);
Source

pub const fn clamp(self, min: f16, max: f16) -> f16

Restrict a value to a certain interval unless it is NaN.

Returns max if self is greater than max, and min if self is less than min. Otherwise this returns self.

Note that this function returns NaN if the initial value was NaN as well.

§Panics

Panics if min > max, min is NaN, or max is NaN.

§Examples
assert!(f16::from_f32(-3.0).clamp(f16::from_f32(-2.0), f16::from_f32(1.0)) == f16::from_f32(-2.0));
assert!(f16::from_f32(0.0).clamp(f16::from_f32(-2.0), f16::from_f32(1.0)) == f16::from_f32(0.0));
assert!(f16::from_f32(2.0).clamp(f16::from_f32(-2.0), f16::from_f32(1.0)) == f16::from_f32(1.0));
assert!(f16::NAN.clamp(f16::from_f32(-2.0), f16::from_f32(1.0)).is_nan());
Source

pub fn total_cmp(&self, other: &f16) -> Ordering

Returns the ordering between self and other.

Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in the IEEE 754 (2008 revision) floating point standard. The values are ordered in the following sequence:

  • negative quiet NaN
  • negative signaling NaN
  • negative infinity
  • negative numbers
  • negative subnormal numbers
  • negative zero
  • positive zero
  • positive subnormal numbers
  • positive numbers
  • positive infinity
  • positive signaling NaN
  • positive quiet NaN.

The ordering established by this function does not always agree with the PartialOrd and PartialEq implementations of f16. For example, they consider negative and positive zero equal, while total_cmp doesn’t.

The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.

§Examples
let mut v: Vec<f16> = vec![];
v.push(f16::ONE);
v.push(f16::INFINITY);
v.push(f16::NEG_INFINITY);
v.push(f16::NAN);
v.push(f16::MAX_SUBNORMAL);
v.push(-f16::MAX_SUBNORMAL);
v.push(f16::ZERO);
v.push(f16::NEG_ZERO);
v.push(f16::NEG_ONE);
v.push(f16::MIN_POSITIVE);

v.sort_by(|a, b| a.total_cmp(&b));

assert!(v
    .into_iter()
    .zip(
        [
            f16::NEG_INFINITY,
            f16::NEG_ONE,
            -f16::MAX_SUBNORMAL,
            f16::NEG_ZERO,
            f16::ZERO,
            f16::MAX_SUBNORMAL,
            f16::MIN_POSITIVE,
            f16::ONE,
            f16::INFINITY,
            f16::NAN
        ]
        .iter()
    )
    .all(|(a, b)| a.to_bits() == b.to_bits()));
Source§

impl f16

Source

pub const fn from_u8(value: u8) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_u16(value: u16) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_u32(value: u32) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_u64(value: u64) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_u128(value: u128) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_i8(value: i8) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_i16(value: i16) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_i32(value: i32) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_i64(value: i64) -> f16

Create from the integral type, as if by an as cast.

Source

pub const fn from_i128(value: i128) -> f16

Create from the integral type, as if by an as cast.

Trait Implementations§

Source§

impl Add<&f16> for &f16

Source§

type Output = <f16 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &f16) -> <&f16 as Add<&f16>>::Output

Performs the + operation. Read more
Source§

impl Add<&f16> for f16

Source§

type Output = <f16 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &f16) -> <f16 as Add<&f16>>::Output

Performs the + operation. Read more
Source§

impl Add<f16> for &f16

Source§

type Output = <f16 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f16) -> <&f16 as Add<f16>>::Output

Performs the + operation. Read more
Source§

impl Add for f16

Source§

type Output = f16

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f16) -> <f16 as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign<&f16> for f16

Source§

fn add_assign(&mut self, rhs: &f16)

Performs the += operation. Read more
Source§

impl AddAssign for f16

Source§

fn add_assign(&mut self, rhs: f16)

Performs the += operation. Read more
Source§

impl AsCast for f16

Source§

fn as_cast<N>(n: N) -> f16
where N: AsPrimitive,

Creates a number from another value that can be converted into a primitive via the AsPrimitive trait. Read more
Source§

impl AsPrimitive for f16

Source§

fn as_u8(self) -> u8

Convert the value to a u8, as if by value as u8.
Source§

fn as_u16(self) -> u16

Convert the value to a u16, as if by value as u16.
Source§

fn as_u32(self) -> u32

Convert the value to a u32, as if by value as u32.
Source§

fn as_u64(self) -> u64

Convert the value to a u64, as if by value as u64.
Source§

fn as_u128(self) -> u128

Convert the value to a u128, as if by value as u128.
Source§

fn as_usize(self) -> usize

Convert the value to a usize, as if by value as usize.
Source§

fn as_i8(self) -> i8

Convert the value to an i8, as if by value as i8.
Source§

fn as_i16(self) -> i16

Convert the value to an i16, as if by value as i16.
Source§

fn as_i32(self) -> i32

Convert the value to an i32, as if by value as i32.
Source§

fn as_i64(self) -> i64

Convert the value to an i64, as if by value as i64.
Source§

fn as_i128(self) -> i128

Convert the value to an i128, as if by value as i128.
Source§

fn as_isize(self) -> isize

Convert the value to an isize, as if by value as isize.
Source§

fn as_f32(self) -> f32

Convert the value to an f32, as if by value as f32.
Source§

fn as_f64(self) -> f64

Convert the value to an f64, as if by value as f64.
Source§

fn from_u32(value: u32) -> f16

Convert the value from a u32, as if by value as _.
Source§

fn from_u64(value: u64) -> f16

Convert the value from a u64, as if by value as _.
Source§

fn as_f16(self) -> f16

Convert the value to an f16, identical to value as f16 if f16 was a primitive type.
Source§

fn as_bf16(self) -> bf16

Convert the value to an bf16, identical to value as bf16 if bf16 was a primitive type.
Source§

impl Binary for f16

Source§

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

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

impl Clone for f16

Source§

fn clone(&self) -> f16

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for f16

Source§

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

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

impl Default for f16

Source§

fn default() -> f16

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

impl Display for f16

Source§

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

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

impl Div<&f16> for &f16

Source§

type Output = <f16 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &f16) -> <&f16 as Div<&f16>>::Output

Performs the / operation. Read more
Source§

impl Div<&f16> for f16

Source§

type Output = <f16 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &f16) -> <f16 as Div<&f16>>::Output

Performs the / operation. Read more
Source§

impl Div<f16> for &f16

Source§

type Output = <f16 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f16) -> <&f16 as Div<f16>>::Output

Performs the / operation. Read more
Source§

impl Div for f16

Source§

type Output = f16

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f16) -> <f16 as Div>::Output

Performs the / operation. Read more
Source§

impl DivAssign<&f16> for f16

Source§

fn div_assign(&mut self, rhs: &f16)

Performs the /= operation. Read more
Source§

impl DivAssign for f16

Source§

fn div_assign(&mut self, rhs: f16)

Performs the /= operation. Read more
Source§

impl Float for f16

Source§

const ZERO: f16

A value equal to 0.
Source§

const ONE: f16

A value equal to 1.
Source§

const TWO: f16

A value equal to 2.
Source§

const MAX: f16

Largest finite value. Read more
Source§

const MIN: f16

Smallest finite value. Read more
Source§

const INFINITY: f16

Infinity (). Read more
Source§

const NEG_INFINITY: f16

Negative infinity (−∞). Read more
Source§

const NAN: f16

Not a Number (NaN). Read more
Source§

const BITS: usize = 16usize

The size of this float type in bits. Read more
Source§

const SIGN_MASK: <f16 as Float>::Unsigned = {transmute(0x8000): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Bitmask to extract the sign from the float.
Source§

const EXPONENT_MASK: <f16 as Float>::Unsigned = {transmute(0x7c00): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Bitmask to extract the biased exponent, including the hidden bit.
Source§

const HIDDEN_BIT_MASK: <f16 as Float>::Unsigned = {transmute(0x0400): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Bitmask to extract the hidden bit in the exponent, which is an implicit 1 in the significant digits.
Source§

const MANTISSA_MASK: <f16 as Float>::Unsigned = {transmute(0x03ff): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Bitmask to extract the mantissa (significant digits), excluding the hidden bit.
Source§

const CARRY_MASK: <f16 as Float>::Unsigned = {transmute(0x0800): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Mask to determine if a full-carry occurred (1 in bit above hidden bit).
Source§

const INFINITY_BITS: <f16 as Float>::Unsigned = {transmute(0x7c00): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Positive infinity as bits.
Source§

const NEGATIVE_INFINITY_BITS: <f16 as Float>::Unsigned = {transmute(0xfc00): <lexical_parse_float::f16 as lexical_util::num::Float>::Unsigned}

Positive infinity as bits.
Source§

const EXPONENT_SIZE: i32 = 5i32

The number of bits in the exponent.
Source§

const MANTISSA_SIZE: i32 = 10i32

Size of the significand (mantissa) without the hidden bit.
Source§

const EXPONENT_BIAS: i32 = 25i32

Bias of the exponent. See exponent bias.
Source§

const DENORMAL_EXPONENT: i32 = -24i32

Exponent portion of a denormal float.
Source§

const MAX_EXPONENT: i32 = 6i32

Maximum (unbiased) exponent value in the float.
Source§

type Unsigned = u16

Unsigned type of the same size.
Source§

fn to_bits(self) -> u16

Raw transmutation to the unsigned integral type. Read more
Source§

fn from_bits(u: u16) -> f16

Raw transmutation from the unsigned integral type. Read more
Source§

fn ln(self) -> f16

Returns the natural logarithm of the number. Read more
Source§

fn floor(self) -> f16

Returns the largest integer less than or equal to self. Read more
Source§

fn is_sign_positive(self) -> bool

Returns true if self has a positive sign, including +0.0, NaNs with positive sign bit and positive infinity. Read more
Source§

fn is_sign_negative(self) -> bool

Returns true if self has a negative sign, including -0.0, NaNs with negative sign bit and negative infinity. Read more
Source§

fn is_denormal(self) -> bool

Returns true if the float is denormal. Read more
Source§

fn is_special(self) -> bool

Returns true if the float is NaN, positive infinity, or negative infinity.
Source§

fn is_nan(self) -> bool

Returns true if the float is NaN.
Source§

fn is_inf(self) -> bool

Returns true if the float is positive or negative infinity.
Source§

fn is_odd(self) -> bool

Returns true if the float’s least-significant mantissa bit is odd.
Source§

fn is_even(self) -> bool

Returns true if the float’s least-significant mantissa bit is even.
Source§

fn needs_negative_sign(self) -> bool

Returns true if the float needs a negative sign when serializing it. Read more
Source§

fn exponent(self) -> i32

Get the unbiased exponent component from the float.
Source§

fn mantissa(self) -> Self::Unsigned

Get the mantissa (significand) component from float.
Source§

fn next(self) -> Self

Get next greater float. Read more
Source§

fn next_positive(self) -> Self

Get next greater float for a positive float. Read more
Source§

fn prev(self) -> Self

Get previous greater float, such that self.prev().next() == self. Read more
Source§

fn prev_positive(self) -> Self

Get previous greater float for a positive float. Value must be > 0.0.
Source§

fn round_positive_even(self) -> Self

Round a positive number to even.
Source§

fn max_finite(self, f: Self) -> Self

Get the max of two finite numbers. Read more
Source§

fn min_finite(self, f: Self) -> Self

Get the min of two finite numbers. Read more
Source§

impl FormattedSize for f16

Source§

const FORMATTED_SIZE: usize = 256usize

Maximum number of bytes required to serialize a number to string. If power-of-two or radix is not enabled, this is the same as FORMATTED_SIZE_DECIMAL. Read more
Source§

const FORMATTED_SIZE_DECIMAL: usize = 64usize

Maximum number of bytes required to serialize a number to a decimal string. Read more
Source§

impl From<i8> for f16

Source§

fn from(x: i8) -> f16

Converts to this type from the input type.
Source§

impl From<u8> for f16

Source§

fn from(x: u8) -> f16

Converts to this type from the input type.
Source§

impl FromLexical for f16

Source§

fn from_lexical(bytes: &[u8]) -> Result<f16, Error>

Checked parser for a string-to-number conversion. Read more
Source§

fn from_lexical_partial(bytes: &[u8]) -> Result<(f16, usize), Error>

Checked parser for a string-to-number conversion. Read more
Source§

impl FromLexicalWithOptions for f16

Source§

type Options = Options

Custom formatting options for parsing a number.
Source§

fn from_lexical_with_options<const FORMAT: u128>( bytes: &[u8], options: &<f16 as FromLexicalWithOptions>::Options, ) -> Result<f16, Error>

Checked parser for a string-to-number conversion. Read more
Source§

fn from_lexical_partial_with_options<const FORMAT: u128>( bytes: &[u8], options: &<f16 as FromLexicalWithOptions>::Options, ) -> Result<(f16, usize), Error>

Checked parser for a string-to-number conversion. Read more
Source§

impl FromStr for f16

Source§

type Err = ParseFloatError

The associated error which can be returned from parsing.
Source§

fn from_str(src: &str) -> Result<f16, ParseFloatError>

Parses a string s to return a value of this type. Read more
Source§

impl LowerExp for f16

Source§

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

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

impl LowerHex for f16

Source§

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

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

impl Mul<&f16> for &f16

Source§

type Output = <f16 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &f16) -> <&f16 as Mul<&f16>>::Output

Performs the * operation. Read more
Source§

impl Mul<&f16> for f16

Source§

type Output = <f16 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &f16) -> <f16 as Mul<&f16>>::Output

Performs the * operation. Read more
Source§

impl Mul<f16> for &f16

Source§

type Output = <f16 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f16) -> <&f16 as Mul<f16>>::Output

Performs the * operation. Read more
Source§

impl Mul for f16

Source§

type Output = f16

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f16) -> <f16 as Mul>::Output

Performs the * operation. Read more
Source§

impl MulAssign<&f16> for f16

Source§

fn mul_assign(&mut self, rhs: &f16)

Performs the *= operation. Read more
Source§

impl MulAssign for f16

Source§

fn mul_assign(&mut self, rhs: f16)

Performs the *= operation. Read more
Source§

impl Neg for &f16

Source§

type Output = <f16 as Neg>::Output

The resulting type after applying the - operator.
Source§

fn neg(self) -> <&f16 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Neg for f16

Source§

type Output = f16

The resulting type after applying the - operator.
Source§

fn neg(self) -> <f16 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Number for f16

Source§

const IS_SIGNED: bool = true

If the number can hold negative values.
Source§

impl Octal for f16

Source§

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

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

impl PartialEq for f16

Source§

fn eq(&self, other: &f16) -> bool

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

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

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

impl PartialOrd for f16

Source§

fn partial_cmp(&self, other: &f16) -> Option<Ordering>

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

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

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

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

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

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

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

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

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

impl<'a> Product<&'a f16> for f16

Source§

fn product<I>(iter: I) -> f16
where I: Iterator<Item = &'a f16>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Product for f16

Source§

fn product<I>(iter: I) -> f16
where I: Iterator<Item = f16>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Rem<&f16> for &f16

Source§

type Output = <f16 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &f16) -> <&f16 as Rem<&f16>>::Output

Performs the % operation. Read more
Source§

impl Rem<&f16> for f16

Source§

type Output = <f16 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &f16) -> <f16 as Rem<&f16>>::Output

Performs the % operation. Read more
Source§

impl Rem<f16> for &f16

Source§

type Output = <f16 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: f16) -> <&f16 as Rem<f16>>::Output

Performs the % operation. Read more
Source§

impl Rem for f16

Source§

type Output = f16

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: f16) -> <f16 as Rem>::Output

Performs the % operation. Read more
Source§

impl RemAssign<&f16> for f16

Source§

fn rem_assign(&mut self, rhs: &f16)

Performs the %= operation. Read more
Source§

impl RemAssign for f16

Source§

fn rem_assign(&mut self, rhs: f16)

Performs the %= operation. Read more
Source§

impl Sub<&f16> for &f16

Source§

type Output = <f16 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &f16) -> <&f16 as Sub<&f16>>::Output

Performs the - operation. Read more
Source§

impl Sub<&f16> for f16

Source§

type Output = <f16 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &f16) -> <f16 as Sub<&f16>>::Output

Performs the - operation. Read more
Source§

impl Sub<f16> for &f16

Source§

type Output = <f16 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f16) -> <&f16 as Sub<f16>>::Output

Performs the - operation. Read more
Source§

impl Sub for f16

Source§

type Output = f16

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f16) -> <f16 as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign<&f16> for f16

Source§

fn sub_assign(&mut self, rhs: &f16)

Performs the -= operation. Read more
Source§

impl SubAssign for f16

Source§

fn sub_assign(&mut self, rhs: f16)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a f16> for f16

Source§

fn sum<I>(iter: I) -> f16
where I: Iterator<Item = &'a f16>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for f16

Source§

fn sum<I>(iter: I) -> f16
where I: Iterator<Item = f16>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl ToLexical for f16

Source§

fn to_lexical(self, bytes: &mut [u8]) -> &mut [u8]

Serializer for a number-to-string conversion. Read more
Source§

impl ToLexicalWithOptions for f16

Source§

type Options = Options

Custom formatting options for writing a number.
Source§

fn to_lexical_with_options<'a, const FORMAT: u128>( self, bytes: &'a mut [u8], options: &<f16 as ToLexicalWithOptions>::Options, ) -> &'a mut [u8]

Serializer for a number-to-string conversion. Read more
Source§

impl TryFrom<f32> for f16

Source§

type Error = TryFromFloatError

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

fn try_from(x: f32) -> Result<f16, <f16 as TryFrom<f32>>::Error>

Performs the conversion.
Source§

impl TryFrom<f64> for f16

Source§

type Error = TryFromFloatError

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

fn try_from(x: f64) -> Result<f16, <f16 as TryFrom<f64>>::Error>

Performs the conversion.
Source§

impl UpperExp for f16

Source§

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

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

impl UpperHex for f16

Source§

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

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

impl Copy for f16

Source§

impl Primitive for f16

Auto Trait Implementations§

§

impl Freeze for f16

§

impl RefUnwindSafe for f16

§

impl Send for f16

§

impl Sync for f16

§

impl Unpin for f16

§

impl UnwindSafe for f16

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.