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
sourceimpl<T: Clone + PrimitiveFloat> Clone for NiceFloat<T>
impl<T: Clone + PrimitiveFloat> Clone for NiceFloat<T>
sourceimpl<T: PrimitiveFloat> Debug for NiceFloat<T>
impl<T: PrimitiveFloat> Debug for NiceFloat<T>
sourcefn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats a NiceFloat
as a string.
This is identical to the Display::fmt
implementation.
sourceimpl<T: Default + PrimitiveFloat> Default for NiceFloat<T>
impl<T: Default + PrimitiveFloat> Default for NiceFloat<T>
sourceimpl<T: PrimitiveFloat> Display for NiceFloat<T>
impl<T: PrimitiveFloat> Display for NiceFloat<T>
sourcefn 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::float::NiceFloat;
assert_eq!(NiceFloat(0.0).to_string(), "0.0");
assert_eq!(NiceFloat(-0.0).to_string(), "-0.0");
assert_eq!(NiceFloat(f32::POSITIVE_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"
);
sourceimpl<T: PrimitiveFloat> FromStr for NiceFloat<T>
impl<T: PrimitiveFloat> FromStr for NiceFloat<T>
sourcefn 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));
sourceimpl<T: PrimitiveFloat> Hash for NiceFloat<T>
impl<T: PrimitiveFloat> Hash for NiceFloat<T>
sourcefn hash<H: Hasher>(&self, state: &mut H)
fn hash<H: Hasher>(&self, state: &mut H)
Computes a hash of a NiceFloat
.
The hash is compatible with NiceFloat
equality: all NaN
s hash to the same value.
Worst-case complexity
Constant time and additional memory.
sourceimpl<T: PrimitiveFloat> Ord for NiceFloat<T>
impl<T: PrimitiveFloat> Ord for NiceFloat<T>
sourcefn 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 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::basic::floats::PrimitiveFloat;
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::POSITIVE_INFINITY) > NiceFloat(f32::NAN));
assert!(NiceFloat(f32::NAN) < NiceFloat(1.0));
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<T: PrimitiveFloat> PartialEq<NiceFloat<T>> for NiceFloat<T>
impl<T: PrimitiveFloat> PartialEq<NiceFloat<T>> for NiceFloat<T>
sourcefn 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 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_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));
sourceimpl<T: PrimitiveFloat> PartialOrd<NiceFloat<T>> for NiceFloat<T>
impl<T: PrimitiveFloat> PartialOrd<NiceFloat<T>> for NiceFloat<T>
sourcefn 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.
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl TryFrom<NiceFloat<f32>> for i128
impl TryFrom<NiceFloat<f32>> for i128
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for i16
impl TryFrom<NiceFloat<f32>> for i16
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for i32
impl TryFrom<NiceFloat<f32>> for i32
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for i64
impl TryFrom<NiceFloat<f32>> for i64
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for i8
impl TryFrom<NiceFloat<f32>> for i8
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for isize
impl TryFrom<NiceFloat<f32>> for isize
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for u128
impl TryFrom<NiceFloat<f32>> for u128
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for u16
impl TryFrom<NiceFloat<f32>> for u16
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for u32
impl TryFrom<NiceFloat<f32>> for u32
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for u64
impl TryFrom<NiceFloat<f32>> for u64
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for u8
impl TryFrom<NiceFloat<f32>> for u8
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f32>> for usize
impl TryFrom<NiceFloat<f32>> for usize
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for i128
impl TryFrom<NiceFloat<f64>> for i128
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for i16
impl TryFrom<NiceFloat<f64>> for i16
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for i32
impl TryFrom<NiceFloat<f64>> for i32
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for i64
impl TryFrom<NiceFloat<f64>> for i64
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for i8
impl TryFrom<NiceFloat<f64>> for i8
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for isize
impl TryFrom<NiceFloat<f64>> for isize
sourcefn 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.
type Error = SignedFromFloatError
type Error = SignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for u128
impl TryFrom<NiceFloat<f64>> for u128
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for u16
impl TryFrom<NiceFloat<f64>> for u16
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for u32
impl TryFrom<NiceFloat<f64>> for u32
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for u64
impl TryFrom<NiceFloat<f64>> for u64
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for u8
impl TryFrom<NiceFloat<f64>> for u8
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<NiceFloat<f64>> for usize
impl TryFrom<NiceFloat<f64>> for usize
sourcefn 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.
type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
sourceimpl TryFrom<i128> for NiceFloat<f32>
impl TryFrom<i128> for NiceFloat<f32>
sourcefn try_from(value: i128) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: i128) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i128> for NiceFloat<f64>
impl TryFrom<i128> for NiceFloat<f64>
sourcefn try_from(value: i128) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: i128) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i16> for NiceFloat<f32>
impl TryFrom<i16> for NiceFloat<f32>
sourcefn try_from(value: i16) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: i16) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i16> for NiceFloat<f64>
impl TryFrom<i16> for NiceFloat<f64>
sourcefn try_from(value: i16) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: i16) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i32> for NiceFloat<f32>
impl TryFrom<i32> for NiceFloat<f32>
sourcefn try_from(value: i32) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: i32) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i32> for NiceFloat<f64>
impl TryFrom<i32> for NiceFloat<f64>
sourcefn try_from(value: i32) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: i32) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i64> for NiceFloat<f32>
impl TryFrom<i64> for NiceFloat<f32>
sourcefn try_from(value: i64) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: i64) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i64> for NiceFloat<f64>
impl TryFrom<i64> for NiceFloat<f64>
sourcefn try_from(value: i64) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: i64) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i8> for NiceFloat<f32>
impl TryFrom<i8> for NiceFloat<f32>
sourcefn try_from(value: i8) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: i8) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<i8> for NiceFloat<f64>
impl TryFrom<i8> for NiceFloat<f64>
sourcefn try_from(value: i8) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: i8) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<isize> for NiceFloat<f32>
impl TryFrom<isize> for NiceFloat<f32>
sourcefn try_from(value: isize) -> Result<NiceFloat<f32>, Self::Error>
fn try_from(value: isize) -> Result<NiceFloat<f32>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<isize> for NiceFloat<f64>
impl TryFrom<isize> for NiceFloat<f64>
sourcefn try_from(value: isize) -> Result<NiceFloat<f64>, Self::Error>
fn try_from(value: isize) -> Result<NiceFloat<f64>, Self::Error>
Converts a value of a signed type to a value of a floating point type, returning an error if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
type Error = PrimitiveFloatFromSignedError
type Error = PrimitiveFloatFromSignedError
sourceimpl TryFrom<u128> for NiceFloat<f32>
impl TryFrom<u128> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u128> for NiceFloat<f64>
impl TryFrom<u128> for NiceFloat<f64>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u16> for NiceFloat<f32>
impl TryFrom<u16> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u16> for NiceFloat<f64>
impl TryFrom<u16> for NiceFloat<f64>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u32> for NiceFloat<f32>
impl TryFrom<u32> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u32> for NiceFloat<f64>
impl TryFrom<u32> for NiceFloat<f64>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u64> for NiceFloat<f32>
impl TryFrom<u64> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u64> for NiceFloat<f64>
impl TryFrom<u64> for NiceFloat<f64>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u8> for NiceFloat<f32>
impl TryFrom<u8> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<u8> for NiceFloat<f64>
impl TryFrom<u8> for NiceFloat<f64>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<usize> for NiceFloat<f32>
impl TryFrom<usize> for NiceFloat<f32>
sourcefn 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.
type Error = PrimitiveFloatFromUnsignedError
type Error = PrimitiveFloatFromUnsignedError
sourceimpl TryFrom<usize> for NiceFloat<f64>
impl TryFrom<usize> for NiceFloat<f64>
sourcefn 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.