docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

core::num::half

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

f16 (IEEE 754 binary16) and bf16 (bfloat16), storage types held as their 16 bits. #[keyword] routes the type names here; a literal in an f16 / bf16 slot is its bits, rounded once from the decimal, and as converts to and from every number primitive.

Conversions round to nearest, ties to even, straight from the source (an f64 or an i64 is never rounded to f32 first). Arithmetic is done in f32 and rounded once to the type: for + - * / % and sqrt that is the correctly rounded result. Comparisons are those of the f32 values. f16 <-> f32 runs on the CPU where it converts (x86-64 with F16C, arm64), else in the runtime.

Structs

F16Source

pub struct F16

IEEE 754 binary16: 1 sign, 5 exponent and 10 significand bits.

  • pub const EPSILON: F16 = F16 { bits: 0x1400u16 }§

    Source

    The gap between 1.0 and the next larger value (2^-10).

  • pub const MAX: F16 = F16 { bits: 0x7bffu16 }§

    Source

    The largest value, 65504.

  • pub const MIN: F16 = F16 { bits: 0xfbffu16 }§

    Source

    The smallest value, -65504.

  • pub const MIN_POSITIVE: F16 = F16 { bits: 0x0400u16 }§

    Source

    The smallest positive normal value (2^-14).

  • pub const NAN: F16 = F16 { bits: 0x7e00u16 }§

    Source

    Not a number: the quiet NaN with the sign bit clear.

  • pub const INFINITY: F16 = F16 { bits: 0x7c00u16 }§

    Source

    Positive infinity.

  • pub const NEG_INFINITY: F16 = F16 { bits: 0xfc00u16 }§

    Source

    Negative infinity.

  • pub const fn from_bits(bits: u16) -> F16§

    Source

    The value with the bit pattern bits.

  • pub const fn to_bits(self) -> u16§

    Source

    The bit pattern.

  • pub const fn from_f32(x: f32) -> F16§

    Source

    x rounded to nearest, ties to even.

  • pub const fn from_f64(x: f64) -> F16§

    Source

    x rounded to nearest, ties to even (once, not through f32).

  • pub const fn from_i64(x: i64) -> F16§

    Source

    x rounded to nearest, ties to even.

  • pub const fn from_u64(x: u64) -> F16§

    Source

    x rounded to nearest, ties to even.

  • pub const fn to_f32(self) -> f32§

    Source

    The value as an f32, exactly.

  • pub const fn is_nan(self) -> bool§

    Source

    true for NaN.

  • pub const fn is_infinite(self) -> bool§

    Source

    true for +/-inf.

  • pub const fn is_finite(self) -> bool§

    Source

    true for neither inf nor NaN.

  • pub const fn is_normal(self) -> bool§

    Source

    true for neither zero, subnormal, inf nor NaN.

  • pub const fn abs(self) -> F16§

    Source

    The absolute value (the sign bit cleared).

  • pub const fn to_f64(self) -> f64§

    Source

    The value as an f64, exactly.

  • pub const fn is_sign_positive(self) -> bool§

    Source

    true for a positive sign bit (+0.0, a positive NaN).

  • pub const fn is_sign_negative(self) -> bool§

    Source

    true for a negative sign bit (-0.0, a negative NaN).

  • pub const fn copysign(self, sign: F16) -> F16§

    Source

    self's magnitude with sign's sign bit.

  • pub const fn min(self, other: F16) -> F16§

    Source

    The smaller of the two; a NaN operand gives the other one, and -0.0 is below +0.0 (as f32::min).

  • pub const fn max(self, other: F16) -> F16§

    Source

    The larger of the two; a NaN operand gives the other one, and +0.0 is above -0.0 (as f32::max).

  • pub const fn total_cmp(self, other: F16) -> core::cmp::Ordering§

    Source

    The IEEE 754 total order: -NaN < -inf < .. < -0 < +0 < .. < inf < NaN. Sorting by it never fails: xs.sort_by(f16::total_cmp).

BF16Source

pub struct BF16

bfloat16: f32's sign and 8 exponent bits, 7 significand bits.

  • pub const EPSILON: BF16 = BF16 { bits: 0x3c00u16 }§

    Source

    The gap between 1.0 and the next larger value (2^-7).

  • pub const MAX: BF16 = BF16 { bits: 0x7f7fu16 }§

    Source

    The largest value, about 3.39e38.

  • pub const MIN: BF16 = BF16 { bits: 0xff7fu16 }§

    Source

    The smallest value.

  • pub const MIN_POSITIVE: BF16 = BF16 { bits: 0x0080u16 }§

    Source

    The smallest positive normal value (2^-126).

  • pub const NAN: BF16 = BF16 { bits: 0x7fc0u16 }§

    Source

    Not a number: the quiet NaN with the sign bit clear.

  • pub const INFINITY: BF16 = BF16 { bits: 0x7f80u16 }§

    Source

    Positive infinity.

  • pub const NEG_INFINITY: BF16 = BF16 { bits: 0xff80u16 }§

    Source

    Negative infinity.

  • pub const fn from_bits(bits: u16) -> BF16§

    Source

    The value with the bit pattern bits.

  • pub const fn to_bits(self) -> u16§

    Source

    The bit pattern.

  • pub const fn from_f32(x: f32) -> BF16§

    Source

    x rounded to nearest, ties to even.

  • pub const fn from_f64(x: f64) -> BF16§

    Source

    x rounded to nearest, ties to even (once, not through f32).

  • pub const fn from_i64(x: i64) -> BF16§

    Source

    x rounded to nearest, ties to even (once, not through f64).

  • pub const fn from_u64(x: u64) -> BF16§

    Source

    x rounded to nearest, ties to even (once, not through f64).

  • pub const fn to_f32(self) -> f32§

    Source

    The value as an f32, exactly: the high half of its bits.

  • pub const fn is_nan(self) -> bool§

    Source

    true for NaN.

  • pub const fn is_infinite(self) -> bool§

    Source

    true for +/-inf.

  • pub const fn is_finite(self) -> bool§

    Source

    true for neither inf nor NaN.

  • pub const fn is_normal(self) -> bool§

    Source

    true for neither zero, subnormal, inf nor NaN.

  • pub const fn abs(self) -> BF16§

    Source

    The absolute value (the sign bit cleared).

  • pub const fn to_f64(self) -> f64§

    Source

    The value as an f64, exactly.

  • pub const fn is_sign_positive(self) -> bool§

    Source

    true for a positive sign bit (+0.0, a positive NaN).

  • pub const fn is_sign_negative(self) -> bool§

    Source

    true for a negative sign bit (-0.0, a negative NaN).

  • pub const fn copysign(self, sign: BF16) -> BF16§

    Source

    self's magnitude with sign's sign bit.

  • pub const fn min(self, other: BF16) -> BF16§

    Source

    The smaller of the two; a NaN operand gives the other one, and -0.0 is below +0.0 (as f32::min).

  • pub const fn max(self, other: BF16) -> BF16§

    Source

    The larger of the two; a NaN operand gives the other one, and +0.0 is above -0.0 (as f32::max).

  • pub const fn total_cmp(self, other: BF16) -> core::cmp::Ordering§

    Source

    The IEEE 754 total order: -NaN < -inf < .. < -0 < +0 < .. < inf < NaN. Sorting by it never fails: xs.sort_by(bf16::total_cmp).