pub struct HFloating(/* private fields */);Expand description
§The VAX H_floating type.
§Reference Documentation
Here are excerpts from the VAX Architecture Reference Manual and the VAX MACRO and Instruction Set Reference Manual for the VAX H_floating floating-point type.
§VAX Architecture Reference Manual
The H_floating data type need not be supported by a subset implementation. An H_floating datum is 16 contiguous bytes starting on an arbitrary byte boundary. The bits are labeled from the right 〈0〉 through 〈127〉, as shown in Figure 1.2. An H_floating datum is specified by its address A which is the address of the byte containing bit 〈0〉. The form of an H_floating datum is sign magnitude with bit 〈15〉, the sign bit; bits 〈14:0〉, an excess 16384 binary exponent; and bits 〈127:16〉, a normalized 113-bit fraction with the redundant most-significant fraction bit not represented. Within the fraction, bits of increasing significance are from 〈112〉 through 〈127〉, 〈96〉 through 〈111〉, 〈80〉 through 〈95〉, 〈64〉 through 〈79〉, 〈48〉 through 〈63〉, 〈32〉 through 〈47〉, and 〈16〉 through 〈31〉. The 15-bit exponent field encodes the values 0 through 32767. An exponent value of 0 together with a sign bit of 0 is taken to indicate that the H_floating datum has a value of O. Exponent values of 1 through 32767 indicate true binary exponents of -16383 through +16383. An exponent value of 0 together with a sign bit of 1 is taken as reserved. Floating-point instructions processing a reserved operand take a reserved operand fault (see Chapters 3 and 5). The value of an H_floating datum is in the approximate range .84*10-4932 through .59*104932. The precision of an H_floating datum is approximately one part in 2112, typically 33 decimal digits.
§VAX MACRO and Instruction Set Reference Manual
An H_floating datum is 16 contiguous bytes starting on an arbitrary byte boundary. The 128 bits are labeled from right to left 0 to 127.
An H_floating datum is specified by its address, A, which is the address of the byte containing bit 0. The form of an H_floating datum is sign magnitude with bit 15 as the sign bit, bits 14:0 as an excess 16,384 binary exponent, and bits 127:16 as a normalized 113-bit fraction with the redundant most-significant fraction bit not represented. Within the fraction, bits of increasing significance range from bits 112 to 127, 96 to 111, 80 to 95, 64 to 79, 48 to 63, 32 to 47, and 16 to 31. The 15-bit exponent field encodes the values 0 to 32,767. An exponent value of zero, together with a sign bit of 0, is taken to indicate that the H_floating datum has a value of zero. Exponent values of 1 to 32,767 indicate true binary exponents of -16,383 to +16,383. An exponent value of zero, together with a sign bit of 1, is taken as reserved. Floating-point instructions processing a reserved operand take a reserved operand fault (see Appendix E). The value of an H_floating datum is in the approximate range .84*10**-4932 to .59*10**4932. The precision of an H_floating datum is approximately one part in 2**112, typically, 33 decimal digits.
§Bibliography
- Bhandarkar, D. P., Conklin, P. F., Cutler, D. N., Eggers, T. W., Hastings, T. N., Hustvedt, R. I., Leonard, J. S., Lipman, P., Rarich, T., Rodgers, D. P., Rothman, S., Strecker, W. D., & Taylor, T. B. (1987). VAX Architecture Reference Manual (T. E. Leonard, Ed.). DECBooks.
- Compaq Computer Corporation (2001). VAX MACRO and Instruction Set Reference Manual. Compaq Computer Corporation.
Implementations§
Source§impl HFloating
impl HFloating
Sourcepub const MANTISSA_DIGITS: u32 = 113u32
pub const MANTISSA_DIGITS: u32 = 113u32
Number of significant digits in base 2.
Sourcepub const EPSILON: HFloating
pub const EPSILON: HFloating
Machine epsilon value for HFloating.
This is the difference between 1.0 and the next larger representable number.
Sourcepub const MIN_POSITIVE: HFloating
pub const MIN_POSITIVE: HFloating
Smallest positive normal HFloating value.
Sourcepub const MIN_EXP: i32 = -16_383i32
pub const MIN_EXP: i32 = -16_383i32
One greater than the minimum possible normal power of 2 exponent.
Sourcepub const MIN_10_EXP: i32 = -4_932i32
pub const MIN_10_EXP: i32 = -4_932i32
Minimum possible normal power of 10 exponent.
Sourcepub const MAX_10_EXP: i32 = 4_931i32
pub const MAX_10_EXP: i32 = 4_931i32
Maximum possible power of 10 exponent.
Sourcepub const fn to_bits(self) -> u128
pub const fn to_bits(self) -> u128
Raw transmutation from the HFloating type to u128.
§Examples
assert_eq!(HFloating::from_f32(0_f32).to_bits(), 0_u128);
assert_eq!(HFloating::from_f32(1.5).to_bits(), 0x0000000000000000000000000080004001_u128);
assert_eq!(HFloating::from_f32(12.5).to_bits(), 0x0000000000000000000000000090004004_u128);Sourcepub const fn from_bits(bits: u128) -> Self
pub const fn from_bits(bits: u128) -> Self
Raw transmutation from a u128 the HFloating type.
§Examples
assert_eq!(HFloating::from_bits(0), HFloating::from_f32(0_f32));
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), HFloating::from_f32(1.5));
assert_eq!(HFloating::from_bits(0x0000000000000000000000000090004004), HFloating::from_f32(12.5));Sourcepub const fn to_le_bytes(&self) -> [u8; 16]
pub const fn to_le_bytes(&self) -> [u8; 16]
Return the memory representation of the HFloating type as a byte array in little-endian byte order.
§Examples
let bytes = HFloating::from_f32(12.5).to_le_bytes();
assert_eq!(bytes, [0x04, 0x40, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);Sourcepub const fn to_be_bytes(&self) -> [u8; 16]
pub const fn to_be_bytes(&self) -> [u8; 16]
Return the memory representation of the HFloating type as a byte array in big-endian (network) byte order.
§Examples
let bytes = HFloating::from_f32(12.5).to_be_bytes();
assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x40, 0x04]);Sourcepub const fn to_ne_bytes(&self) -> [u8; 16]
pub const fn to_ne_bytes(&self) -> [u8; 16]
Return the memory representation of the HFloating type as a byte array in native byte order.
§Examples
let bytes = HFloating::from_f32(12.5).to_ne_bytes();
assert_eq!(
bytes,
if cfg!(target_endian = "big") {
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x40, 0x04]
} else {
[0x04, 0x40, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
);Sourcepub const fn from_le_bytes(bytes: [u8; 16]) -> Self
pub const fn from_le_bytes(bytes: [u8; 16]) -> Self
Create a HFloating type from its representation as a byte array in little endian.
§Examples
let float = HFloating::from_le_bytes([0x04, 0x40, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
assert_eq!(float, HFloating::from_f32(12.5));Sourcepub const fn from_be_bytes(bytes: [u8; 16]) -> Self
pub const fn from_be_bytes(bytes: [u8; 16]) -> Self
Create a HFloating type from its representation as a byte array in big endian.
§Examples
let float = HFloating::from_be_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x40, 0x04]);
assert_eq!(float, HFloating::from_f32(12.5));Sourcepub const fn from_ne_bytes(bytes: [u8; 16]) -> Self
pub const fn from_ne_bytes(bytes: [u8; 16]) -> Self
Create a HFloating type from its representation as a byte array in native endianness.
§Examples
let float = HFloating::from_ne_bytes(
if cfg!(target_endian = "big") {
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x40, 0x04]
} else {
[0x04, 0x40, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
);
assert_eq!(float, HFloating::from_f32(12.5));Sourcepub const fn to_swapped(self) -> u128
pub const fn to_swapped(self) -> u128
Reverses the (16-bit) word order of the raw transmutation of a u128 into the HFloating type.
§Examples
assert_eq!(HFloating::from_bits(0x0000000000000000000000000090004004).to_swapped(), 0x40049000000000000000000000000000_u128);
assert_eq!(HFloating::from_f32(12.5).to_swapped(), 0x40049000000000000000000000000000_u128);Sourcepub const fn from_swapped(swapped: u128) -> Self
pub const fn from_swapped(swapped: u128) -> Self
Reverses the (16-bit) word order of the raw transmutation of the HFloating type into a u128.
§Examples
assert_eq!(HFloating::from_swapped(0x40049000000000000000000000000000), HFloating::from_f32(12.5));
assert_eq!(HFloating::from_swapped(0x40049000000000000000000000000000), HFloating::from_bits(0x0000000000000000000000000090004004));Sourcepub const fn signum(self) -> Self
pub const fn signum(self) -> Self
Returns a number that represents the sign of self.
1.0if the number is positive,+0.0-1.0if the number is negativeReservedif the number isReserved
§Examples
const ONE: HFloating = HFloating::from_i8(1);
const NEG: HFloating = HFloating::from_i8(-1);
assert_eq!(HFloating::from_bits(0).signum(), ONE);
assert_eq!(HFloating::MIN_POSITIVE.signum(), ONE);
assert_eq!(HFloating::MAX.signum(), ONE);
assert_eq!(HFloating::MIN.signum(), NEG);
assert!(HFloating::from_bits(0x8000).signum().is_reserved());Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Return true if the HFloating is zero.
§Examples
assert_eq!(HFloating::from_bits(0).is_zero(), true);
assert_eq!(HFloating::MIN_POSITIVE.is_zero(), false);
assert_eq!(HFloating::MAX.is_zero(), false);
assert_eq!(HFloating::MIN.is_zero(), false);
// As long as the sign and exponent is zero, it is considered to be zero.
assert_eq!(HFloating::from_bits(0xFFFF0000_u128).is_zero(), true);Sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Return true if the HFloating is negative.
§Examples
assert_eq!(HFloating::from_bits(0).is_negative(), false);
assert_eq!(HFloating::MIN_POSITIVE.is_negative(), false);
assert_eq!(HFloating::MAX.is_negative(), false);
assert_eq!(HFloating::MIN.is_negative(), true);
// All reserved values have the sign bit set, but are not negative.
assert_eq!(HFloating::from_bits(0x8000_u128).is_negative(), false);Sourcepub const fn is_reserved(&self) -> bool
pub const fn is_reserved(&self) -> bool
Return true if the HFloating is reserved.
§Examples
assert_eq!(HFloating::from_bits(0).is_reserved(), false);
assert_eq!(HFloating::MIN_POSITIVE.is_reserved(), false);
assert_eq!(HFloating::MAX.is_reserved(), false);
assert_eq!(HFloating::MIN.is_reserved(), false);
// As long as the sign is negative and exponent is zero, it is considered reserved.
assert_eq!(HFloating::from_bits(0x8000_u128).is_reserved(), true);
assert_eq!(HFloating::from_bits(0xFFFF8000_u128).is_reserved(), true);Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Force the sign of the HFloating to positive.
§Examples
for (case, abs) in [
(0_f32, 0_f32), // Zero doesn't have a sign.
(1.5, 1.5), // Positive isn't changed.
(-3.14, 3.14), // Negative to positive.
(-0.04, 0.04), // Negative to positive.
].iter() {
assert_eq!(HFloating::from_f32(*case).abs(), HFloating::from_f32(*abs));
}Sourcepub const fn negate(self) -> Self
pub const fn negate(self) -> Self
Negate the sign of the HFloating value.
§Examples
for (case, neg) in [
(0_f32, 0_f32), // Zero doesn't have a sign.
(1.5, -1.5), // Positive to negative.
(-3.14, 3.14), // Negative to positive.
].iter() {
assert_eq!(HFloating::from_f32(*case).negate(), HFloating::from_f32(*neg));
}Sourcepub const fn sign(&self) -> Sign
pub const fn sign(&self) -> Sign
Return the sign of the HFloating value.
§Examples
for (case, sign) in [
(-0.0_f32, Sign::Positive),
(1.5, Sign::Positive),
(-3.14, Sign::Negative),
].iter() {
assert_eq!(HFloating::from_f32(*case).sign(), *sign);
}Sourcepub const fn add_to(self, other: Self) -> Self
pub const fn add_to(self, other: Self) -> Self
Add a HFloating to another HFloating.
§Examples
const NINETEEN_POINT_FIVE: HFloating = HFloating::from_u8(17).add_to(HFloating::from_f32(2.5));
let seventeen = HFloating::from_u8(17);
let two_point_five = HFloating::from_f32(2.5);
assert_eq!(seventeen + two_point_five, NINETEEN_POINT_FIVE);This is the same as the addition (+) operator, except it can be used to
define constants.
const NINETEEN_POINT_FIVE: HFloating = HFloating::from_u8(17) + HFloating::from_f32(2.5);Sourcepub const fn subtract_by(self, other: Self) -> Self
pub const fn subtract_by(self, other: Self) -> Self
Subtract a HFloating from another HFloating.
§Examples
const FOURTEEN_POINT_FIVE: HFloating = HFloating::from_u8(17).subtract_by(HFloating::from_f32(2.5));
let seventeen = HFloating::from_u8(17);
let two_point_five = HFloating::from_f32(2.5);
assert_eq!(seventeen - two_point_five, FOURTEEN_POINT_FIVE);This is the same as the subtraction (-) operator, except it can be used to
define constants.
const FOURTEEN_POINT_FIVE: HFloating = HFloating::from_u8(17) - HFloating::from_f32(2.5);Sourcepub const fn multiply_by(self, multiplier: Self) -> Self
pub const fn multiply_by(self, multiplier: Self) -> Self
Multiply a HFloating by another HFloating.
§Examples
const SEVENTEEN_TIMES_TWENTY_THREE: HFloating = HFloating::from_u8(17).multiply_by(HFloating::from_u8(23));
let seventeen = HFloating::from_u8(17);
let twenty_three = HFloating::from_u8(23);
assert_eq!(seventeen * twenty_three, SEVENTEEN_TIMES_TWENTY_THREE);This is the same as the multiplication (*) operator, except it can be used to
define constants.
const SEVENTEEN_TIMES_TWENTY_THREE: HFloating = HFloating::from_u8(17) * HFloating::from_u8(23);Sourcepub const fn divide_by(self, divisor: Self) -> Self
pub const fn divide_by(self, divisor: Self) -> Self
Divide a HFloating by another HFloating.
§Examples
const TWENTY_TWO_SEVENTHS: HFloating = HFloating::from_u8(22).divide_by(HFloating::from_u8(7));
let twenty_two = HFloating::from_u8(22);
let seven = HFloating::from_u8(7);
assert_eq!(twenty_two / seven, TWENTY_TWO_SEVENTHS);This is the same as the division (/) operator, except it can be used to define
constants.
const TWENTY_TWO_SEVENTHS: HFloating = HFloating::from_u8(22) / HFloating::from_u8(7);Sourcepub const fn to_fp(&self) -> VaxFloatingPoint<u128>
pub const fn to_fp(&self) -> VaxFloatingPoint<u128>
Convert from a HFloating to a VaxFloatingPoint<u128>.
VaxFloatingPoint is used internally for performing mathmatical operations. Since
the VaxFloatingPoint<u128> type has more precision (it uses the entireu128)
and supports exponent values outside the range of the
HFloating(H_floating)
floating-point type, it may be useful for some calculations.
§Examples
const TWO: VaxFloatingPoint<u128> = HFloating::from_ascii("2").to_fp();
const THREE: VaxFloatingPoint<u128> = VaxFloatingPoint::<u128>::from_u8(3);
const TWO_THIRDS_MAX: HFloating = HFloating::MAX.divide_by(HFloating::from_u8(3)).multiply_by(HFloating::from_u8(2));
let fp = HFloating::MAX.to_fp();
let invalid = fp * TWO;
let two_thirds = invalid / THREE;
assert_eq!(HFloating::from_fp(two_thirds), TWO_THIRDS_MAX);
assert!(HFloating::from_fp(invalid).is_reserved());Sourcepub const fn from_fp(fp: VaxFloatingPoint<u128>) -> Self
pub const fn from_fp(fp: VaxFloatingPoint<u128>) -> Self
Convert from a VaxFloatingPoint<u128> to a HFloating.
VaxFloatingPoint is used internally for performing mathmatical operations. Since
the VaxFloatingPoint<u128> type has more precision (it uses the entireu128)
and supports exponent values outside the range of the
HFloating(H_floating)
floating-point type, it may be useful for some calculations.
§Examples
const TWO: VaxFloatingPoint<u128> = HFloating::from_ascii("2").to_fp();
const THREE: VaxFloatingPoint<u128> = VaxFloatingPoint::<u128>::from_u8(3);
const TWO_THIRDS_MAX: HFloating = HFloating::MAX.divide_by(HFloating::from_u8(3)).multiply_by(HFloating::from_u8(2));
let fp = HFloating::MAX.to_fp();
let invalid = fp * TWO;
let two_thirds = invalid / THREE;
assert_eq!(HFloating::from_fp(two_thirds), TWO_THIRDS_MAX);
assert!(HFloating::from_fp(invalid).is_reserved());Sourcepub const fn from_ascii(text: &str) -> HFloating
pub const fn from_ascii(text: &str) -> HFloating
Parse a string slice into a HFloating.
§Panics
This will panic if it fails to parse the string.
§Examples
const TWELVE_DOT_FIVE: HFloating = HFloating::from_ascii("12.5");
assert_eq!(HFloating::from_f32(12.5), TWELVE_DOT_FIVE);Invalid input strings will fail to compile.
const TWO_DECIMAL_POINTS: HFloating = HFloating::from_ascii("..");Unlike FromStr::from_str, from_ascii can be used to define constants.
const TWELVE_DOT_FIVE: HFloating = HFloating::from_str("12.5").unwrap();Sourcepub const fn unwrap(self) -> Self
pub const fn unwrap(self) -> Self
Panic if the HFloating is not a valid value (i.e. reserved).
This should be used when defining constants to check for errors.
§Panics
Panics if the value is reserved (i.e. sign bit set with exponent value of zero).
§Examples
const TWELVE_DOT_FIVE: HFloating = HFloating::from_f32(12.5).unwrap();
assert_eq!(HFloating::from_f32(12.5), TWELVE_DOT_FIVE);const OVERFLOW: HFloating = HFloating::MAX.add_to(HFloating::MAX).unwrap();const DIV_BY_ZERO: HFloating = HFloating::MAX.divide_by(HFloating::from_bits(0));
// Without unwrap, sets constant to divide-by-zero encoded reserved value.
assert_eq!(HFloating::from_bits(0x8000), DIV_BY_ZERO);const DIV_BY_ZERO: HFloating = HFloating::MAX.divide_by(HFloating::from_bits(0)).unwrap();Sourcepub const fn unwrap_or_default(self) -> Self
pub const fn unwrap_or_default(self) -> Self
Return the defualt value if the HFloating is not valid (i.e. reserved).
§Examples
const TWELVE_DOT_FIVE: HFloating = HFloating::from_f32(12.5).unwrap_or_default();
assert_eq!(HFloating::from_f32(12.5), TWELVE_DOT_FIVE);
const OVERFLOW: HFloating = HFloating::MAX.add_to(HFloating::MAX).unwrap_or_default();
assert_eq!(HFloating::default(), OVERFLOW);Sourcepub const fn unwrap_or(self, default: Self) -> Self
pub const fn unwrap_or(self, default: Self) -> Self
Return an alternate value if the HFloating is not valid (i.e. reserved).
§Examples
const TWELVE_DOT_FIVE: HFloating = HFloating::from_f32(12.5).unwrap_or(HFloating::MAX);
assert_eq!(HFloating::from_f32(12.5), TWELVE_DOT_FIVE);
const OVERFLOW: HFloating = HFloating::MAX.add_to(HFloating::MAX).unwrap_or(HFloating::MAX);
assert_eq!(HFloating::MAX, OVERFLOW);Sourcepub fn unwrap_or_else<F: FnOnce(Self) -> Self>(self, op: F) -> Self
pub fn unwrap_or_else<F: FnOnce(Self) -> Self>(self, op: F) -> Self
Returns the result from a closure if the HFloating is not valid (i.e. reserved).
This is included for completeness, but it isn’t const like the other unwrap
functions.
§Examples
use vax_floating::Result;
fn saturate_float(float: HFloating) -> HFloating {
use vax_floating::Error::*;
match <Result<HFloating>>::from(float) {
Ok(float) => float,
Err(Overflow(_)) | Err(DivByZero) => HFloating::MAX,
Err(Underflow(_)) => HFloating::MIN_POSITIVE,
Err(_) => HFloating::MIN,
}
}
let twelve_dot_five: HFloating = HFloating::from_f32(12.5).unwrap_or_else(saturate_float);
assert_eq!(HFloating::from_f32(12.5), twelve_dot_five);
let overflow: HFloating = HFloating::MAX.add_to(HFloating::MAX).unwrap_or_else(saturate_float);
assert_eq!(HFloating::MAX, overflow);Sourcepub const fn from_u8(src: u8) -> Self
pub const fn from_u8(src: u8) -> Self
Convert from u8 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_u8(0_u8);
const TEN: HFloating = HFloating::from_u8(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<u8> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_u8);Sourcepub const fn from_i8(src: i8) -> Self
pub const fn from_i8(src: i8) -> Self
Convert from i8 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_i8(0_i8);
const TEN: HFloating = HFloating::from_i8(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<i8> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_i8);Sourcepub const fn from_u16(src: u16) -> Self
pub const fn from_u16(src: u16) -> Self
Convert from u16 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_u16(0_u16);
const TEN: HFloating = HFloating::from_u16(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<u16> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_u16);Sourcepub const fn from_i16(src: i16) -> Self
pub const fn from_i16(src: i16) -> Self
Convert from i16 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_i16(0_i16);
const TEN: HFloating = HFloating::from_i16(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<i16> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_i16);Sourcepub const fn from_u32(src: u32) -> Self
pub const fn from_u32(src: u32) -> Self
Convert from u32 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_u32(0_u32);
const TEN: HFloating = HFloating::from_u32(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<u32> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_u32);Sourcepub const fn from_i32(src: i32) -> Self
pub const fn from_i32(src: i32) -> Self
Convert from i32 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_i32(0_i32);
const TEN: HFloating = HFloating::from_i32(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<i32> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_i32);Sourcepub const fn from_u64(src: u64) -> Self
pub const fn from_u64(src: u64) -> Self
Convert from u64 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_u64(0_u64);
const TEN: HFloating = HFloating::from_u64(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<u64> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_u64);Sourcepub const fn from_i64(src: i64) -> Self
pub const fn from_i64(src: i64) -> Self
Convert from i64 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_i64(0_i64);
const TEN: HFloating = HFloating::from_i64(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<i64> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_i64);Sourcepub const fn from_usize(src: usize) -> Self
pub const fn from_usize(src: usize) -> Self
Convert from usize to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_usize(0_usize);
const TEN: HFloating = HFloating::from_usize(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<usize> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_usize);Sourcepub const fn from_isize(src: isize) -> Self
pub const fn from_isize(src: isize) -> Self
Convert from isize to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_isize(0_isize);
const TEN: HFloating = HFloating::from_isize(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<isize> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_isize);Sourcepub const fn from_u128(src: u128) -> Self
pub const fn from_u128(src: u128) -> Self
Convert from u128 to a HFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: HFloating = HFloating::from_u128(0_u128);
const TEN: HFloating = HFloating::from_u128(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<u128> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_u128);Sourcepub const fn from_i128(src: i128) -> Self
pub const fn from_i128(src: i128) -> Self
Convert from i128 to a HFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: HFloating = HFloating::from_i128(0_i128);
const TEN: HFloating = HFloating::from_i128(10);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x00000000000000000000000040004004), TEN);From<i128> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_i128);Sourcepub const fn from_f32(src: f32) -> Self
pub const fn from_f32(src: f32) -> Self
Convert from f32 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_f32(0_f32);
const THREE_HALVES: HFloating = HFloating::from_f32(1.5);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<f32> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_f32);Sourcepub const fn to_f32(&self) -> f32
pub const fn to_f32(&self) -> f32
Convert from a HFloating to f32.
Can be used to define constants.
§Examples
const ZERO: f32 = HFloating::from_bits(0).to_f32();
const THREE_HALVES: f32 = HFloating::from_bits(0x0000000000000000000000000080004001).to_f32();
assert_eq!(ZERO, 0.0_f32);
assert_eq!(THREE_HALVES, 1.5_f32);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001).to_f32(), 1.5_f32);From<HFloating> cannot be used to define constants.
const ZERO: f32 = f32::from(HFloating::from_bits(0));Sourcepub const fn from_f64(src: f64) -> Self
pub const fn from_f64(src: f64) -> Self
Convert from f64 to a HFloating.
Can be used to define constants.
§Examples
const ZERO: HFloating = HFloating::from_f64(0_f64);
const THREE_HALVES: HFloating = HFloating::from_f64(1.5);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<f64> cannot be used to define constants.
const ZERO: HFloating = HFloating::from(0_f64);Sourcepub const fn to_f64(&self) -> f64
pub const fn to_f64(&self) -> f64
Convert from a HFloating to f64.
Can be used to define constants.
§Examples
const ZERO: f64 = HFloating::from_bits(0).to_f64();
const THREE_HALVES: f64 = HFloating::from_bits(0x0000000000000000000000000080004001).to_f64();
assert_eq!(ZERO, 0.0_f64);
assert_eq!(THREE_HALVES, 1.5_f64);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001).to_f64(), 1.5_f64);From<HFloating> cannot be used to define constants.
const ZERO: f64 = f64::from(HFloating::from_bits(0));Sourcepub const fn from_f_floating(src: FFloating) -> Self
pub const fn from_f_floating(src: FFloating) -> Self
Convert from FFloating to a HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: FFloating = FFloating::from_bits(0);
const FROM_THREE_HALVES: FFloating = FFloating::from_f32(1.5);
const ZERO: HFloating = HFloating::from_f_floating(FROM_ZERO);
const THREE_HALVES: HFloating = HFloating::from_f_floating(FROM_THREE_HALVES);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<FFloating> cannot be used to define constants.
const FROM_ZERO: FFloating = FFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Sourcepub const fn to_f_floating(&self) -> FFloating
pub const fn to_f_floating(&self) -> FFloating
Convert from a HFloating to FFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const FROM_THREE_HALVES: HFloating = HFloating::from_bits(0x0000000000000000000000000080004001);
const ZERO: FFloating = FROM_ZERO.to_f_floating();
const THREE_HALVES: FFloating = FROM_THREE_HALVES.to_f_floating();
assert_eq!(ZERO, FFloating::from_bits(0));
assert_eq!(THREE_HALVES, FFloating::from_f32(1.5));From<HFloating> cannot be used to define constants.
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const ZERO: FFloating = FFloating::from(FROM_ZERO);Sourcepub const fn from_d_floating(src: DFloating) -> Self
pub const fn from_d_floating(src: DFloating) -> Self
Convert from DFloating to a HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const FROM_THREE_HALVES: DFloating = DFloating::from_f32(1.5);
const ZERO: HFloating = HFloating::from_d_floating(FROM_ZERO);
const THREE_HALVES: HFloating = HFloating::from_d_floating(FROM_THREE_HALVES);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Sourcepub const fn to_d_floating(&self) -> DFloating
pub const fn to_d_floating(&self) -> DFloating
Convert from a HFloating to DFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const FROM_THREE_HALVES: HFloating = HFloating::from_bits(0x0000000000000000000000000080004001);
const ZERO: DFloating = FROM_ZERO.to_d_floating();
const THREE_HALVES: DFloating = FROM_THREE_HALVES.to_d_floating();
assert_eq!(ZERO, DFloating::from_bits(0));
assert_eq!(THREE_HALVES, DFloating::from_f32(1.5));From<HFloating> cannot be used to define constants.
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const ZERO: DFloating = DFloating::from(FROM_ZERO);Sourcepub const fn from_g_floating(src: GFloating) -> Self
pub const fn from_g_floating(src: GFloating) -> Self
Convert from GFloating to a HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: GFloating = GFloating::from_bits(0);
const FROM_THREE_HALVES: GFloating = GFloating::from_f32(1.5);
const ZERO: HFloating = HFloating::from_g_floating(FROM_ZERO);
const THREE_HALVES: HFloating = HFloating::from_g_floating(FROM_THREE_HALVES);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<GFloating> cannot be used to define constants.
const FROM_ZERO: GFloating = GFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Sourcepub const fn to_g_floating(&self) -> GFloating
pub const fn to_g_floating(&self) -> GFloating
Convert from a HFloating to GFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const FROM_THREE_HALVES: HFloating = HFloating::from_bits(0x0000000000000000000000000080004001);
const ZERO: GFloating = FROM_ZERO.to_g_floating();
const THREE_HALVES: GFloating = FROM_THREE_HALVES.to_g_floating();
assert_eq!(ZERO, GFloating::from_bits(0));
assert_eq!(THREE_HALVES, GFloating::from_f32(1.5));From<HFloating> cannot be used to define constants.
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const ZERO: GFloating = GFloating::from(FROM_ZERO);Sourcepub const fn from_h_floating(src: HFloating) -> Self
pub const fn from_h_floating(src: HFloating) -> Self
Convert from HFloating to a HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const FROM_THREE_HALVES: HFloating = HFloating::from_f32(1.5);
const ZERO: HFloating = HFloating::from_h_floating(FROM_ZERO);
const THREE_HALVES: HFloating = HFloating::from_h_floating(FROM_THREE_HALVES);
assert_eq!(HFloating::from_bits(0), ZERO);
assert_eq!(HFloating::from_bits(0x0000000000000000000000000080004001), THREE_HALVES);From<HFloating> cannot be used to define constants.
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Sourcepub const fn to_h_floating(&self) -> HFloating
pub const fn to_h_floating(&self) -> HFloating
Convert from a HFloating to HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const FROM_THREE_HALVES: HFloating = HFloating::from_bits(0x0000000000000000000000000080004001);
const ZERO: HFloating = FROM_ZERO.to_h_floating();
const THREE_HALVES: HFloating = FROM_THREE_HALVES.to_h_floating();
assert_eq!(ZERO, HFloating::from_bits(0));
assert_eq!(THREE_HALVES, HFloating::from_f32(1.5));From<HFloating> cannot be used to define constants.
const FROM_ZERO: HFloating = HFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Trait Implementations§
Source§impl AddAssign<&HFloating> for HFloating
impl AddAssign<&HFloating> for HFloating
Source§fn add_assign(&mut self, other: &HFloating)
fn add_assign(&mut self, other: &HFloating)
+= operation. Read moreSource§impl AddAssign for HFloating
impl AddAssign for HFloating
Source§fn add_assign(&mut self, other: HFloating)
fn add_assign(&mut self, other: HFloating)
+= operation. Read moreSource§impl DivAssign<&HFloating> for HFloating
impl DivAssign<&HFloating> for HFloating
Source§fn div_assign(&mut self, other: &HFloating)
fn div_assign(&mut self, other: &HFloating)
/= operation. Read moreSource§impl DivAssign for HFloating
impl DivAssign for HFloating
Source§fn div_assign(&mut self, other: HFloating)
fn div_assign(&mut self, other: HFloating)
/= operation. Read moreSource§impl From<&i128> for HFloating
impl From<&i128> for HFloating
Source§fn from(src: &i128) -> Self
fn from(src: &i128) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&u128> for HFloating
impl From<&u128> for HFloating
Source§fn from(src: &u128) -> Self
fn from(src: &u128) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<i128> for HFloating
impl From<i128> for HFloating
Source§fn from(src: i128) -> Self
fn from(src: i128) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<u128> for HFloating
impl From<u128> for HFloating
Source§fn from(src: u128) -> Self
fn from(src: u128) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of HFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl MulAssign<&HFloating> for HFloating
impl MulAssign<&HFloating> for HFloating
Source§fn mul_assign(&mut self, other: &HFloating)
fn mul_assign(&mut self, other: &HFloating)
*= operation. Read moreSource§impl MulAssign for HFloating
impl MulAssign for HFloating
Source§fn mul_assign(&mut self, other: HFloating)
fn mul_assign(&mut self, other: HFloating)
*= operation. Read moreSource§impl PartialOrd for HFloating
impl PartialOrd for HFloating
Source§impl ShlAssign<&u32> for HFloating
impl ShlAssign<&u32> for HFloating
Source§fn shl_assign(&mut self, other: &u32)
fn shl_assign(&mut self, other: &u32)
<<= operation. Read moreSource§impl ShlAssign<u32> for HFloating
impl ShlAssign<u32> for HFloating
Source§fn shl_assign(&mut self, other: u32)
fn shl_assign(&mut self, other: u32)
<<= operation. Read moreSource§impl ShrAssign<&u32> for HFloating
impl ShrAssign<&u32> for HFloating
Source§fn shr_assign(&mut self, other: &u32)
fn shr_assign(&mut self, other: &u32)
>>= operation. Read moreSource§impl ShrAssign<u32> for HFloating
impl ShrAssign<u32> for HFloating
Source§fn shr_assign(&mut self, other: u32)
fn shr_assign(&mut self, other: u32)
>>= operation. Read moreSource§impl SubAssign<&HFloating> for HFloating
impl SubAssign<&HFloating> for HFloating
Source§fn sub_assign(&mut self, other: &HFloating)
fn sub_assign(&mut self, other: &HFloating)
-= operation. Read moreSource§impl SubAssign for HFloating
impl SubAssign for HFloating
Source§fn sub_assign(&mut self, other: HFloating)
fn sub_assign(&mut self, other: HFloating)
-= operation. Read more