bf16

Struct bf16 

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

A 16-bit floating point type implementing the bfloat16 format.

The bfloat16 floating point format is a truncated 16-bit version of the IEEE 754 standard binary32, a.k.a f32. bf16 has approximately the same dynamic range as f32 by having a lower precision than f16. While f16 has a precision of 11 bits, bf16 has a precision of only 8 bits.

Implementations§

Source§

impl bf16

Source

pub const DIGITS: u32 = 2u32

Approximate number of bf16 significant digits in base 10

Source

pub const EPSILON: bf16

bf16 machine epsilon value

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

Source

pub const INFINITY: bf16

bf16 positive Infinity (+∞)

Source

pub const MANTISSA_DIGITS: u32 = 8u32

Number of bf16 significant digits in base 2

Source

pub const MAX: bf16

Largest finite bf16 value

Source

pub const MAX_10_EXP: i32 = 38i32

Maximum possible bf16 power of 10 exponent

Source

pub const MAX_EXP: i32 = 128i32

Maximum possible bf16 power of 2 exponent

Source

pub const MIN: bf16

Smallest finite bf16 value

Source

pub const MIN_10_EXP: i32 = -37i32

Minimum possible normal bf16 power of 10 exponent

Source

pub const MIN_EXP: i32 = -125i32

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

Source

pub const MIN_POSITIVE: bf16

Smallest positive normal bf16 value

Source

pub const NAN: bf16

bf16 Not a Number (NaN)

Source

pub const NEG_INFINITY: bf16

bf16 negative infinity (-∞).

Source

pub const RADIX: u32 = 2u32

The radix or base of the internal representation of bf16

Source

pub const MIN_POSITIVE_SUBNORMAL: bf16

Minimum positive subnormal bf16 value

Source

pub const MAX_SUBNORMAL: bf16

Maximum subnormal bf16 value

Source

pub const ONE: bf16

bf16 1

Source

pub const ZERO: bf16

bf16 0

Source

pub const NEG_ZERO: bf16

bf16 -0

Source

pub const NEG_ONE: bf16

bf16 -1

Source

pub const E: bf16

bf16 Euler’s number (ℯ)

Source

pub const PI: bf16

bf16 Archimedes’ constant (π)

Source

pub const FRAC_1_PI: bf16

bf16 1/π

Source

pub const FRAC_1_SQRT_2: bf16

bf16 1/√2

Source

pub const FRAC_2_PI: bf16

bf16 2/π

Source

pub const FRAC_2_SQRT_PI: bf16

bf16 2/√π

Source

pub const FRAC_PI_2: bf16

bf16 π/2

Source

pub const FRAC_PI_3: bf16

bf16 π/3

Source

pub const FRAC_PI_4: bf16

bf16 π/4

Source

pub const FRAC_PI_6: bf16

bf16 π/6

Source

pub const FRAC_PI_8: bf16

bf16 π/8

Source

pub const LN_10: bf16

bf16 𝗅𝗇 10

Source

pub const LN_2: bf16

bf16 𝗅𝗇 2

Source

pub const LOG10_E: bf16

bf16 𝗅𝗈𝗀₁₀ℯ

Source

pub const LOG10_2: bf16

bf16 𝗅𝗈𝗀₁₀2

Source

pub const LOG2_E: bf16

bf16 𝗅𝗈𝗀₂ℯ

Source

pub const LOG2_10: bf16

bf16 𝗅𝗈𝗀₂10

Source

pub const SQRT_2: bf16

bf16 √2

Source

pub const SIGN_MASK: u16 = 32_768u16

Sign bit

Source

pub const EXP_MASK: u16 = 32_640u16

Exponent mask

Source

pub const HIDDEN_BIT_MASK: u16 = 128u16

Mask for the hidden bit.

Source

pub const MAN_MASK: u16 = 127u16

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

Constructs a bf16 value from the raw bits.

Source

pub fn from_f32(value: f32) -> bf16

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

This operation is lossy. If the 32-bit value is too large to fit, ±∞ will result. NaN values are preserved. Subnormal values that are too tiny to be represented will result in ±0. All other values are truncated and rounded to the nearest representable value.

