[−][src]Struct ibmfloat::F32
A 32-bit IBM floating point number.
This type supports the conversions:
- Transmuting to/from a
u32
viafrom_bits()
,to_bits()
- Transmuting to/from a big-endian
[u8; 4]
viafrom_be_bytes()
/to_be_bytes()
- Lossily converting to an
f32
viaFrom
/Into
- Losslessly converting to an
f64
viaFrom
/Into
IBM F32
floats have slightly less precision than IEEE-754 f32
floats, but it covers a
slightly larger domain. F32
s of typical magnitude can be converted to f32
without rounding
or other loss of precision. Converting F32
s of large magnitude to f32
will cause rounding;
F32
s of extreme magnitude can also cause overflow and underflow to occur.
Every F32
can be precisely represented as an f64
, without rounding, overflow, or underflow.
Those seeking a lossless path to IEEE-754 should convert F32
to f64
.
// Use the example -118.625: // https://en.wikipedia.org/wiki/IBM_hexadecimal_floating_point#Example let foreign_float = ibmfloat::F32::from_bits(0b1_1000010_0111_0110_1010_0000_0000_0000); let native_float = f32::from(foreign_float); assert_eq!(native_float, -118.625f32); let native_float: f32 = foreign_float.into(); assert_eq!(native_float, -118.625f32);
Methods
impl F32
[src]
pub fn from_bits(value: u32) -> Self
[src]
Transmute a native-endian u64
into an F64
.
let foreign_float = ibmfloat::F32::from_bits(0x46000001); let native_float = f32::from(foreign_float); // potential loss of precision assert_eq!(native_float, 1.0f32); let native_float = f64::from(foreign_float); // always exact assert_eq!(native_float, 1.0f64);
pub fn to_bits(self) -> u32
[src]
Transmute this F32
to a native-endian u32
.
let foreign_float = ibmfloat::F32::from_bits(0x46000001); assert_eq!(foreign_float.to_bits(), 0x46000001);
pub fn from_be_bytes(bytes: [u8; 4]) -> Self
[src]
Create a floating point value from its representation as a byte array in big endian.
let foreign_float = ibmfloat::F32::from_be_bytes([0x46, 0, 0, 1]); assert_eq!(foreign_float.to_bits(), 0x46000001); let native_float = f32::from(foreign_float); assert_eq!(native_float, 1.0f32);
pub fn to_be_bytes(self) -> [u8; 4]
[src]
Return the memory representation of this floating point number as a byte array in big-endian (network) byte order.
let foreign_float = ibmfloat::F32::from_bits(0x46000001); assert_eq!(foreign_float.to_be_bytes(), [0x46, 0, 0, 1]);
Trait Implementations
impl Clone for F32
[src]
impl Copy for F32
[src]
impl Debug for F32
[src]
impl From<F32> for f32
[src]
impl From<F32> for f64
[src]
impl PartialEq<F32> for F32
[src]
impl PartialOrd<F32> for F32
[src]
Auto Trait Implementations
impl RefUnwindSafe for F32
impl Send for F32
impl Sync for F32
impl Unpin for F32
impl UnwindSafe for F32
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,