Struct malachite_base::num::float::NiceFloat
source · pub struct NiceFloat<T: PrimitiveFloat>(pub T);
Expand description
NiceFloat
is a wrapper around primitive float types that provides nicer Eq
, Ord
,
Hash
, Display
, and FromStr
instances.
In most languages, floats behave weirdly due to the IEEE 754 standard. The NiceFloat
type
ignores the standard in favor of more intuitive behavior.
- Using
NiceFloat
,NaN
s are equal to themselves. There is a single, uniqueNaN
; there’s no concept of signallingNaN
s. Positive and negative zero are two distinct values, not equal to each other. - The
NiceFloat
hash respects this equality. NiceFloat
has a total order. These are the classes of floats, in ascending order:- Negative infinity
- Negative nonzero finite floats
- Negative zero
- NaN
- Positive zero
- Positive nonzero finite floats
- Positive infinity
NiceFloat
uses a differentDisplay
implementation than floats do by default in Rust. For example, Rust will formatf32::MIN_POSITIVE_SUBNORMAL
as something with many zeros, butNiceFloat(f32::MIN_POSITIVE_SUBNORMAL)
just formats it as"1.0e-45"
. The conversion function uses David Tolnay’sryu
crate, with a few modifications:- All finite floats have a decimal point. For example, Ryu by itself would convert
f32::MIN_POSITIVE_SUBNORMAL
to"1e-45"
. - Positive infinity, negative infinity, and NaN are converted to the strings
"Infinity"
,"-Infinity"
, and “NaN
”, respectively.
- All finite floats have a decimal point. For example, Ryu by itself would convert
FromStr
accepts these strings.
Tuple Fields§
§0: T
Trait Implementations§
source§impl<T: PrimitiveFloat> Debug for NiceFloat<T>
impl<T: PrimitiveFloat> Debug for NiceFloat<T>
source§impl<T: PrimitiveFloat> Display for NiceFloat<T>
impl<T: PrimitiveFloat> Display for NiceFloat<T>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats a NiceFloat
as a string.
NiceFloat
uses a different Display
implementation than floats do by default in Rust.
For example, Rust will convert f32::MIN_POSITIVE_SUBNORMAL
to something with many zeros,
but NiceFloat(f32::MIN_POSITIVE_SUBNORMAL)
just converts to "1.0e-45"
. The conversion
function uses David Tolnay’s ryu
crate, with a few
modifications:
- All finite floats have a decimal point. For example, Ryu by itself would convert
f32::MIN_POSITIVE_SUBNORMAL
to"1e-45"
. - Positive infinity, negative infinity, and NaN are converted to the strings
"Infinity"
,"-Infinity"
, and “NaN
”, respectively.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::float::NiceFloat;
assert_eq!(NiceFloat(0.0).to_string(), "0.0");
assert_eq!(NiceFloat(-0.0).to_string(), "-0.0");
assert_eq!(NiceFloat(f32::INFINITY).to_string(), "Infinity");
assert_eq!(NiceFloat(f32::NEGATIVE_INFINITY).to_string(), "-Infinity");
assert_eq!(NiceFloat(f32::NAN).to_string(), "NaN");
assert_eq!(NiceFloat(1.0).to_string(), "1.0");
assert_eq!(NiceFloat(-1.0).to_string(), "-1.0");
assert_eq!(
NiceFloat(f32::MIN_POSITIVE_SUBNORMAL).to_string(),
"1.0e-45"
);
assert_eq!(
NiceFloat(std::f64::consts::E).to_string(),
"2.718281828459045"
);
assert_eq!(
NiceFloat(std::f64::consts::PI).to_string(),
"3.141592653589793"
);
source§impl<T: PrimitiveFloat> FromStr for NiceFloat<T>
impl<T: PrimitiveFloat> FromStr for NiceFloat<T>
source§fn from_str(src: &str) -> Result<NiceFloat<T>, <T as FromStr>::Err>
fn from_str(src: &str) -> Result<NiceFloat<T>, <T as FromStr>::Err>
Converts a &str
to a NiceFloat
.
If the &str
does not represent a valid NiceFloat
, an Err
is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ = src.len()
.
§Examples
use malachite_base::num::float::NiceFloat;
use std::str::FromStr;
assert_eq!(NiceFloat::from_str("NaN").unwrap(), NiceFloat(f32::NAN));
assert_eq!(NiceFloat::from_str("-0.00").unwrap(), NiceFloat(-0.0f64));
assert_eq!(NiceFloat::from_str(".123").unwrap(), NiceFloat(0.123f32));
source§impl<T: PrimitiveFloat> Hash for NiceFloat<T>
impl<T: PrimitiveFloat> Hash for NiceFloat<T>
source§impl<T: PrimitiveFloat> Ord for NiceFloat<T>
impl<T: PrimitiveFloat> Ord for NiceFloat<T>
source§fn cmp(&self, other: &NiceFloat<T>) -> Ordering
fn cmp(&self, other: &NiceFloat<T>) -> Ordering
Compares two NiceFloat
s.
This implementation ignores the IEEE 754 standard in favor of a comparison operation that
respects the expected properties of antisymmetry, reflexivity, and transitivity. NiceFloat
has a total order. These are the classes of floats, in ascending order:
- Negative infinity
- Negative nonzero finite floats
- Negative zero
- NaN
- Positive zero
- Positive nonzero finite floats
- Positive infinity
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::float::NiceFloat;
assert!(NiceFloat(0.0) > NiceFloat(-0.0));
assert!(NiceFloat(f32::NAN) < NiceFloat(0.0));
assert!(NiceFloat(f32::NAN) > NiceFloat(-0.0));
assert!(NiceFloat(f32::INFINITY) > NiceFloat(f32::NAN));
assert!(NiceFloat(f32::NAN) < NiceFloat(1.0));
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T: PrimitiveFloat> PartialEq for NiceFloat<T>
impl<T: PrimitiveFloat> PartialEq for NiceFloat<T>
source§fn eq(&self, other: &NiceFloat<T>) -> bool
fn eq(&self, other: &NiceFloat<T>) -> bool
Compares two NiceFloat
s for equality.
This implementation ignores the IEEE 754 standard in favor of an equality operation that
respects the expected properties of symmetry, reflexivity, and transitivity. Using
NiceFloat
, NaN
s are equal to themselves. There is a single, unique NaN
; there’s no
concept of signalling NaN
s. Positive and negative zero are two distinct values, not equal
to each other.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::float::NiceFloat;
assert_eq!(NiceFloat(0.0), NiceFloat(0.0));
assert_eq!(NiceFloat(f32::NAN), NiceFloat(f32::NAN));
assert_ne!(NiceFloat(f32::NAN), NiceFloat(0.0));
assert_ne!(NiceFloat(0.0), NiceFloat(-0.0));
assert_eq!(NiceFloat(1.0), NiceFloat(1.0));
source§impl<T: PrimitiveFloat> PartialOrd for NiceFloat<T>
impl<T: PrimitiveFloat> PartialOrd for NiceFloat<T>
source§fn partial_cmp(&self, other: &NiceFloat<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &NiceFloat<T>) -> Option<Ordering>
Compares a NiceFloat
to another NiceFloat
.
See the documentation for the Ord
implementation.
source§impl TryFrom<NiceFloat<f32>> for i128
impl TryFrom<NiceFloat<f32>> for i128
source§fn try_from(value: NiceFloat<f32>) -> Result<i128, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<i128, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for i16
impl TryFrom<NiceFloat<f32>> for i16
source§fn try_from(value: NiceFloat<f32>) -> Result<i16, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<i16, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for i32
impl TryFrom<NiceFloat<f32>> for i32
source§fn try_from(value: NiceFloat<f32>) -> Result<i32, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<i32, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for i64
impl TryFrom<NiceFloat<f32>> for i64
source§fn try_from(value: NiceFloat<f32>) -> Result<i64, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<i64, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for i8
impl TryFrom<NiceFloat<f32>> for i8
source§fn try_from(value: NiceFloat<f32>) -> Result<i8, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<i8, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for isize
impl TryFrom<NiceFloat<f32>> for isize
source§fn try_from(value: NiceFloat<f32>) -> Result<isize, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<isize, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for u128
impl TryFrom<NiceFloat<f32>> for u128
source§fn try_from(value: NiceFloat<f32>) -> Result<u128, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<u128, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for u16
impl TryFrom<NiceFloat<f32>> for u16
source§fn try_from(value: NiceFloat<f32>) -> Result<u16, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<u16, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for u32
impl TryFrom<NiceFloat<f32>> for u32
source§fn try_from(value: NiceFloat<f32>) -> Result<u32, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<u32, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for u64
impl TryFrom<NiceFloat<f32>> for u64
source§fn try_from(value: NiceFloat<f32>) -> Result<u64, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<u64, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for u8
impl TryFrom<NiceFloat<f32>> for u8
source§fn try_from(value: NiceFloat<f32>) -> Result<u8, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<u8, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f32>> for usize
impl TryFrom<NiceFloat<f32>> for usize
source§fn try_from(value: NiceFloat<f32>) -> Result<usize, Self::Error>
fn try_from(value: NiceFloat<f32>) -> Result<usize, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for i128
impl TryFrom<NiceFloat<f64>> for i128
source§fn try_from(value: NiceFloat<f64>) -> Result<i128, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<i128, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for i16
impl TryFrom<NiceFloat<f64>> for i16
source§fn try_from(value: NiceFloat<f64>) -> Result<i16, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<i16, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for i32
impl TryFrom<NiceFloat<f64>> for i32
source§fn try_from(value: NiceFloat<f64>) -> Result<i32, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<i32, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for i64
impl TryFrom<NiceFloat<f64>> for i64
source§fn try_from(value: NiceFloat<f64>) -> Result<i64, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<i64, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for i8
impl TryFrom<NiceFloat<f64>> for i8
source§fn try_from(value: NiceFloat<f64>) -> Result<i8, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<i8, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for isize
impl TryFrom<NiceFloat<f64>> for isize
source§fn try_from(value: NiceFloat<f64>) -> Result<isize, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<isize, Self::Error>
Converts a value of a floating point type to a value of a signed type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for u128
impl TryFrom<NiceFloat<f64>> for u128
source§fn try_from(value: NiceFloat<f64>) -> Result<u128, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<u128, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for u16
impl TryFrom<NiceFloat<f64>> for u16
source§fn try_from(value: NiceFloat<f64>) -> Result<u16, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<u16, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for u32
impl TryFrom<NiceFloat<f64>> for u32
source§fn try_from(value: NiceFloat<f64>) -> Result<u32, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<u32, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for u64
impl TryFrom<NiceFloat<f64>> for u64
source§fn try_from(value: NiceFloat<f64>) -> Result<u64, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<u64, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for u8
impl TryFrom<NiceFloat<f64>> for u8
source§fn try_from(value: NiceFloat<f64>) -> Result<u8, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<u8, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<NiceFloat<f64>> for usize
impl TryFrom<NiceFloat<f64>> for usize
source§fn try_from(value: NiceFloat<f64>) -> Result<usize, Self::Error>
fn try_from(value: NiceFloat<f64>) -> Result<usize, Self::Error>
Converts a value of a floating point type to a value of an unsigned type, returning an error if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
source§impl TryFrom<i128> for NiceFloat<f32>
impl TryFrom<i128> for NiceFloat<f32>
source§impl TryFrom<i128> for NiceFloat<f64>
impl TryFrom<i128> for NiceFloat<f64>
source§impl TryFrom<i16> for NiceFloat<f32>
impl TryFrom<i16> for NiceFloat<f32>
source§impl TryFrom<i16> for NiceFloat<f64>
impl TryFrom<i16> for NiceFloat<f64>
source§impl TryFrom<i32> for NiceFloat<f32>
impl TryFrom<i32> for NiceFloat<f32>
source§impl TryFrom<i32> for NiceFloat<f64>
impl TryFrom<i32> for NiceFloat<f64>
source§impl TryFrom<i64> for NiceFloat<f32>
impl TryFrom<i64> for NiceFloat<f32>
source§impl TryFrom<i64> for NiceFloat<f64>
impl TryFrom<i64> for NiceFloat<f64>
source§impl TryFrom<i8> for NiceFloat<f32>
impl TryFrom<i8> for NiceFloat<f32>
source§impl TryFrom<i8> for NiceFloat<f64>
impl TryFrom<i8> for NiceFloat<f64>
source§impl TryFrom<isize> for NiceFloat<f32>
impl TryFrom<isize> for NiceFloat<f32>
source§impl TryFrom<isize> for NiceFloat<f64>
impl TryFrom<isize> for NiceFloat<f64>
source§impl TryFrom<u128> for NiceFloat<f32>
impl TryFrom<u128> for NiceFloat<f32>
source§fn try_from(value: u128) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: u128) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u128> for NiceFloat<f64>
impl TryFrom<u128> for NiceFloat<f64>
source§fn try_from(value: u128) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: u128) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u16> for NiceFloat<f32>
impl TryFrom<u16> for NiceFloat<f32>
source§fn try_from(value: u16) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: u16) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u16> for NiceFloat<f64>
impl TryFrom<u16> for NiceFloat<f64>
source§fn try_from(value: u16) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: u16) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u32> for NiceFloat<f32>
impl TryFrom<u32> for NiceFloat<f32>
source§fn try_from(value: u32) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: u32) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u32> for NiceFloat<f64>
impl TryFrom<u32> for NiceFloat<f64>
source§fn try_from(value: u32) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: u32) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u64> for NiceFloat<f32>
impl TryFrom<u64> for NiceFloat<f32>
source§fn try_from(value: u64) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: u64) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u64> for NiceFloat<f64>
impl TryFrom<u64> for NiceFloat<f64>
source§fn try_from(value: u64) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: u64) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u8> for NiceFloat<f32>
impl TryFrom<u8> for NiceFloat<f32>
source§fn try_from(value: u8) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: u8) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<u8> for NiceFloat<f64>
impl TryFrom<u8> for NiceFloat<f64>
source§fn try_from(value: u8) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: u8) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<usize> for NiceFloat<f32>
impl TryFrom<usize> for NiceFloat<f32>
source§fn try_from(value: usize) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: usize) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
source§impl TryFrom<usize> for NiceFloat<f64>
impl TryFrom<usize> for NiceFloat<f64>
source§fn try_from(value: usize) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: usize) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of an unsigned type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
impl<T: Copy + PrimitiveFloat> Copy for NiceFloat<T>
impl<T: PrimitiveFloat> Eq for NiceFloat<T>
Auto Trait Implementations§
impl<T> Freeze for NiceFloat<T>where
T: Freeze,
impl<T> RefUnwindSafe for NiceFloat<T>
impl<T> Send for NiceFloat<T>where
T: Send,
impl<T> Sync for NiceFloat<T>where
T: Sync,
impl<T> Unpin for NiceFloat<T>where
T: Unpin,
impl<T> UnwindSafe for NiceFloat<T>where
T: UnwindSafe,
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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