pub struct F64(/* private fields */);Expand description
A 64-bit IBM floating point number.
This type supports the conversions:
- Transmuting to/from a
u64viafrom_bits(),to_bits() - Transmuting to/from a big-endian
[u8; 8]viafrom_be_bytes()/to_be_bytes() - Lossily converting to an
f32viaFrom/Into - Lossily converting to an
f64viaFrom/Into
IBM F64 floats have slightly more precision than IEEE-754 f64 floats, but they cover a
slightly smaller domain. Most conversions will require rounding, but there is no risk of
overflow or underflow.
let foreign_float = ibmfloat::F64::from_bits(0x4110000000000000);
let native_float = f64::from(foreign_float);
assert_eq!(native_float, 1.0f64);
let native_float: f64 = foreign_float.into();
assert_eq!(native_float, 1.0f64);Implementations§
Source§impl F64
impl F64
Sourcepub fn from_bits(value: u64) -> Self
pub fn from_bits(value: u64) -> Self
Transmute a native-endian u64 into an F64.
let foreign_float = ibmfloat::F64::from_bits(0x4110000000000000);
let native_float = f64::from(foreign_float);
assert_eq!(native_float, 1.0f64);Sourcepub fn to_bits(self) -> u64
pub fn to_bits(self) -> u64
Transmute this F64 to a native-endian u64.
let foreign_float = ibmfloat::F64::from_bits(0x4110000000000000);
assert_eq!(foreign_float.to_bits(), 0x4110000000000000);Sourcepub fn from_be_bytes(bytes: [u8; 8]) -> Self
pub fn from_be_bytes(bytes: [u8; 8]) -> Self
Create a floating point value from its representation as a byte array in big endian.
let foreign_float = ibmfloat::F64::from_be_bytes([0x41, 0x10, 0, 0, 0, 0, 0, 0]);
assert_eq!(foreign_float.to_bits(), 0x4110000000000000);
let native_float = f64::from(foreign_float);
assert_eq!(native_float, 1.0f64);Sourcepub fn to_be_bytes(self) -> [u8; 8]
pub fn to_be_bytes(self) -> [u8; 8]
Return the memory representation of this floating point number as a byte array in big-endian (network) byte order.
let foreign_float = ibmfloat::F64::from_bits(0x4110000000000000);
assert_eq!(foreign_float.to_be_bytes(), [0x41, 0x10, 0, 0, 0, 0, 0, 0]);Trait Implementations§
Source§impl PartialOrd for F64
impl PartialOrd for F64
impl Copy for F64
Auto Trait Implementations§
impl Freeze for F64
impl RefUnwindSafe for F64
impl Send for F64
impl Sync for F64
impl Unpin for F64
impl UnwindSafe for F64
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
Mutably borrows from an owned value. Read more