pub struct DFloating(/* private fields */);Expand description
§The VAX D_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 D_floating floating-point type.
§VAX Architecture Reference Manual
This data type need not be supported in a subset implementation. A D_floating datum is 8 contiguous bytes starting on an arbitrary byte boundary. The bits are labeled from the right 〈0〉 through 〈63〉, as shown in Figure 1.2. A D_floating datum is specified by its address A, the address of the byte containing bit 〈0〉. The form of a D_floating datum is identical to a floating datum except for an additional 32 low- significance fraction bits. Within the fraction, bits of increasing significance are from 〈48〉 through 〈63〉, 〈32〉 through 〈47〉, 〈16〉 through 〈31〉, and 〈0〉 through 〈6〉. The exponent conventions and approximate range of values is the same for D_floating as for F_floating. The precision of a D_floating datum is approximately one part in 255, typically 16 decimal digits.
§VAX MACRO and Instruction Set Reference Manual
A D_floating datum is 8 contiguous bytes starting on an arbitrary byte boundary. The bits are labeled from right to left 0 to 63.
A D_floating datum is specified by its address, A, which is the address of the byte containing bit 0. The form of a D_floating datum is identical to an F_floating datum except for additional 32 low-significance fraction bits. Within the fraction, bits of increasing significance range from bits 48 to 63, 32 to 47, 16 to 31, and 0 to 6. The exponent conventions and the approximate range of values are the same for D_floating as they are for F_floating. The precision of a D_floating datum is approximately one part in 2**55, typically, 16 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 DFloating
impl DFloating
Sourcepub const MANTISSA_DIGITS: u32 = 56u32
pub const MANTISSA_DIGITS: u32 = 56u32
Number of significant digits in base 2.
Sourcepub const EPSILON: DFloating
pub const EPSILON: DFloating
Machine epsilon value for DFloating.
This is the difference between 1.0 and the next larger representable number.
Sourcepub const MIN_POSITIVE: DFloating
pub const MIN_POSITIVE: DFloating
Smallest positive normal DFloating value.
Sourcepub const MIN_EXP: i32 = -127i32
pub const MIN_EXP: i32 = -127i32
One greater than the minimum possible normal power of 2 exponent.
Sourcepub const MIN_10_EXP: i32 = -38i32
pub const MIN_10_EXP: i32 = -38i32
Minimum possible normal power of 10 exponent.
Sourcepub const MAX_10_EXP: i32 = 38i32
pub const MAX_10_EXP: i32 = 38i32
Maximum possible power of 10 exponent.
Sourcepub const fn to_bits(self) -> u64
pub const fn to_bits(self) -> u64
Raw transmutation from the DFloating type to u64.
§Examples
assert_eq!(DFloating::from_f32(0_f32).to_bits(), 0_u64);
assert_eq!(DFloating::from_f32(1.5).to_bits(), 0x00000000000040C0_u64);
assert_eq!(DFloating::from_f32(12.5).to_bits(), 0x0000000000004248_u64);Sourcepub const fn from_bits(bits: u64) -> Self
pub const fn from_bits(bits: u64) -> Self
Raw transmutation from a u64 the DFloating type.
§Examples
assert_eq!(DFloating::from_bits(0), DFloating::from_f32(0_f32));
assert_eq!(DFloating::from_bits(0x00000000000040C0), DFloating::from_f32(1.5));
assert_eq!(DFloating::from_bits(0x0000000000004248), DFloating::from_f32(12.5));Sourcepub const fn to_le_bytes(&self) -> [u8; 8]
pub const fn to_le_bytes(&self) -> [u8; 8]
Return the memory representation of the DFloating type as a byte array in little-endian byte order.
§Examples
let bytes = DFloating::from_f32(12.5).to_le_bytes();
assert_eq!(bytes, [0x48, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);Sourcepub const fn to_be_bytes(&self) -> [u8; 8]
pub const fn to_be_bytes(&self) -> [u8; 8]
Return the memory representation of the DFloating type as a byte array in big-endian (network) byte order.
§Examples
let bytes = DFloating::from_f32(12.5).to_be_bytes();
assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x48]);Sourcepub const fn to_ne_bytes(&self) -> [u8; 8]
pub const fn to_ne_bytes(&self) -> [u8; 8]
Return the memory representation of the DFloating type as a byte array in native byte order.
§Examples
let bytes = DFloating::from_f32(12.5).to_ne_bytes();
assert_eq!(
bytes,
if cfg!(target_endian = "big") {
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x48]
} else {
[0x48, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
);Sourcepub const fn from_le_bytes(bytes: [u8; 8]) -> Self
pub const fn from_le_bytes(bytes: [u8; 8]) -> Self
Create a DFloating type from its representation as a byte array in little endian.
§Examples
let float = DFloating::from_le_bytes([0x48, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
assert_eq!(float, DFloating::from_f32(12.5));Sourcepub const fn from_be_bytes(bytes: [u8; 8]) -> Self
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self
Create a DFloating type from its representation as a byte array in big endian.
§Examples
let float = DFloating::from_be_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x48]);
assert_eq!(float, DFloating::from_f32(12.5));Sourcepub const fn from_ne_bytes(bytes: [u8; 8]) -> Self
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self
Create a DFloating type from its representation as a byte array in native endianness.
§Examples
let float = DFloating::from_ne_bytes(
if cfg!(target_endian = "big") {
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x48]
} else {
[0x48, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
}
);
assert_eq!(float, DFloating::from_f32(12.5));Sourcepub const fn to_swapped(self) -> u64
pub const fn to_swapped(self) -> u64
Reverses the (16-bit) word order of the raw transmutation of a u64 into the DFloating type.
§Examples
assert_eq!(DFloating::from_bits(0x0000000000004248).to_swapped(), 0x4248000000000000_u64);
assert_eq!(DFloating::from_f32(12.5).to_swapped(), 0x4248000000000000_u64);Sourcepub const fn from_swapped(swapped: u64) -> Self
pub const fn from_swapped(swapped: u64) -> Self
Reverses the (16-bit) word order of the raw transmutation of the DFloating type into a u64.
§Examples
assert_eq!(DFloating::from_swapped(0x4248000000000000), DFloating::from_f32(12.5));
assert_eq!(DFloating::from_swapped(0x4248000000000000), DFloating::from_bits(0x0000000000004248));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: DFloating = DFloating::from_i8(1);
const NEG: DFloating = DFloating::from_i8(-1);
assert_eq!(DFloating::from_bits(0).signum(), ONE);
assert_eq!(DFloating::MIN_POSITIVE.signum(), ONE);
assert_eq!(DFloating::MAX.signum(), ONE);
assert_eq!(DFloating::MIN.signum(), NEG);
assert!(DFloating::from_bits(0x8000).signum().is_reserved());Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Return true if the DFloating is zero.
§Examples
assert_eq!(DFloating::from_bits(0).is_zero(), true);
assert_eq!(DFloating::MIN_POSITIVE.is_zero(), false);
assert_eq!(DFloating::MAX.is_zero(), false);
assert_eq!(DFloating::MIN.is_zero(), false);
// As long as the sign and exponent is zero, it is considered to be zero.
assert_eq!(DFloating::from_bits(0xFFFF0000_u64).is_zero(), true);Sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Return true if the DFloating is negative.
§Examples
assert_eq!(DFloating::from_bits(0).is_negative(), false);
assert_eq!(DFloating::MIN_POSITIVE.is_negative(), false);
assert_eq!(DFloating::MAX.is_negative(), false);
assert_eq!(DFloating::MIN.is_negative(), true);
// All reserved values have the sign bit set, but are not negative.
assert_eq!(DFloating::from_bits(0x8000_u64).is_negative(), false);Sourcepub const fn is_reserved(&self) -> bool
pub const fn is_reserved(&self) -> bool
Return true if the DFloating is reserved.
§Examples
assert_eq!(DFloating::from_bits(0).is_reserved(), false);
assert_eq!(DFloating::MIN_POSITIVE.is_reserved(), false);
assert_eq!(DFloating::MAX.is_reserved(), false);
assert_eq!(DFloating::MIN.is_reserved(), false);
// As long as the sign is negative and exponent is zero, it is considered reserved.
assert_eq!(DFloating::from_bits(0x8000_u64).is_reserved(), true);
assert_eq!(DFloating::from_bits(0xFFFF8000_u64).is_reserved(), true);Sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Force the sign of the DFloating 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!(DFloating::from_f32(*case).abs(), DFloating::from_f32(*abs));
}Sourcepub const fn negate(self) -> Self
pub const fn negate(self) -> Self
Negate the sign of the DFloating 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!(DFloating::from_f32(*case).negate(), DFloating::from_f32(*neg));
}Sourcepub const fn sign(&self) -> Sign
pub const fn sign(&self) -> Sign
Return the sign of the DFloating value.
§Examples
for (case, sign) in [
(-0.0_f32, Sign::Positive),
(1.5, Sign::Positive),
(-3.14, Sign::Negative),
].iter() {
assert_eq!(DFloating::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 DFloating to another DFloating.
§Examples
const NINETEEN_POINT_FIVE: DFloating = DFloating::from_u8(17).add_to(DFloating::from_f32(2.5));
let seventeen = DFloating::from_u8(17);
let two_point_five = DFloating::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: DFloating = DFloating::from_u8(17) + DFloating::from_f32(2.5);Sourcepub const fn subtract_by(self, other: Self) -> Self
pub const fn subtract_by(self, other: Self) -> Self
Subtract a DFloating from another DFloating.
§Examples
const FOURTEEN_POINT_FIVE: DFloating = DFloating::from_u8(17).subtract_by(DFloating::from_f32(2.5));
let seventeen = DFloating::from_u8(17);
let two_point_five = DFloating::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: DFloating = DFloating::from_u8(17) - DFloating::from_f32(2.5);Sourcepub const fn multiply_by(self, multiplier: Self) -> Self
pub const fn multiply_by(self, multiplier: Self) -> Self
Multiply a DFloating by another DFloating.
§Examples
const SEVENTEEN_TIMES_TWENTY_THREE: DFloating = DFloating::from_u8(17).multiply_by(DFloating::from_u8(23));
let seventeen = DFloating::from_u8(17);
let twenty_three = DFloating::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: DFloating = DFloating::from_u8(17) * DFloating::from_u8(23);Sourcepub const fn divide_by(self, divisor: Self) -> Self
pub const fn divide_by(self, divisor: Self) -> Self
Divide a DFloating by another DFloating.
§Examples
const TWENTY_TWO_SEVENTHS: DFloating = DFloating::from_u8(22).divide_by(DFloating::from_u8(7));
let twenty_two = DFloating::from_u8(22);
let seven = DFloating::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: DFloating = DFloating::from_u8(22) / DFloating::from_u8(7);Sourcepub const fn to_fp(&self) -> VaxFloatingPoint<u64>
pub const fn to_fp(&self) -> VaxFloatingPoint<u64>
Convert from a DFloating to a VaxFloatingPoint<u64>.
VaxFloatingPoint is used internally for performing mathmatical operations. Since
the VaxFloatingPoint<u64> type has more precision (it uses the entireu64)
and supports exponent values outside the range of the
DFloating(D_floating)
floating-point type, it may be useful for some calculations.
§Examples
const TWO: VaxFloatingPoint<u64> = DFloating::from_ascii("2").to_fp();
const THREE: VaxFloatingPoint<u64> = VaxFloatingPoint::<u64>::from_u8(3);
const TWO_THIRDS_MAX: DFloating = DFloating::MAX.divide_by(DFloating::from_u8(3)).multiply_by(DFloating::from_u8(2));
let fp = DFloating::MAX.to_fp();
let invalid = fp * TWO;
let two_thirds = invalid / THREE;
assert_eq!(DFloating::from_fp(two_thirds), TWO_THIRDS_MAX);
assert!(DFloating::from_fp(invalid).is_reserved());Sourcepub const fn from_fp(fp: VaxFloatingPoint<u64>) -> Self
pub const fn from_fp(fp: VaxFloatingPoint<u64>) -> Self
Convert from a VaxFloatingPoint<u64> to a DFloating.
VaxFloatingPoint is used internally for performing mathmatical operations. Since
the VaxFloatingPoint<u64> type has more precision (it uses the entireu64)
and supports exponent values outside the range of the
DFloating(D_floating)
floating-point type, it may be useful for some calculations.
§Examples
const TWO: VaxFloatingPoint<u64> = DFloating::from_ascii("2").to_fp();
const THREE: VaxFloatingPoint<u64> = VaxFloatingPoint::<u64>::from_u8(3);
const TWO_THIRDS_MAX: DFloating = DFloating::MAX.divide_by(DFloating::from_u8(3)).multiply_by(DFloating::from_u8(2));
let fp = DFloating::MAX.to_fp();
let invalid = fp * TWO;
let two_thirds = invalid / THREE;
assert_eq!(DFloating::from_fp(two_thirds), TWO_THIRDS_MAX);
assert!(DFloating::from_fp(invalid).is_reserved());Sourcepub const fn from_ascii(text: &str) -> DFloating
pub const fn from_ascii(text: &str) -> DFloating
Parse a string slice into a DFloating.
§Panics
This will panic if it fails to parse the string.
§Examples
const TWELVE_DOT_FIVE: DFloating = DFloating::from_ascii("12.5");
assert_eq!(DFloating::from_f32(12.5), TWELVE_DOT_FIVE);Invalid input strings will fail to compile.
const TWO_DECIMAL_POINTS: DFloating = DFloating::from_ascii("..");Unlike FromStr::from_str, from_ascii can be used to define constants.
const TWELVE_DOT_FIVE: DFloating = DFloating::from_str("12.5").unwrap();Sourcepub const fn unwrap(self) -> Self
pub const fn unwrap(self) -> Self
Panic if the DFloating 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: DFloating = DFloating::from_f32(12.5).unwrap();
assert_eq!(DFloating::from_f32(12.5), TWELVE_DOT_FIVE);const OVERFLOW: DFloating = DFloating::MAX.add_to(DFloating::MAX).unwrap();const DIV_BY_ZERO: DFloating = DFloating::MAX.divide_by(DFloating::from_bits(0));
// Without unwrap, sets constant to divide-by-zero encoded reserved value.
assert_eq!(DFloating::from_bits(0x8000), DIV_BY_ZERO);const DIV_BY_ZERO: DFloating = DFloating::MAX.divide_by(DFloating::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 DFloating is not valid (i.e. reserved).
§Examples
const TWELVE_DOT_FIVE: DFloating = DFloating::from_f32(12.5).unwrap_or_default();
assert_eq!(DFloating::from_f32(12.5), TWELVE_DOT_FIVE);
const OVERFLOW: DFloating = DFloating::MAX.add_to(DFloating::MAX).unwrap_or_default();
assert_eq!(DFloating::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 DFloating is not valid (i.e. reserved).
§Examples
const TWELVE_DOT_FIVE: DFloating = DFloating::from_f32(12.5).unwrap_or(DFloating::MAX);
assert_eq!(DFloating::from_f32(12.5), TWELVE_DOT_FIVE);
const OVERFLOW: DFloating = DFloating::MAX.add_to(DFloating::MAX).unwrap_or(DFloating::MAX);
assert_eq!(DFloating::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 DFloating 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: DFloating) -> DFloating {
use vax_floating::Error::*;
match <Result<DFloating>>::from(float) {
Ok(float) => float,
Err(Overflow(_)) | Err(DivByZero) => DFloating::MAX,
Err(Underflow(_)) => DFloating::MIN_POSITIVE,
Err(_) => DFloating::MIN,
}
}
let twelve_dot_five: DFloating = DFloating::from_f32(12.5).unwrap_or_else(saturate_float);
assert_eq!(DFloating::from_f32(12.5), twelve_dot_five);
let overflow: DFloating = DFloating::MAX.add_to(DFloating::MAX).unwrap_or_else(saturate_float);
assert_eq!(DFloating::MAX, overflow);Sourcepub const fn from_u8(src: u8) -> Self
pub const fn from_u8(src: u8) -> Self
Convert from u8 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_u8(0_u8);
const TEN: DFloating = DFloating::from_u8(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<u8> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_u8);Sourcepub const fn from_i8(src: i8) -> Self
pub const fn from_i8(src: i8) -> Self
Convert from i8 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_i8(0_i8);
const TEN: DFloating = DFloating::from_i8(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<i8> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_i8);Sourcepub const fn from_u16(src: u16) -> Self
pub const fn from_u16(src: u16) -> Self
Convert from u16 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_u16(0_u16);
const TEN: DFloating = DFloating::from_u16(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<u16> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_u16);Sourcepub const fn from_i16(src: i16) -> Self
pub const fn from_i16(src: i16) -> Self
Convert from i16 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_i16(0_i16);
const TEN: DFloating = DFloating::from_i16(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<i16> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_i16);Sourcepub const fn from_u32(src: u32) -> Self
pub const fn from_u32(src: u32) -> Self
Convert from u32 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_u32(0_u32);
const TEN: DFloating = DFloating::from_u32(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<u32> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_u32);Sourcepub const fn from_i32(src: i32) -> Self
pub const fn from_i32(src: i32) -> Self
Convert from i32 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_i32(0_i32);
const TEN: DFloating = DFloating::from_i32(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<i32> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_i32);Sourcepub const fn from_u64(src: u64) -> Self
pub const fn from_u64(src: u64) -> Self
Convert from u64 to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_u64(0_u64);
const TEN: DFloating = DFloating::from_u64(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<u64> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_u64);Sourcepub const fn from_i64(src: i64) -> Self
pub const fn from_i64(src: i64) -> Self
Convert from i64 to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_i64(0_i64);
const TEN: DFloating = DFloating::from_i64(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<i64> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_i64);Sourcepub const fn from_usize(src: usize) -> Self
pub const fn from_usize(src: usize) -> Self
Convert from usize to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_usize(0_usize);
const TEN: DFloating = DFloating::from_usize(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<usize> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_usize);Sourcepub const fn from_isize(src: isize) -> Self
pub const fn from_isize(src: isize) -> Self
Convert from isize to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_isize(0_isize);
const TEN: DFloating = DFloating::from_isize(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<isize> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_isize);Sourcepub const fn from_u128(src: u128) -> Self
pub const fn from_u128(src: u128) -> Self
Convert from u128 to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_u128(0_u128);
const TEN: DFloating = DFloating::from_u128(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<u128> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_u128);Sourcepub const fn from_i128(src: i128) -> Self
pub const fn from_i128(src: i128) -> Self
Convert from i128 to a DFloating.
Can be used to define constants.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
§Examples
const ZERO: DFloating = DFloating::from_i128(0_i128);
const TEN: DFloating = DFloating::from_i128(10);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x0000000000004220), TEN);From<i128> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_i128);Sourcepub const fn from_f32(src: f32) -> Self
pub const fn from_f32(src: f32) -> Self
Convert from f32 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_f32(0_f32);
const THREE_HALVES: DFloating = DFloating::from_f32(1.5);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);From<f32> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_f32);Sourcepub const fn to_f32(&self) -> f32
pub const fn to_f32(&self) -> f32
Convert from a DFloating to f32.
Can be used to define constants.
§Examples
const ZERO: f32 = DFloating::from_bits(0).to_f32();
const THREE_HALVES: f32 = DFloating::from_bits(0x00000000000040C0).to_f32();
assert_eq!(ZERO, 0.0_f32);
assert_eq!(THREE_HALVES, 1.5_f32);
assert_eq!(DFloating::from_bits(0x00000000000040C0).to_f32(), 1.5_f32);From<DFloating> cannot be used to define constants.
const ZERO: f32 = f32::from(DFloating::from_bits(0));Sourcepub const fn from_f64(src: f64) -> Self
pub const fn from_f64(src: f64) -> Self
Convert from f64 to a DFloating.
Can be used to define constants.
§Examples
const ZERO: DFloating = DFloating::from_f64(0_f64);
const THREE_HALVES: DFloating = DFloating::from_f64(1.5);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);From<f64> cannot be used to define constants.
const ZERO: DFloating = DFloating::from(0_f64);Sourcepub const fn to_f64(&self) -> f64
pub const fn to_f64(&self) -> f64
Convert from a DFloating to f64.
Can be used to define constants.
§Examples
const ZERO: f64 = DFloating::from_bits(0).to_f64();
const THREE_HALVES: f64 = DFloating::from_bits(0x00000000000040C0).to_f64();
assert_eq!(ZERO, 0.0_f64);
assert_eq!(THREE_HALVES, 1.5_f64);
assert_eq!(DFloating::from_bits(0x00000000000040C0).to_f64(), 1.5_f64);From<DFloating> cannot be used to define constants.
const ZERO: f64 = f64::from(DFloating::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 DFloating.
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: DFloating = DFloating::from_f_floating(FROM_ZERO);
const THREE_HALVES: DFloating = DFloating::from_f_floating(FROM_THREE_HALVES);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);From<FFloating> cannot be used to define constants.
const FROM_ZERO: FFloating = FFloating::from_bits(0);
const ZERO: DFloating = DFloating::from(FROM_ZERO);Sourcepub const fn to_f_floating(&self) -> FFloating
pub const fn to_f_floating(&self) -> FFloating
Convert from a DFloating to FFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const FROM_THREE_HALVES: DFloating = DFloating::from_bits(0x00000000000040C0);
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<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::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 DFloating.
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: DFloating = DFloating::from_d_floating(FROM_ZERO);
const THREE_HALVES: DFloating = DFloating::from_d_floating(FROM_THREE_HALVES);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);From<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const ZERO: DFloating = DFloating::from(FROM_ZERO);Sourcepub const fn to_d_floating(&self) -> DFloating
pub const fn to_d_floating(&self) -> DFloating
Convert from a DFloating to DFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const FROM_THREE_HALVES: DFloating = DFloating::from_bits(0x00000000000040C0);
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<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::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 DFloating.
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: DFloating = DFloating::from_g_floating(FROM_ZERO);
const THREE_HALVES: DFloating = DFloating::from_g_floating(FROM_THREE_HALVES);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);From<GFloating> cannot be used to define constants.
const FROM_ZERO: GFloating = GFloating::from_bits(0);
const ZERO: DFloating = DFloating::from(FROM_ZERO);Sourcepub const fn to_g_floating(&self) -> GFloating
pub const fn to_g_floating(&self) -> GFloating
Convert from a DFloating to GFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const FROM_THREE_HALVES: DFloating = DFloating::from_bits(0x00000000000040C0);
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<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::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 DFloating.
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: DFloating = DFloating::from_h_floating(FROM_ZERO);
const THREE_HALVES: DFloating = DFloating::from_h_floating(FROM_THREE_HALVES);
assert_eq!(DFloating::from_bits(0), ZERO);
assert_eq!(DFloating::from_bits(0x00000000000040C0), THREE_HALVES);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 to_h_floating(&self) -> HFloating
pub const fn to_h_floating(&self) -> HFloating
Convert from a DFloating to HFloating.
Can be used to define constants.
§Examples
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const FROM_THREE_HALVES: DFloating = DFloating::from_bits(0x00000000000040C0);
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<DFloating> cannot be used to define constants.
const FROM_ZERO: DFloating = DFloating::from_bits(0);
const ZERO: HFloating = HFloating::from(FROM_ZERO);Trait Implementations§
Source§impl AddAssign<&DFloating> for DFloating
impl AddAssign<&DFloating> for DFloating
Source§fn add_assign(&mut self, other: &DFloating)
fn add_assign(&mut self, other: &DFloating)
+= operation. Read moreSource§impl AddAssign for DFloating
impl AddAssign for DFloating
Source§fn add_assign(&mut self, other: DFloating)
fn add_assign(&mut self, other: DFloating)
+= operation. Read moreSource§impl DivAssign<&DFloating> for DFloating
impl DivAssign<&DFloating> for DFloating
Source§fn div_assign(&mut self, other: &DFloating)
fn div_assign(&mut self, other: &DFloating)
/= operation. Read moreSource§impl DivAssign for DFloating
impl DivAssign for DFloating
Source§fn div_assign(&mut self, other: DFloating)
fn div_assign(&mut self, other: DFloating)
/= operation. Read moreSource§impl From<&i128> for DFloating
impl From<&i128> for DFloating
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 DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&i64> for DFloating
impl From<&i64> for DFloating
Source§fn from(src: &i64) -> Self
fn from(src: &i64) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&isize> for DFloating
impl From<&isize> for DFloating
Source§fn from(src: &isize) -> Self
fn from(src: &isize) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&u128> for DFloating
impl From<&u128> for DFloating
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 DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&u64> for DFloating
impl From<&u64> for DFloating
Source§fn from(src: &u64) -> Self
fn from(src: &u64) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<&usize> for DFloating
impl From<&usize> for DFloating
Source§fn from(src: &usize) -> Self
fn from(src: &usize) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<i128> for DFloating
impl From<i128> for DFloating
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 DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<i64> for DFloating
impl From<i64> for DFloating
Source§fn from(src: i64) -> Self
fn from(src: i64) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<isize> for DFloating
impl From<isize> for DFloating
Source§fn from(src: isize) -> Self
fn from(src: isize) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<u128> for DFloating
impl From<u128> for DFloating
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 DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<u64> for DFloating
impl From<u64> for DFloating
Source§fn from(src: u64) -> Self
fn from(src: u64) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl From<usize> for DFloating
impl From<usize> for DFloating
Source§fn from(src: usize) -> Self
fn from(src: usize) -> Self
Converts to this type from the input type.
Note: Only the most significant set bits that fit into the number of DFloating::MANTISSA_DIGITS will be preserved. This will result in a loss
of precision.
Source§impl MulAssign<&DFloating> for DFloating
impl MulAssign<&DFloating> for DFloating
Source§fn mul_assign(&mut self, other: &DFloating)
fn mul_assign(&mut self, other: &DFloating)
*= operation. Read moreSource§impl MulAssign for DFloating
impl MulAssign for DFloating
Source§fn mul_assign(&mut self, other: DFloating)
fn mul_assign(&mut self, other: DFloating)
*= operation. Read moreSource§impl PartialOrd for DFloating
impl PartialOrd for DFloating
Source§impl ShlAssign<&u32> for DFloating
impl ShlAssign<&u32> for DFloating
Source§fn shl_assign(&mut self, other: &u32)
fn shl_assign(&mut self, other: &u32)
<<= operation. Read moreSource§impl ShlAssign<u32> for DFloating
impl ShlAssign<u32> for DFloating
Source§fn shl_assign(&mut self, other: u32)
fn shl_assign(&mut self, other: u32)
<<= operation. Read moreSource§impl ShrAssign<&u32> for DFloating
impl ShrAssign<&u32> for DFloating
Source§fn shr_assign(&mut self, other: &u32)
fn shr_assign(&mut self, other: &u32)
>>= operation. Read moreSource§impl ShrAssign<u32> for DFloating
impl ShrAssign<u32> for DFloating
Source§fn shr_assign(&mut self, other: u32)
fn shr_assign(&mut self, other: u32)
>>= operation. Read moreSource§impl SubAssign<&DFloating> for DFloating
impl SubAssign<&DFloating> for DFloating
Source§fn sub_assign(&mut self, other: &DFloating)
fn sub_assign(&mut self, other: &DFloating)
-= operation. Read moreSource§impl SubAssign for DFloating
impl SubAssign for DFloating
Source§fn sub_assign(&mut self, other: DFloating)
fn sub_assign(&mut self, other: DFloating)
-= operation. Read more