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 F16IEEE 754 binary16: 1 sign, 5 exponent and 10 significand bits.
The gap between 1.0 and the next larger value (2^-10).
The largest value, 65504.
The smallest value, -65504.
The smallest positive normal value (2^-14).
Not a number: the quiet NaN with the sign bit clear.
Positive infinity.
Negative infinity.
The value with the bit pattern
bits.The bit pattern.
xrounded to nearest, ties to even.xrounded to nearest, ties to even (once, not throughf32).xrounded to nearest, ties to even.xrounded to nearest, ties to even.The value as an
f32, exactly.truefor NaN.truefor +/-inf.truefor neither inf nor NaN.truefor neither zero, subnormal, inf nor NaN.The absolute value (the sign bit cleared).
The value as an
f64, exactly.truefor a positive sign bit (+0.0, a positive NaN).truefor a negative sign bit (-0.0, a negative NaN).self's magnitude withsign's sign bit.The smaller of the two; a NaN operand gives the other one, and
-0.0is below+0.0(asf32::min).The larger of the two; a NaN operand gives the other one, and
+0.0is above-0.0(asf32::max).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 BF16bfloat16: f32's sign and 8 exponent bits, 7 significand bits.
The gap between 1.0 and the next larger value (2^-7).
The largest value, about 3.39e38.
The smallest value.
The smallest positive normal value (2^-126).
Not a number: the quiet NaN with the sign bit clear.
Positive infinity.
Negative infinity.
The value with the bit pattern
bits.The bit pattern.
xrounded to nearest, ties to even.xrounded to nearest, ties to even (once, not throughf32).xrounded to nearest, ties to even (once, not throughf64).xrounded to nearest, ties to even (once, not throughf64).The value as an
f32, exactly: the high half of its bits.truefor NaN.truefor +/-inf.truefor neither inf nor NaN.truefor neither zero, subnormal, inf nor NaN.The absolute value (the sign bit cleared).
The value as an
f64, exactly.truefor a positive sign bit (+0.0, a positive NaN).truefor a negative sign bit (-0.0, a negative NaN).self's magnitude withsign's sign bit.The smaller of the two; a NaN operand gives the other one, and
-0.0is below+0.0(asf32::min).The larger of the two; a NaN operand gives the other one, and
+0.0is above-0.0(asf32::max).The IEEE 754 total order:
-NaN < -inf < .. < -0 < +0 < .. < inf < NaN. Sorting by it never fails:xs.sort_by(bf16::total_cmp).