pub struct f16b(/* private fields */);f16b)Expand description
A 16-bit brain floating-point value.
This type stores values using the bfloat16 encoding. It deliberately
exposes only raw-bit construction, comparison, formatting, and lossless
widening to f32.
The 16-bit brain floating-point intends to preserve the dynamic range of
a 32-bit floating-point value while using half the storage. It does
this by using 8 bits for the exponent, the same as f32, but only
using 7 bits for the mantissa. See Wikipedia on bfloat16 for
more information.
Implementationsยง
Sourceยงimpl f16b
impl f16b
Sourcepub const fn from_bits(bits: u16) -> f16b
๐ฌThis is a nightly-only experimental API. (f16b)
pub const fn from_bits(bits: u16) -> f16b
f16b)Raw transmutation from u16.
This is currently identical to transmute::<u16, f16b>(v) on all platforms.
It turns out this is incredibly portable, for two reasons:
- Floats and Ints have the same endianness on all supported platforms.
- IEEE 754 very precisely specifies the bit layout of floats.
However there is one caveat: prior to the 2008 version of IEEE 754, how to interpret the NaN signaling bit wasnโt actually specified. Most platforms (notably x86 and ARM) picked the interpretation that was ultimately standardized in 2008, but some didnโt (notably MIPS). As a result, all signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.
Rather than trying to preserve signaling-ness cross-platform, this implementation favors preserving the exact bits. This means that any payloads encoded in NaNs will be preserved even if the result of this method is sent over the network from an x86 machine to a MIPS one.
If the results of this method are only manipulated by the same architecture that produced them, then there is no portability concern.
If the input isnโt NaN, then there is no portability concern.
If you donโt care about signalingness (very likely), then there is no portability concern.
Note that this function is distinct from as casting, which attempts to
preserve the numeric value, and not the bitwise value.
#![feature(f16b)]
use core::num::f16b;
let v = f16b::from_bits(0x4148);
assert_eq!(f32::from(v), 12.5);Sourcepub const fn to_bits(self) -> u16
๐ฌThis is a nightly-only experimental API. (f16b)
pub const fn to_bits(self) -> u16
f16b)Raw transmutation to u16.
This is currently identical to transmute::<f16b, u16>(self) on all platforms.
See from_bits for some discussion of the
portability of this operation (there are almost no issues).
Note that this function is distinct from as casting, which attempts to
preserve the numeric value, and not the bitwise value.
#![feature(f16b)]
use core::num::f16b;
assert_eq!(f16b::from_bits(0x4148).to_bits(), 0x4148);Trait Implementationsยง
impl Copy for f16b
Auto Trait Implementationsยง
impl Freeze for f16b
impl RefUnwindSafe for f16b
impl Send for f16b
impl Sync for f16b
impl Unpin for f16b
impl UnsafeUnpin for f16b
impl UnwindSafe for f16b
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
ยงimpl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
ยงimpl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
ยงimpl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more