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, NaNs are equal to themselves. There is a single, unique NaN; there’s no concept of signalling NaNs. 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 different Display implementation than floats do by default in Rust. For example, Rust will format f32::MIN_POSITIVE_SUBNORMAL as something with many zeros, but NiceFloat(f32::MIN_POSITIVE_SUBNORMAL) just formats it as "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.
  • FromStr accepts these strings.

Tuple Fields§

§0: T

Trait Implementations§

source§

impl<T: Clone + PrimitiveFloat> Clone for NiceFloat<T>

source§

fn clone(&self) -> NiceFloat<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: PrimitiveFloat> Debug for NiceFloat<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats a NiceFloat as a string.

This is identical to the Display::fmt implementation.

source§

impl<T: Default + PrimitiveFloat> Default for NiceFloat<T>

source§

fn default() -> NiceFloat<T>

Returns the “default value” for a type. Read more
source§

impl<T: PrimitiveFloat> Display for NiceFloat<T>

source§

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>

source§

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));
§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
source§

impl<T: PrimitiveFloat> Hash for NiceFloat<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Computes a hash of a NiceFloat.

The hash is compatible with NiceFloat equality: all NaNs hash to the same value.

§Worst-case complexity

Constant time and additional memory.

1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PrimitiveFloat> Ord for NiceFloat<T>

source§

fn cmp(&self, other: &NiceFloat<T>) -> Ordering

Compares two NiceFloats.

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::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::INFINITY) > NiceFloat(f32::NAN));
assert!(NiceFloat(f32::NAN) < NiceFloat(1.0));
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PrimitiveFloat> PartialEq for NiceFloat<T>

source§

fn eq(&self, other: &NiceFloat<T>) -> bool

Compares two NiceFloats 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, NaNs are equal to themselves. There is a single, unique NaN; there’s no concept of signalling NaNs. 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));
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PrimitiveFloat> PartialOrd for NiceFloat<T>

source§

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 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<NiceFloat<f32>> for i128

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for i16

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for i32

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for i64

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for i8

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for isize

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for u128

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for u16

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for u32

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for u64

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for u8

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f32>> for usize

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for i128

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for i16

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for i32

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for i64

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for i8

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for isize

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for u128

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for u16

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for u32

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for u64

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for u8

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<NiceFloat<f64>> for usize

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i128> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i128> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i16> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i16> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i32> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i32> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i64> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i64> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i8> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<i8> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<isize> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<isize> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u128> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u128> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u16> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u16> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u32> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u32> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u64> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u64> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u8> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<u8> for NiceFloat<f64>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<usize> for NiceFloat<f32>

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<usize> for NiceFloat<f64>

source§

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.

§

type Error = PrimitiveFloatFromUnsignedError

The type returned in the event of a conversion error.
source§

impl<T: Copy + PrimitiveFloat> Copy for NiceFloat<T>

source§

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>
where T: RefUnwindSafe,

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

source§

fn exact_from(value: T) -> U

source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

source§

fn exact_into(self) -> U

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

source§

impl<T> ToDebugString for T
where T: Debug,

source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

source§

fn wrapping_into(self) -> U