Source

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

Constructs a bf16 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 too large to fit, ±∞ will result. NaN values are preserved. Subnormal values that are too tiny to be represented will result in ±0. All other values are truncated and rounded to the nearest representable value.

Source

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

Create a bf16 loslessly from an f32.

This is only true if the f32 is non-finite (infinite or NaN), or 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.

Since bf16 has the same number of exponent bits as f32, this is effectively just checking if the value is non-finite (infinite or NaN) or the value is normal and the lower 16 bits are 0.

Source

pub fn from_f64(value: f64) -> bf16

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

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

Source

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

Constructs a bf16 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, ±∞ will result. NaN values are preserved. 64-bit subnormal values are too tiny to be represented and result in ±0. Exponents that underflow the minimum exponent will result in subnormals or ±0. All other values are truncated and rounded to the nearest representable value.

Source

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

Create a bf16 loslessly from an f64.

This is only true if the f64 is non-finite (infinite or NaN), zero, or the exponent can be represented by a normal bf16 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 bf16 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 = bf16::from_f32(12.5).to_le_bytes();
assert_eq!(bytes, [0x48, 0x41]);
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 = bf16::from_f32(12.5).to_be_bytes();
assert_eq!(bytes, [0x41, 0x48]);
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 = bf16::from_f32(12.5).to_ne_bytes();
assert_eq!(bytes, if cfg!(target_endian = "big") {
    [0x41, 0x48]
} else {
    [0x48, 0x41]
});
Source

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

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

§Examples
let value = bf16::from_le_bytes([0x48, 0x41]);
assert_eq!(value, bf16::from_f32(12.5));
Source

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

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

§Examples
let value = bf16::from_be_bytes([0x41, 0x48]);
assert_eq!(value, bf16::from_f32(12.5));
Source

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

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 = bf16::from_ne_bytes(if cfg!(target_endian = "big") {
    [0x41, 0x48]
} else {
    [0x48, 0x41]
});
assert_eq!(value, bf16::from_f32(12.5));
Source

pub fn to_f32(self) -> f32

Converts a bf16 value into an f32 value.

This conversion is lossless as all values can be represented exactly in f32.

Source

pub const fn to_f32_const(self) -> f32

Converts a bf16 value into an 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 values can be represented exactly in f32.

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 bf16 value into an f64 value.

This conversion is lossless as all values can be represented exactly in f64.

Source

pub const fn to_f64_const(self) -> f64

Converts a bf16 value into an 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 values can be represented exactly in f64.

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 = bf16::NAN;
let f = bf16::from_f32(7.0_f32);

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

pub const fn abs(self) -> bf16

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 = bf16::from_f32(7.0f32);
let inf = bf16::INFINITY;
let neg_inf = bf16::NEG_INFINITY;
let nan = bf16::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 = bf16::from_f32(7.0f32);
let inf = bf16::INFINITY;
let neg_inf = bf16::NEG_INFINITY;
let nan = bf16::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 = bf16::MIN_POSITIVE;
let max = bf16::MAX;
let lower_than_min = bf16::from_f32(1.0e-39_f32);
let zero = bf16::from_f32(0.0_f32);

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

assert!(!zero.is_normal());
assert!(!bf16::NAN.is_normal());
assert!(!bf16::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 = bf16::from_f32(12.4_f32);
let inf = bf16::INFINITY;

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

pub const fn signum(self) -> bf16

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`]bf16::NEG_INFINITY
  • NAN if the number is NaN
§Examples

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

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

assert!(bf16::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 = bf16::NAN;
let f = bf16::from_f32(7.0_f32);
let g = bf16::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 = bf16::NAN;
let f = bf16::from_f32(7.0f32);
let g = bf16::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: bf16) -> bf16

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 = bf16::from_f32(3.5);

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

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

pub fn recip(self) -> bf16

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

Source

pub fn to_degrees(self) -> bf16

Converts radians to degrees.

Source

pub fn to_radians(self) -> bf16

Converts degrees to radians.

Source

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

Returns the maximum of the two numbers.

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

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

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

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

Returns the minimum of the two numbers.

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

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

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

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

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!(bf16::from_f32(-3.0).clamp(bf16::from_f32(-2.0), bf16::from_f32(1.0)) == bf16::from_f32(-2.0));
assert!(bf16::from_f32(0.0).clamp(bf16::from_f32(-2.0), bf16::from_f32(1.0)) == bf16::from_f32(0.0));
assert!(bf16::from_f32(2.0).clamp(bf16::from_f32(-2.0), bf16::from_f32(1.0)) == bf16::from_f32(1.0));
assert!(bf16::NAN.clamp(bf16::from_f32(-2.0), bf16::from_f32(1.0)).is_nan());
Source

pub fn total_cmp(&self, other: &bf16) -> 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 bf16. 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<bf16> = vec![];
v.push(bf16::ONE);
v.push(bf16::INFINITY);
v.push(bf16::NEG_INFINITY);
v.push(bf16::NAN);
v.push(bf16::MAX_SUBNORMAL);
v.push(-bf16::MAX_SUBNORMAL);
v.push(bf16::ZERO);
v.push(bf16::NEG_ZERO);
v.push(bf16::NEG_ONE);
v.push(bf16::MIN_POSITIVE);

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

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

impl bf16

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Trait Implementations§

Source§

impl Add<&bf16> for &bf16

Source§

type Output = <bf16 as Add>::Output

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<&bf16> for bf16

Source§

type Output = <bf16 as Add>::Output

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<bf16> for &bf16

Source§

type Output = <bf16 as Add>::Output

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for bf16

Source§

type Output = bf16

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<&bf16> for bf16

Source§

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

Performs the += operation. Read more
Source§

impl AddAssign for bf16

Source§

fn add_assign(&mut self, rhs: bf16)

Performs the += operation. Read more
Source§

impl AsCast for bf16

Source§

fn as_cast<N>(n: N) -> bf16
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 bf16

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

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

fn from_u64(value: u64) -> bf16

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 bf16

Source§

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

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

impl Clone for bf16

Source§

fn clone(&self) -> bf16

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 bf16

Source§

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

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

impl Default for bf16

Source§

fn default() -> bf16

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

impl Display for bf16

Source§

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

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

impl Div<&bf16> for &bf16

Source§

type Output = <bf16 as Div>::Output

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<&bf16> for bf16

Source§

type Output = <bf16 as Div>::Output

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<bf16> for &bf16

Source§

type Output = <bf16 as Div>::Output

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for bf16

Source§

type Output = bf16

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<&bf16> for bf16

Source§

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

Performs the /= operation. Read more
Source§

impl DivAssign for bf16

Source§

fn div_assign(&mut self, rhs: bf16)

Performs the /= operation. Read more
Source§

impl Float for bf16

Source§

const ZERO: bf16

A value equal to 0.
Source§

const ONE: bf16

A value equal to 1.
Source§

const TWO: bf16

A value equal to 2.
Source§

const MAX: bf16

Largest finite value. Read more
Source§

const MIN: bf16

Smallest finite value. Read more
Source§

const INFINITY: bf16

Infinity (). Read more
Source§

const NEG_INFINITY: bf16

Negative infinity (−∞). Read more
Source§

const NAN: bf16

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: <bf16 as Float>::Unsigned = {transmute(0x8000): <lexical_parse_float::bf16 as lexical_util::num::Float>::Unsigned}

Bitmask to extract the sign from the float.
Source§

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

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

const HIDDEN_BIT_MASK: <bf16 as Float>::Unsigned = {transmute(0x0080): <lexical_parse_float::bf16 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: <bf16 as Float>::Unsigned = {transmute(0x007f): <lexical_parse_float::bf16 as lexical_util::num::Float>::Unsigned}

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

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

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

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

Positive infinity as bits.
Source§

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

Positive infinity as bits.
Source§

const EXPONENT_SIZE: i32 = 8i32

The number of bits in the exponent.
Source§

const MANTISSA_SIZE: i32 = 7i32

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

const EXPONENT_BIAS: i32 = 134i32

Bias of the exponent. See exponent bias.
Source§

const DENORMAL_EXPONENT: i32 = -133i32

Exponent portion of a denormal float.
Source§

const MAX_EXPONENT: i32 = 121i32

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

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

fn ln(self) -> bf16

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

fn floor(self) -> bf16

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 bf16

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 bf16

Source§

fn from(x: i8) -> bf16

Converts to this type from the input type.
Source§

impl From<u8> for bf16

Source§

fn from(x: u8) -> bf16

Converts to this type from the input type.
Source§

impl FromLexical for bf16

Source§

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

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

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

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

impl FromLexicalWithOptions for bf16

Source§

type Options = Options

Custom formatting options for parsing a number.
Source§

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

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

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

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

impl FromStr for bf16

Source§

type Err = ParseFloatError

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

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

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

impl LowerExp for bf16

Source§

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

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

impl LowerHex for bf16

Source§

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

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

impl Mul<&bf16> for &bf16

Source§

type Output = <bf16 as Mul>::Output

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<&bf16> for bf16

Source§

type Output = <bf16 as Mul>::Output

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<bf16> for &bf16

Source§

type Output = <bf16 as Mul>::Output

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for bf16

Source§

type Output = bf16

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<&bf16> for bf16

Source§

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

Performs the *= operation. Read more
Source§

impl MulAssign for bf16

Source§

fn mul_assign(&mut self, rhs: bf16)

Performs the *= operation. Read more
Source§

impl Neg for &bf16

Source§

type Output = <bf16 as Neg>::Output

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

impl Neg for bf16

Source§

type Output = bf16

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

impl Number for bf16

Source§

const IS_SIGNED: bool = true

If the number can hold negative values.
Source§

impl Octal for bf16

Source§

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

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

impl PartialEq for bf16

Source§

fn eq(&self, other: &bf16) -> 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 bf16

Source§

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

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

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

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

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

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

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

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

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

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

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

Source§

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

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

impl Product for bf16

Source§

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

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

impl Rem<&bf16> for &bf16

Source§

type Output = <bf16 as Rem>::Output

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Rem<&bf16> for bf16

Source§

type Output = <bf16 as Rem>::Output

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Rem<bf16> for &bf16

Source§

type Output = <bf16 as Rem>::Output

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl Rem for bf16

Source§

type Output = bf16

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl RemAssign<&bf16> for bf16

Source§

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

Performs the %= operation. Read more
Source§

impl RemAssign for bf16

Source§

fn rem_assign(&mut self, rhs: bf16)

Performs the %= operation. Read more
Source§

impl Sub<&bf16> for &bf16

Source§

type Output = <bf16 as Sub>::Output

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<&bf16> for bf16

Source§

type Output = <bf16 as Sub>::Output

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<bf16> for &bf16

Source§

type Output = <bf16 as Sub>::Output

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for bf16

Source§

type Output = bf16

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<&bf16> for bf16

Source§

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

Performs the -= operation. Read more
Source§

impl SubAssign for bf16

Source§

fn sub_assign(&mut self, rhs: bf16)

Performs the -= operation. Read more
Source§

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

Source§

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

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

impl Sum for bf16

Source§

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

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

impl ToLexical for bf16

Source§

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

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

impl ToLexicalWithOptions for bf16

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: &<bf16 as ToLexicalWithOptions>::Options, ) -> &'a mut [u8]

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

impl TryFrom<f32> for bf16

Source§

type Error = TryFromFloatError

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

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

Performs the conversion.
Source§

impl TryFrom<f64> for bf16

Source§

type Error = TryFromFloatError

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

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

Performs the conversion.
Source§

impl UpperExp for bf16

Source§

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

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

impl UpperHex for bf16

Source§

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

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

impl Copy for bf16

Source§

impl Primitive for bf16

Auto Trait Implementations§

§

impl Freeze for bf16

§

impl RefUnwindSafe for bf16

§

impl Send for bf16

§

impl Sync for bf16

§

impl Unpin for bf16

§

impl UnwindSafe for bf16

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.