Struct malachite_float::Float

source ·
pub struct Float(/* private fields */);
Expand description

A floating-point number.

Floats are currently experimental. They are missing many important functions. However, the functions that are currently implemented are thoroughly tested and documented, with the exception of string conversion functions. The current string conversions are incomplete and will be changed in the future to match MPFR’s behavior.

Floats are similar to the primitive floats defined by the IEEE 754 standard. They include NaN, positive and negative infinity, and positive and negative zero. There is only one NaN; there is no concept of a NaN payload.

All the finite Floats are dyadic rationals (rational numbers whose denominator is a power of 2). A finite Float consists of several fields:

  • a sign, which denotes whether the Float is positive or negative;
  • a significand, which is a Natural number whose value is equal to the Float’s absolute value multiplied by a power of 2;
  • an exponent, which is one more than the floor of the base-2 logarithm of the Float’s absolute value;
  • and finally, a precision, which is greater than zero and indicates the number of significant bits. It is common to think of a Float as an approximation to some real number, and the precision indicates how good the approximation is intended to be.

Floats inherit some odd behavior from the IEEE 754 standard regarding comparison. A NaN is not equal to any Float, including itself. Positive and negative zero compare as equal, despite being two distinct values. Additionally, (and this is not IEEE 754’s fault), Floats with different precisions compare as equal if they represent the same numeric value.

In many cases, the above behavior is unsatisfactory, so the ComparableFloat and ComparableFloat wrappers are provided. See their documentation for a description of their comparison behavior.

In documentation, we will use the ‘$=$’ sign to mean that two Floats are identical, writing things like $-\text{NaN}=\text{NaN}$ and $-(0.0) = -0.0$.

The Float type is designed to be very similar to the mpfr_t type in MPFR, and all Malachite functions produce exactly the same result as their counterparts in MPFR, unless otherwise noted.

Here are the structural difference between Float and mpfr_t:

  • Float can only represent a single NaN value, with no sign or payload.
  • Only finite, nonzero Floats have a significand, precision, and exponent. For other Floats, these concepts are undefined. In particular, unlike mpfr_t zeros, Float zeros do not have a precision.
  • The types of mpfr_t components are configuration- and platform-dependent. The types of Float components are platform-independent, although the Limb type is configuration-dependent: it is u64 by default, but may be changed to u32 using the --32_bit_limbs compiler flag. The type of the exponent is always i64 and the type of the precision is always u64. The Limb type only affects functions that extract the raw significand. All other functions have the same behavior when compiled with either type.

Floats whose precision is 64 bits or less can be represented without any memory allocation. (Unless Malachite is compiled with 32_bit_limbs, in which case the limit is 32).

Implementations§

source§

impl Float

source

pub fn abs_negative_zero(self) -> Float

If self is negative zero, returns positive zero; otherwise, returns self, taking self by value.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(
    ComparableFloat(Float::NAN.abs_negative_zero()),
    ComparableFloat(Float::NAN)
);
assert_eq!(Float::INFINITY.abs_negative_zero(), Float::INFINITY);
assert_eq!(Float::NEGATIVE_INFINITY.abs_negative_zero(), Float::NEGATIVE_INFINITY);
assert_eq!(
    ComparableFloat(Float::ZERO.abs_negative_zero()),
    ComparableFloat(Float::ZERO)
);
assert_eq!(
    ComparableFloat(Float::NEGATIVE_ZERO.abs_negative_zero()),
    ComparableFloat(Float::ZERO)
);
assert_eq!(Float::ONE.abs_negative_zero(), Float::ONE);
assert_eq!(Float::NEGATIVE_ONE.abs_negative_zero(), Float::NEGATIVE_ONE);
source

pub fn abs_negative_zero_ref(&self) -> Float

If self is negative zero, returns positive zero; otherwise, returns self, taking self by reference.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(
    ComparableFloat(Float::NAN.abs_negative_zero_ref()),
    ComparableFloat(Float::NAN)
);
assert_eq!(Float::INFINITY.abs_negative_zero_ref(), Float::INFINITY);
assert_eq!(Float::NEGATIVE_INFINITY.abs_negative_zero_ref(), Float::NEGATIVE_INFINITY);
assert_eq!(
    ComparableFloat(Float::ZERO.abs_negative_zero_ref()),
    ComparableFloat(Float::ZERO)
);
assert_eq!(
    ComparableFloat(Float::NEGATIVE_ZERO.abs_negative_zero_ref()),
    ComparableFloat(Float::ZERO)
);
assert_eq!(Float::ONE.abs_negative_zero_ref(), Float::ONE);
assert_eq!(Float::NEGATIVE_ONE.abs_negative_zero_ref(), Float::NEGATIVE_ONE);
source

pub fn abs_negative_zero_assign(&mut self)

If self is negative zero, replaces it with positive zero; otherwise, does nothing.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

let mut x = Float::NAN;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));

let mut x = Float::INFINITY;
x.abs_negative_zero_assign();
assert_eq!(x, Float::INFINITY);

let mut x = Float::NEGATIVE_INFINITY;
x.abs_negative_zero_assign();
assert_eq!(x, Float::NEGATIVE_INFINITY);

let mut x = Float::ZERO;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));

let mut x = Float::NEGATIVE_ZERO;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));

let mut x = Float::ONE;
x.abs_negative_zero_assign();
assert_eq!(x, Float::ONE);

let mut x = Float::NEGATIVE_ONE;
x.abs_negative_zero_assign();
assert_eq!(x, Float::NEGATIVE_ONE);
source§

impl Float

source

pub fn power_of_2_prec(pow: i64, prec: u64) -> Float

Raises 2 to an integer power, returning a Float with the specified precision.

If you need a Float with precision 1, then the PowerOfTwo implementation may be used instead.

$f(k) = 2^k$,

and the result has precision prec.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples
use malachite_float::Float;

assert_eq!(Float::power_of_2_prec(0, 1).to_string(), "1.0");
assert_eq!(Float::power_of_2_prec(0, 10).to_string(), "1.0");
assert_eq!(Float::power_of_2_prec(0, 100).to_string(), "1.0");

assert_eq!(Float::power_of_2_prec(100, 1).to_string(), "1.0e30");
assert_eq!(Float::power_of_2_prec(100, 10).to_string(), "1.268e30");
assert_eq!(
    Float::power_of_2_prec(100, 100).to_string(),
    "1267650600228229401496703205376.0"
);

assert_eq!(Float::power_of_2_prec(-100, 1).to_string(), "8.0e-31");
assert_eq!(Float::power_of_2_prec(-100, 10).to_string(), "7.89e-31");
assert_eq!(
    Float::power_of_2_prec(-100, 100).to_string(),
    "7.88860905221011805411728565283e-31"
);
source§

impl Float

source

pub const fn is_nan(&self) -> bool

Determines whether a Float is NaN.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::Float;

assert_eq!(Float::NAN.is_nan(), true);
assert_eq!(Float::ONE.is_nan(), false);
source

pub const fn is_finite(&self) -> bool

Determines whether a Float is finite.

NaN is not finite.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, One};
use malachite_float::Float;

assert_eq!(Float::NAN.is_finite(), false);
assert_eq!(Float::INFINITY.is_finite(), false);
assert_eq!(Float::ONE.is_finite(), true);
source

pub const fn is_infinite(&self) -> bool

Determines whether a Float is infinite.

NaN is not infinite.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, One};
use malachite_float::Float;

assert_eq!(Float::NAN.is_infinite(), false);
assert_eq!(Float::INFINITY.is_infinite(), true);
assert_eq!(Float::ONE.is_infinite(), false);
source

pub const fn is_positive_zero(&self) -> bool

Determines whether a Float is positive zero.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.is_positive_zero(), false);
assert_eq!(Float::INFINITY.is_positive_zero(), false);
assert_eq!(Float::ONE.is_positive_zero(), false);
assert_eq!(Float::ZERO.is_positive_zero(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_positive_zero(), false);
source

pub const fn is_negative_zero(&self) -> bool

Determines whether a Float is negative zero.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.is_negative_zero(), false);
assert_eq!(Float::INFINITY.is_negative_zero(), false);
assert_eq!(Float::ONE.is_negative_zero(), false);
assert_eq!(Float::ZERO.is_negative_zero(), false);
assert_eq!(Float::NEGATIVE_ZERO.is_negative_zero(), true);
source

pub const fn is_zero(&self) -> bool

Determines whether a Float is zero (positive or negative).

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.is_zero(), false);
assert_eq!(Float::INFINITY.is_zero(), false);
assert_eq!(Float::ONE.is_zero(), false);
assert_eq!(Float::ZERO.is_zero(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_zero(), true);
source

pub const fn is_normal(&self) -> bool

Determines whether a Float is normal, that is, finite and nonzero.

There is no notion of subnormal Floats.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.is_normal(), false);
assert_eq!(Float::INFINITY.is_normal(), false);
assert_eq!(Float::ZERO.is_normal(), false);
assert_eq!(Float::NEGATIVE_ZERO.is_normal(), false);
assert_eq!(Float::ONE.is_normal(), true);
source

pub const fn is_sign_positive(&self) -> bool

Determines whether a Float’s sign is positive.

A NaN has no sign, so this function returns false when given a NaN.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::Float;

assert_eq!(Float::NAN.is_sign_positive(), false);
assert_eq!(Float::INFINITY.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_INFINITY.is_sign_positive(), false);
assert_eq!(Float::ZERO.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_sign_positive(), false);
assert_eq!(Float::ONE.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_ONE.is_sign_positive(), false);
source

pub const fn is_sign_negative(&self) -> bool

Determines whether a Float’s sign is negative.

A NaN has no sign, so this function returns false when given a NaN.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::Float;

assert_eq!(Float::NAN.is_sign_negative(), false);
assert_eq!(Float::INFINITY.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_INFINITY.is_sign_negative(), true);
assert_eq!(Float::ZERO.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_ZERO.is_sign_negative(), true);
assert_eq!(Float::ONE.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_ONE.is_sign_negative(), true);
source

pub const fn classify(&self) -> FpCategory

Classifies a Float into one of several categories.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::Float;
use std::num::FpCategory;

assert_eq!(Float::NAN.classify(), FpCategory::Nan);
assert_eq!(Float::INFINITY.classify(), FpCategory::Infinite);
assert_eq!(Float::NEGATIVE_INFINITY.classify(), FpCategory::Infinite);
assert_eq!(Float::ZERO.classify(), FpCategory::Zero);
assert_eq!(Float::NEGATIVE_ZERO.classify(), FpCategory::Zero);
assert_eq!(Float::ONE.classify(), FpCategory::Normal);
assert_eq!(Float::NEGATIVE_ONE.classify(), FpCategory::Normal);
source

pub fn into_non_nan(self) -> Option<Float>

Turns a NaN into a None and wraps any non-NaN Float with a Some. The Float is taken by value.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.into_non_nan(), None);
assert_eq!(Float::INFINITY.into_non_nan(), Some(Float::INFINITY));
assert_eq!(Float::ZERO.into_non_nan(), Some(Float::ZERO));
assert_eq!(Float::NEGATIVE_ZERO.into_non_nan(), Some(Float::NEGATIVE_ZERO));
assert_eq!(Float::ONE.into_non_nan(), Some(Float::ONE));
source

pub fn to_non_nan(&self) -> Option<Float>

Turns a NaN into a None and wraps any non-NaN Float with a Some. The Float is taken by reference.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.to_non_nan(), None);
assert_eq!(Float::INFINITY.to_non_nan(), Some(Float::INFINITY));
assert_eq!(Float::ZERO.to_non_nan(), Some(Float::ZERO));
assert_eq!(Float::NEGATIVE_ZERO.to_non_nan(), Some(Float::NEGATIVE_ZERO));
assert_eq!(Float::ONE.to_non_nan(), Some(Float::ONE));
source

pub fn into_finite(self) -> Option<Float>

Turns any Float that’s NaN or infinite into a None and wraps any finite Float with a Some. The Float is taken by value.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.into_finite(), None);
assert_eq!(Float::INFINITY.into_finite(), None);
assert_eq!(Float::ZERO.into_finite(), Some(Float::ZERO));
assert_eq!(Float::NEGATIVE_ZERO.into_finite(), Some(Float::NEGATIVE_ZERO));
assert_eq!(Float::ONE.into_finite(), Some(Float::ONE));
source

pub fn to_finite(&self) -> Option<Float>

Turns any Float that’s NaN or infinite into a None and wraps any finite Float with a Some. The Float is taken by reference.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;

assert_eq!(Float::NAN.to_finite(), None);
assert_eq!(Float::INFINITY.to_finite(), None);
assert_eq!(Float::ZERO.to_finite(), Some(Float::ZERO));
assert_eq!(Float::NEGATIVE_ZERO.to_finite(), Some(Float::NEGATIVE_ZERO));
assert_eq!(Float::ONE.to_finite(), Some(Float::ONE));
source§

impl Float

source

pub fn complexity(&self) -> u64

Determines a Float’s complexity. The complexity is defined as follows:

$$ f(\text{NaN}) = f(\pm\infty) = f(\pm 0.0) = 1, $$

and, if $x$ is finite and nonzero,

$$ f(x) = \max(|\lfloor \log_2 x\rfloor|, p), $$

where $p$ is the precision of $x$.

Informally, the complexity is proportional to the number of characters you would need to write the Float out without using exponents.

See also the Float implementation of SignificantBits.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::Float;

assert_eq!(Float::NAN.complexity(), 1);
assert_eq!(Float::ONE.complexity(), 1);
assert_eq!(Float::one_prec(100).complexity(), 100);
assert_eq!(Float::from(std::f64::consts::PI).complexity(), 53);
assert_eq!(Float::power_of_2(100u64).complexity(), 100);
assert_eq!(Float::power_of_2(-100i64).complexity(), 100);
source§

impl Float

source

pub fn one_prec(prec: u64) -> Float

Returns the number 1, with the given precision.

$$ f(p) = 1, $$

and the output has precision $p$.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is p.

Panics

Panics if p is zero.

Examples
use malachite_float::Float;

assert_eq!(Float::one_prec(1), 1);
assert_eq!(Float::one_prec(10), 1);
assert_eq!(Float::one_prec(100), 1);

assert_eq!(Float::one_prec(1).get_prec(), Some(1));
assert_eq!(Float::one_prec(10).get_prec(), Some(10));
assert_eq!(Float::one_prec(100).get_prec(), Some(100));
source

pub fn two_prec(prec: u64) -> Float

Returns the number 2, with the given precision.

$$ f(p) = 2, $$

and the output has precision $p$.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is p.

Panics

Panics if p is zero.

Examples
use malachite_float::Float;

assert_eq!(Float::two_prec(1), 2);
assert_eq!(Float::two_prec(10), 2);
assert_eq!(Float::two_prec(100), 2);

assert_eq!(Float::two_prec(1).get_prec(), Some(1));
assert_eq!(Float::two_prec(10).get_prec(), Some(10));
assert_eq!(Float::two_prec(100).get_prec(), Some(100));
source

pub fn negative_one_prec(prec: u64) -> Float

Returns the number $-1$, with the given precision.

$$ f(p) = -1, $$

and the output has precision $p$.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is p.

Panics

Panics if p is zero.

Examples
use malachite_float::Float;

assert_eq!(Float::negative_one_prec(1), -1);
assert_eq!(Float::negative_one_prec(10), -1);
assert_eq!(Float::negative_one_prec(100), -1);

assert_eq!(Float::negative_one_prec(1).get_prec(), Some(1));
assert_eq!(Float::negative_one_prec(10).get_prec(), Some(10));
assert_eq!(Float::negative_one_prec(100).get_prec(), Some(100));
source

pub fn one_half_prec(prec: u64) -> Float

Returns the number 0.5, with the given precision.

$$ f(p) = 0.5, $$

and the output has precision $p$.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is p.

Panics

Panics if p is zero.

Examples
use malachite_float::Float;

assert_eq!(Float::one_half_prec(1), 0.5);
assert_eq!(Float::one_half_prec(10), 0.5);
assert_eq!(Float::one_half_prec(100), 0.5);

assert_eq!(Float::one_half_prec(1).get_prec(), Some(1));
assert_eq!(Float::one_half_prec(10).get_prec(), Some(10));
assert_eq!(Float::one_half_prec(100).get_prec(), Some(100));
source§

impl Float

source

pub fn to_significand(&self) -> Option<Natural>

Gets the significand of a Float, taking the Float by value.

The significand is the smallest positive integer which is some power of 2 times the Float, and whose number of significant bits is a multiple of the limb width. If the Float is NaN, infinite, or zero, then None is returned.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.to_significand(), None);
assert_eq!(Float::INFINITY.to_significand(), None);
assert_eq!(Float::ZERO.to_significand(), None);

assert_eq!(Float::ONE.to_significand(), Some(Natural::power_of_2(63)));
assert_eq!(
    Float::from(std::f64::consts::PI).to_significand().unwrap(),
    14488038916154245120u64
);
source

pub fn into_significand(self) -> Option<Natural>

Gets the significand of a Float, taking the Float by reference.

The significand is the smallest positive integer which is some power of 2 times the Float, and whose number of significant bits is a multiple of the limb width. If the Float is NaN, infinite, or zero, then None is returned.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.into_significand(), None);
assert_eq!(Float::INFINITY.into_significand(), None);
assert_eq!(Float::ZERO.into_significand(), None);

assert_eq!(Float::ONE.into_significand(), Some(Natural::power_of_2(63)));
assert_eq!(
    Float::from(std::f64::consts::PI).into_significand().unwrap(),
    14488038916154245120u64
);
source

pub const fn significand_ref(&self) -> Option<&Natural>

Returns a reference to the significand of a Float.

The significand is the smallest positive integer which is some power of 2 times the Float, and whose number of significant bits is a multiple of the limb width. If the Float is NaN, infinite, or zero, then None is returned.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.significand_ref(), None);
assert_eq!(Float::INFINITY.significand_ref(), None);
assert_eq!(Float::ZERO.significand_ref(), None);

assert_eq!(*Float::ONE.significand_ref().unwrap(), Natural::power_of_2(63));
assert_eq!(
    *Float::from(std::f64::consts::PI).significand_ref().unwrap(),
    14488038916154245120u64
);
source

pub const fn get_exponent(&self) -> Option<i64>

Returns a Float’s exponent.

$$ f(\text{NaN}) = f(\pm\infty) = f(\pm 0.0) = \text{None}, $$

and, if $x$ is finite and nonzero,

$$ f(x) = \operatorname{Some}(\lfloor \log_2 x \rfloor + 1). $$

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.get_exponent(), None);
assert_eq!(Float::INFINITY.get_exponent(), None);
assert_eq!(Float::ZERO.get_exponent(), None);

assert_eq!(Float::ONE.get_exponent(), Some(1));
assert_eq!(Float::from(std::f64::consts::PI).get_exponent(), Some(2));
assert_eq!(Float::power_of_2(100u64).get_exponent(), Some(101));
assert_eq!(Float::power_of_2(-100i64).get_exponent(), Some(-99));
source

pub const fn get_prec(&self) -> Option<u64>

Returns a Float’s precision. The precision is a positive integer denoting how many of the Float’s bits are significant.

Only Floats that are finite and nonzero have a precision. For other Floats, None is returned.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.get_prec(), None);
assert_eq!(Float::INFINITY.get_prec(), None);
assert_eq!(Float::ZERO.get_prec(), None);

assert_eq!(Float::ONE.get_prec(), Some(1));
assert_eq!(Float::one_prec(100).get_prec(), Some(100));
assert_eq!(Float::from(std::f64::consts::PI).get_prec(), Some(53));
source

pub fn set_prec_round(&mut self, prec: u64, rm: RoundingMode) -> Ordering

Changes a Float’s precision. If the precision decreases, rounding may be necessary, and will use the provided RoundingMode.

Returns an Ordering, indicating whether the final value is less than, greater than, or equal to the original value.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Panics

Panics if prec is zero or if rm is RoundingMode::Exact but setting the desired precision requires rounding.

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_float::Float;
use std::cmp::Ordering;

let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));

let mut x = original_x.clone();
assert_eq!(x.set_prec_round(100, RoundingMode::Exact), Ordering::Equal);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));

let mut x = original_x.clone();
assert_eq!(x.set_prec_round(10, RoundingMode::Floor), Ordering::Less);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));

let mut x = original_x.clone();
assert_eq!(x.set_prec_round(10, RoundingMode::Ceiling), Ordering::Greater);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
source

pub fn set_prec(&mut self, p: u64) -> Ordering

Changes a Float’s precision. If the precision decreases, rounding may be necessary, and RoundingMode::Nearest will be used.

Returns an Ordering, indicating whether the final value is less than, greater than, or equal to the original value.

To use a different rounding mode, try Float::set_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_float::Float;
use std::cmp::Ordering;

let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));

let mut x = original_x.clone();
assert_eq!(x.set_prec(100), Ordering::Equal);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));

let mut x = original_x.clone();
assert_eq!(x.set_prec(10), Ordering::Greater);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
source§

impl Float

source

pub fn ulp(&self) -> Option<Float>

Gets a Float’s ulp (unit in last place, or unit of least precision).

If the Float is positive, its ulp is the distance to the next-largest Float with the same precision; if it is negative, the next-smallest. (This definition works even if the Float is the largest in its binade.)

If the Float is NaN, infinite, or zero, then None is returned.

$$ f(\text{NaN}) = f(\pm\infty) = f(\pm 0.0) = \text{None}, $$

and, if $x$ is finite and nonzero,

$$ f(x) = \operatorname{Some}(2^{\lfloor \log_2 x \rfloor-p+1}), $$ where $p$ is the precision of $x$.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeOne, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

assert_eq!(Float::NAN.ulp(), None);
assert_eq!(Float::INFINITY.ulp(), None);
assert_eq!(Float::ZERO.ulp(), None);

let s = Float::ONE.ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("1.0"));

let s = Float::one_prec(100).ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("2.0e-30"));

let s = Float::from(std::f64::consts::PI).ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("4.0e-16"));

let s = Float::power_of_2(100u64).ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("1.0e30"));

let s = Float::power_of_2(-100i64).ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("8.0e-31"));

let s = Float::NEGATIVE_ONE.ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("1.0"));
source

pub fn increment(&mut self)

Increments a Float by its ulp.

See Float::ulp for details. If the Float is equal to the negative of its ulp, it becomes negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is NaN, infinite, or zero.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeOne, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

let mut x = Float::ONE;
assert_eq!(x.to_string(), "1.0");
x.increment();
assert_eq!(x.to_string(), "2.0");

let mut x = Float::one_prec(100);
assert_eq!(x.to_string(), "1.0");
x.increment();
assert_eq!(x.to_string(), "1.000000000000000000000000000002");

let mut x = Float::from(std::f64::consts::PI);
assert_eq!(x.to_string(), "3.1415926535897931");
x.increment();
assert_eq!(x.to_string(), "3.1415926535897936");

let mut x = Float::power_of_2(100u64);
assert_eq!(x.to_string(), "1.0e30");
x.increment();
assert_eq!(x.to_string(), "3.0e30");

let mut x = Float::power_of_2(-100i64);
assert_eq!(x.to_string(), "8.0e-31");
x.increment();
assert_eq!(x.to_string(), "1.6e-30");

let mut x = Float::NEGATIVE_ONE;
assert_eq!(x.to_string(), "-1.0");
x.increment();
assert_eq!(x.to_string(), "-0.0");
source

pub fn decrement(&mut self)

Decrements a Float by its ulp.

See Float::ulp for details. If the Float is equal to its ulp, it becomes positive zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is NaN, infinite, or zero.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeOne, One, Zero};
use malachite_nz::natural::Natural;
use malachite_float::Float;

let mut x = Float::ONE;
assert_eq!(x.to_string(), "1.0");
x.decrement();
assert_eq!(x.to_string(), "0.0");

let mut x = Float::one_prec(100);
assert_eq!(x.to_string(), "1.0");
x.decrement();
assert_eq!(x.to_string(), "0.999999999999999999999999999998");

let mut x = Float::from(std::f64::consts::PI);
assert_eq!(x.to_string(), "3.1415926535897931");
x.decrement();
assert_eq!(x.to_string(), "3.1415926535897927");

let mut x = Float::power_of_2(100u64);
assert_eq!(x.to_string(), "1.0e30");
x.decrement();
assert_eq!(x.to_string(), "0.0");

let mut x = Float::power_of_2(-100i64);
assert_eq!(x.to_string(), "8.0e-31");
x.decrement();
assert_eq!(x.to_string(), "0.0");

let mut x = Float::NEGATIVE_ONE;
assert_eq!(x.to_string(), "-1.0");
x.decrement();
assert_eq!(x.to_string(), "-2.0");
source§

impl Float

source

pub fn from_integer_prec_round( x: Integer, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts an Integer to a Float, taking the Integer by value. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_integer_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering;

let (x, o) = Float::from_integer_prec_round(Integer::ZERO, 10, RoundingMode::Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round(
    Integer::from(123),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round(Integer::from(123), 4, RoundingMode::Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec_round(
    Integer::from(123),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_integer_prec_round(
    Integer::from(-123),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round(Integer::from(-123), 4, RoundingMode::Floor);
assert_eq!(x.to_string(), "-1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec_round(
    Integer::from(-123),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source

pub fn from_integer_prec(x: Integer, prec: u64) -> (Float, Ordering)

Converts an Integer to a Float, taking the Integer by value. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the Integer’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_integer_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering;

let (x, o) = Float::from_integer_prec(Integer::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec(Integer::from(123), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec(Integer::from(123), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec(Integer::from(-123), 20);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec(Integer::from(-123), 4);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source

pub fn from_integer_prec_round_ref( x: &Integer, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts an Integer to a Float, taking the Integer by reference. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_integer_prec_ref instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering;

let (x, o) = Float::from_integer_prec_round_ref(&Integer::ZERO, 10, RoundingMode::Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(123),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(123),
    4,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(123),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(-123),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(-123),
    4,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "-1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec_round_ref(
    &Integer::from(-123),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source

pub fn from_integer_prec_ref(x: &Integer, prec: u64) -> (Float, Ordering)

Converts an Integer to a Float, taking the Integer by reference. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the Integer’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_integer_prec_round_ref.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering;

let (x, o) = Float::from_integer_prec_ref(&Integer::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_ref(&Integer::from(123), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_ref(&Integer::from(123), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_integer_prec_ref(&Integer::from(-123), 20);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_integer_prec_ref(&Integer::from(-123), 4);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source§

impl Float

source

pub fn from_natural_prec_round( x: Natural, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts a Natural to a Float, taking the Natural by value. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_natural_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering;

let (x, o) = Float::from_natural_prec_round(Natural::ZERO, 10, RoundingMode::Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_round(
    Natural::from(123u32),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_round(Natural::from(123u32), 4, RoundingMode::Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_natural_prec_round(
    Natural::from(123u32),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source

pub fn from_natural_prec(x: Natural, prec: u64) -> (Float, Ordering)

Converts a Natural to a Float, taking the Natural by value. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the Natural’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_natural_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering;

let (x, o) = Float::from_natural_prec(Natural::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec(Natural::from(123u32), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec(Natural::from(123u32), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);
source

pub fn from_natural_prec_round_ref( x: &Natural, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts a Natural to a Float, taking the Natural by reference. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_natural_prec_ref instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering;

let (x, o) = Float::from_natural_prec_round_ref(&Natural::ZERO, 10, RoundingMode::Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_round_ref(
    &Natural::from(123u32),
    20,
    RoundingMode::Exact
);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_round_ref(
    &Natural::from(123u32),
    4,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_natural_prec_round_ref(
    &Natural::from(123u32),
    4,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Greater);
source

pub fn from_natural_prec_ref(x: &Natural, prec: u64) -> (Float, Ordering)

Converts a Natural to a Float, taking the Natural by reference. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the Natural’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_natural_prec_round_ref.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering;

let (x, o) = Float::from_natural_prec_ref(&Natural::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_ref(&Natural::from(123u32), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_natural_prec_ref(&Natural::from(123u32), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Ordering::Less);
source§

impl Float

source

pub fn from_primitive_float_prec_round<T: PrimitiveFloat>( x: T, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts a primitive float to a Float. If the Float is nonzero and finite, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

If you’re only using RoundingMode::Nearest, try using Float::from_primitive_float_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(prec, x.sci_exponent().abs()).

Examples

See here.

source

pub fn from_primitive_float_prec<T: PrimitiveFloat>( x: T, prec: u64 ) -> (Float, Ordering)

Converts a primitive float to a Float. If the Float is nonzero and finite, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_primitive_float_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(prec, x.sci_exponent().abs()).

Examples

See here.

source§

impl Float

source

pub fn from_unsigned_prec_round<T: PrimitiveUnsigned>( x: T, prec: u64, rm: RoundingMode ) -> (Float, Ordering)
where Natural: From<T>,

Converts a primitive unsigned integer to a Float. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_unsigned_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples

See here.

source

pub fn from_unsigned_prec<T: PrimitiveUnsigned>( x: T, prec: u64 ) -> (Float, Ordering)
where Natural: From<T>,

Converts an unsigned primitive integer to a Float. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the integer’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples

See here.

source

pub fn from_signed_prec_round<T: PrimitiveSigned>( x: T, prec: u64, rm: RoundingMode ) -> (Float, Ordering)
where Integer: From<T>,

Converts a primitive signed integer to a Float. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_signed_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples

See here.

source

pub fn from_signed_prec<T: PrimitiveSigned>( x: T, prec: u64 ) -> (Float, Ordering)
where Integer: From<T>,

Converts a signed primitive integer to a Float. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you want the Float’s precision to be equal to the integer’s number of significant bits, try just using Float::from instead.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is prec.

Examples

See here.

source§

impl Float

source

pub fn from_rational_prec_round( x: Rational, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts a Rational to a Float, taking the Rational by value. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_rational_prec instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering;

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(1, 3),
    10,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(1, 3),
    10,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(1, 3),
    10,
    RoundingMode::Nearest
);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "-0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round(
    Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Nearest
);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);
source

pub fn from_rational_prec(x: Rational, prec: u64) -> (Float, Ordering)

Converts a Rational to a Float, taking the Rational by value. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Rational is dyadic (its denominator is a power of 2), then you can convert it to a Float using try_from instead. The precision of the resulting Float will be the number of significant bits of the Rational’s numerator.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_rational_prec_round.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering;

let (x, o) = Float::from_rational_prec(Rational::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_rational_prec(Rational::from_signeds(1, 3), 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec(Rational::from_signeds(1, 3), 100);
assert_eq!(x.to_string(), "0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec(Rational::from_signeds(-1, 3), 10);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec(Rational::from_signeds(-1, 3), 100);
assert_eq!(x.to_string(), "-0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Ordering::Less);
source

pub fn from_rational_prec_round_ref( x: &Rational, prec: u64, rm: RoundingMode ) -> (Float, Ordering)

Converts a Rational to a Float, taking the Rational by reference. If the Float is nonzero, it has the specified precision. If rounding is needed, the specified rounding mode is used. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If you’re only using RoundingMode::Nearest, try using Float::from_rational_prec_ref instead.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering;

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(1, 3),
    10,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(1, 3),
    10,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(1, 3),
    10,
    RoundingMode::Nearest
);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Floor
);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Ceiling
);
assert_eq!(x.to_string(), "-0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_round_ref(
    &Rational::from_signeds(-1, 3),
    10,
    RoundingMode::Nearest
);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);
source

pub fn from_rational_prec_ref(x: &Rational, prec: u64) -> (Float, Ordering)

Converts a Rational to a Float, taking the Rational by reference. If the Float is nonzero, it has the specified precision. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Rational is dyadic (its denominator is a power of 2), then you can convert it to a Float using try_from instead. The precision of the resulting Float will be the number of significant bits of the Rational’s numerator.

Rounding may occur, in which case RoundingMode::Nearest is used by default. To specify a rounding mode as well as a precision, try Float::from_rational_prec_round_ref.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), prec).

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering;

let (x, o) = Float::from_rational_prec_ref(&Rational::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Ordering::Equal);

let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(1, 3), 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(1, 3), 100);
assert_eq!(x.to_string(), "0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Ordering::Greater);

let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(-1, 3), 10);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Ordering::Less);

let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(-1, 3), 100);
assert_eq!(x.to_string(), "-0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Ordering::Less);
source§

impl Float

source

pub fn sci_mantissa_and_exponent_round<T: PrimitiveFloat>( &self, rm: RoundingMode ) -> Option<(T, i64, Ordering)>

Returns a Float’s scientific mantissa and exponent, rounding according to the specified rounding mode. An Ordering is also returned, indicating whether the mantissa and exponent represent a value that is less than, equal to, or greater than the original value.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the provided rounding mode. If the rounding mode is Exact but the conversion is not exact, None is returned. $$ f(x, r) \approx \left (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor\right ). $$

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_base::num::float::NiceFloat;
use malachite_base::rounding_modes::RoundingMode;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering;

let test = |x: Float, rm: RoundingMode, out: Option<(f32, i64, Ordering)>| {
    assert_eq!(
        x.sci_mantissa_and_exponent_round(rm)
            .map(|(m, e, o)| (NiceFloat(m), e, o)),
        out.map(|(m, e, o)| (NiceFloat(m), e, o))
    );
};
test(Float::from(3u32), RoundingMode::Floor, Some((1.5, 1, Ordering::Equal)));
test(Float::from(3u32), RoundingMode::Down, Some((1.5, 1, Ordering::Equal)));
test(Float::from(3u32), RoundingMode::Ceiling, Some((1.5, 1, Ordering::Equal)));
test(Float::from(3u32), RoundingMode::Up, Some((1.5, 1, Ordering::Equal)));
test(Float::from(3u32), RoundingMode::Nearest, Some((1.5, 1, Ordering::Equal)));
test(Float::from(3u32), RoundingMode::Exact, Some((1.5, 1, Ordering::Equal)));

let x = Float::from(std::f64::consts::PI);
test(x.clone(), RoundingMode::Floor, Some((1.5707963, 1, Ordering::Less)));
test(x.clone(), RoundingMode::Down, Some((1.5707963, 1, Ordering::Less)));
test(x.clone(), RoundingMode::Ceiling, Some((1.5707964, 1, Ordering::Greater)));
test(x.clone(), RoundingMode::Up, Some((1.5707964, 1, Ordering::Greater)));
test(x.clone(), RoundingMode::Nearest, Some((1.5707964, 1, Ordering::Greater)));
test(x.clone(), RoundingMode::Exact, None);

test(
    Float::from(1000000000u32),
    RoundingMode::Nearest,
    Some((1.8626451, 29, Ordering::Equal)),
);
test(
    Float::from(Natural::from(10u32).pow(52)),
    RoundingMode::Nearest,
    Some((1.670478, 172, Ordering::Greater)),
);

test(Float::from(Natural::from(10u32).pow(52)), RoundingMode::Exact, None);

Trait Implementations§

source§

impl<'a> Abs for &'a Float

source§

fn abs(self) -> Float

Takes the absolute value of a Float, taking the Float by reference.

$$ f(x) = |x|. $$

Special cases:

  • $f(\text{NaN}) = \text{NaN}$
  • $f(\infty) = f(-\infty) = \infty$
  • $f(0.0) = f(-0.0) = 0.0$
Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(ComparableFloat((&Float::NAN).abs()), ComparableFloat(Float::NAN));
assert_eq!((&Float::INFINITY).abs(), Float::INFINITY);
assert_eq!((&Float::NEGATIVE_INFINITY).abs(), Float::INFINITY);
assert_eq!(ComparableFloat((&Float::ZERO).abs()), ComparableFloat(Float::ZERO));
assert_eq!(ComparableFloat((&Float::NEGATIVE_ZERO).abs()), ComparableFloat(Float::ZERO));
assert_eq!((&Float::ONE).abs(), Float::ONE);
assert_eq!((&Float::NEGATIVE_ONE).abs(), Float::ONE);
§

type Output = Float

source§

impl Abs for Float

source§

fn abs(self) -> Float

Takes the absolute value of a Float, taking the Float by value.

$$ f(x) = |x|. $$

Special cases:

  • $f(\text{NaN}) = \text{NaN}$
  • $f(\infty) = f(-\infty) = \infty$
  • $f(0.0) = f(-0.0) = 0.0$
Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(ComparableFloat(Float::NAN.abs()), ComparableFloat(Float::NAN));
assert_eq!(Float::INFINITY.abs(), Float::INFINITY);
assert_eq!(Float::NEGATIVE_INFINITY.abs(), Float::INFINITY);
assert_eq!(ComparableFloat(Float::ZERO.abs()), ComparableFloat(Float::ZERO));
assert_eq!(ComparableFloat(Float::NEGATIVE_ZERO.abs()), ComparableFloat(Float::ZERO));
assert_eq!(Float::ONE.abs(), Float::ONE);
assert_eq!(Float::NEGATIVE_ONE.abs(), Float::ONE);
§

type Output = Float

source§

impl AbsAssign for Float

source§

fn abs_assign(&mut self)

Replaces a Float with its absolute value.

$$ x \gets |x|. $$

Special cases:

  • $\text{NaN} \gets \text{NaN}$
  • $\infty \gets \infty$
  • $-\infty \gets \infty$
  • $0.0 \gets 0.0$
  • $-0.0 \gets 0.0$
Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::AbsAssign;
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

let mut x = Float::NAN;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));

let mut x = Float::INFINITY;
x.abs_assign();
assert_eq!(x, Float::INFINITY);

let mut x = Float::NEGATIVE_INFINITY;
x.abs_assign();
assert_eq!(x, Float::INFINITY);

let mut x = Float::ZERO;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));

let mut x = Float::NEGATIVE_ZERO;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));

let mut x = Float::ONE;
x.abs_assign();
assert_eq!(x, Float::ONE);

let mut x = Float::NEGATIVE_ONE;
x.abs_assign();
assert_eq!(x, Float::ONE);
source§

impl Clone for Float

source§

fn clone(&self) -> Float

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<'a> ConvertibleFrom<&'a Float> for Integer

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an Integer, taking the Float by reference.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(Integer::convertible_from(&Float::ZERO), true);
assert_eq!(Integer::convertible_from(&Float::from(123.0)), true);
assert_eq!(Integer::convertible_from(&Float::from(-123.0)), true);

assert_eq!(Integer::convertible_from(&Float::from(1.5)), false);
assert_eq!(Integer::convertible_from(&Float::INFINITY), false);
assert_eq!(Integer::convertible_from(&Float::NAN), false);
source§

impl<'a> ConvertibleFrom<&'a Float> for Natural

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a Natural (when the Float is non-negative and an integer), taking the Float by reference.

Both positive and negative zero are convertible to a Natural. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(Natural::convertible_from(&Float::ZERO), true);
assert_eq!(Natural::convertible_from(&Float::from(123.0)), true);

assert_eq!(Natural::convertible_from(&Float::from(-123.0)), false);
assert_eq!(Natural::convertible_from(&Float::from(1.5)), false);
assert_eq!(Natural::convertible_from(&Float::INFINITY), false);
assert_eq!(Natural::convertible_from(&Float::NAN), false);
source§

impl<'a> ConvertibleFrom<&'a Float> for Rational

source§

fn convertible_from(x: &'a Float) -> bool

Determines whether a Float can be converted to a Rational (which is when the Float is finite), taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_q::Rational;

assert_eq!(Rational::convertible_from(&Float::ZERO), true);
assert_eq!(Rational::convertible_from(&Float::from(123.0)), true);
assert_eq!(Rational::convertible_from(&Float::from(-123.0)), true);
assert_eq!(Rational::convertible_from(&Float::from(1.5)), true);

assert_eq!(Rational::convertible_from(&Float::INFINITY), false);
assert_eq!(Rational::convertible_from(&Float::NAN), false);
source§

impl<'a> ConvertibleFrom<&'a Float> for f32

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a primitive float, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for f64

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a primitive float, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for i128

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for i16

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for i32

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for i64

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for i8

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for isize

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to a signed primitive integer, taking the Float by reference.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for u128

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for u16

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for u32

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for u64

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for u8

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Float> for usize

source§

fn convertible_from(f: &'a Float) -> bool

Determines whether a Float can be converted to an unsigned primitive integer, taking the Float by reference.

Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl<'a> ConvertibleFrom<&'a Rational> for Float

source§

fn convertible_from(x: &'a Rational) -> bool

Determines whether a Rational can be converted to an Float, taking the Rational by reference.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_q::Rational;

assert_eq!(Float::convertible_from(&Rational::ZERO), true);
assert_eq!(Float::convertible_from(&Rational::from_signeds(3, 8)), true);
assert_eq!(Float::convertible_from(&Rational::from_signeds(-3, 8)), true);

assert_eq!(Float::convertible_from(&Rational::from_signeds(1, 3)), false);
assert_eq!(Float::convertible_from(&Rational::from_signeds(-1, 3)), false);
source§

impl Debug for Float

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Float

source§

fn default() -> Float

The default value of a Float, NaN.

source§

impl Display for Float

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a Integer> for Float

source§

fn from(n: &'a Integer) -> Float

Converts an Integer to a Float, taking the Integer by reference.

If the Integer is nonzero, the precision of the Float is equal to the Integer’s number of significant bits. If you want to specify a different precision, try Float::from_integer_prec_ref. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_integer_prec_round_ref.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(Float::from(&Integer::ZERO).to_string(), "0.0");
assert_eq!(Float::from(&Integer::from(123)).to_string(), "123.0");
assert_eq!(Float::from(&Integer::from(123)).get_prec(), Some(7));
assert_eq!(Float::from(&Integer::from(-123)).to_string(), "-123.0");
source§

impl<'a> From<&'a Natural> for Float

source§

fn from(n: &'a Natural) -> Float

Converts a Natural to a Float, taking the Natural by reference.

If the Natural is nonzero, the precision of the Float is equal to the Natural’s number of significant bits. If you want to specify a different precision, try Float::from_natural_prec_ref. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_natural_prec_round_ref.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(Float::from(&Natural::ZERO).to_string(), "0.0");
assert_eq!(Float::from(&Natural::from(123u32)).to_string(), "123.0");
assert_eq!(Float::from(&Natural::from(123u32)).get_prec(), Some(7));
source§

impl From<Integer> for Float

source§

fn from(n: Integer) -> Float

Converts an Integer to a Float, taking the Integer by value.

If the Integer is nonzero, the precision of the Float is equal to the Integer’s number of significant bits. If you want to specify a different precision, try Float::from_integer_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_integer_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(Float::from(Integer::ZERO).to_string(), "0.0");
assert_eq!(Float::from(Integer::from(123)).to_string(), "123.0");
assert_eq!(Float::from(Integer::from(123)).get_prec(), Some(7));
assert_eq!(Float::from(Integer::from(-123)).to_string(), "-123.0");
source§

impl From<Natural> for Float

source§

fn from(n: Natural) -> Float

Converts a Natural to a Float, taking the Natural by value.

If the Natural is nonzero, the precision of the Float is equal to the Natural’s number of significant bits. If you want to specify a different precision, try Float::from_natural_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_natural_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(Float::from(Natural::ZERO).to_string(), "0.0");
assert_eq!(Float::from(Natural::from(123u32)).to_string(), "123.0");
assert_eq!(Float::from(Natural::from(123u32)).get_prec(), Some(7));
source§

impl From<f32> for Float

source§

fn from(x: f32) -> Float

Converts a primitive float to a Float.

If the primitive float is finite and nonzero, the precision of the Float is equal to the maximum precision of any primitive float in the same binade (for normal f32s this is 24, and for normal f64s it is 53). If you want to specify a different precision, try Float::from_primitive_float_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_primitive_float_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.sci_exponent().abs().

Examples

See here.

source§

impl From<f64> for Float

source§

fn from(x: f64) -> Float

Converts a primitive float to a Float.

If the primitive float is finite and nonzero, the precision of the Float is equal to the maximum precision of any primitive float in the same binade (for normal f32s this is 24, and for normal f64s it is 53). If you want to specify a different precision, try Float::from_primitive_float_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_primitive_float_prec_round.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.sci_exponent().abs().

Examples

See here.

source§

impl From<i128> for Float

source§

fn from(i: i128) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<i16> for Float

source§

fn from(i: i16) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<i32> for Float

source§

fn from(i: i32) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<i64> for Float

source§

fn from(i: i64) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<i8> for Float

source§

fn from(i: i8) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<isize> for Float

source§

fn from(i: isize) -> Float

Converts a signed primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_signed_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_signed_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<u128> for Float

source§

fn from(u: u128) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<u16> for Float

source§

fn from(u: u16) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<u32> for Float

source§

fn from(u: u32) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<u64> for Float

source§

fn from(u: u64) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<u8> for Float

source§

fn from(u: u8) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl From<usize> for Float

source§

fn from(u: usize) -> Float

Converts an unsigned primitive integer to a Float.

If the integer is nonzero, the precision of the Float is equal to the integer’s number of significant bits. If you want to specify a different precision, try Float::from_unsigned_prec. This may require rounding, which uses RoundingMode::Nearest by default. To specify a rounding mode as well as a precision, try Float::from_unsigned_prec_round.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

impl FromStringBase for Float

source§

fn from_string_base(base: u8, s: &str) -> Option<Self>

source§

impl Infinity for Float

The constant Infinity.

source§

impl IntegerMantissaAndExponent<Natural, i64> for Float

source§

fn integer_mantissa_and_exponent(self) -> (Natural, i64)

Returns a Float’s integer mantissa and exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = (\frac{|x|}{2^{e_i}}, e_i), $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.

The inverse operation is from_integer_mantissa_and_exponent.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::ONE.integer_mantissa_and_exponent(), (Natural::ONE, 0));
assert_eq!(
    Float::from(std::f64::consts::PI).integer_mantissa_and_exponent(),
    (Natural::from(884279719003555u64), -48)
);
assert_eq!(
    Float::from(Natural::from(3u32).pow(50u64)).integer_mantissa_and_exponent(),
    (Natural::from_str("717897987691852588770249").unwrap(), 0)
);
assert_eq!(
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
        .integer_mantissa_and_exponent(),
    (Natural::from_str("1067349099133908271875104088939").unwrap(), -179)
);
source§

fn integer_exponent(self) -> i64

Returns a Float’s integer exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = e_i, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::ONE.integer_exponent(), 0);
assert_eq!(Float::from(std::f64::consts::PI).integer_exponent(), -48);
assert_eq!(Float::from(Natural::from(3u32).pow(50u64)).integer_exponent(), 0);
assert_eq!(
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0.integer_exponent(),
    -179
);
source§

fn from_integer_mantissa_and_exponent( integer_mantissa: Natural, integer_exponent: i64 ) -> Option<Float>

Constructs a Float from its integer mantissa and exponent.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer.

$$ f(x) = 2^{e_i}m_i. $$

The input does not have to be reduced; that is, the mantissa does not have to be odd.

The result is an Option, but for this trait implementation the result is always Some.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is integer_mantissa.significant_bits().

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::from_integer_mantissa_and_exponent(Natural::ONE, 0).unwrap(), 1);
assert_eq!(
    Float::from_integer_mantissa_and_exponent(Natural::from(884279719003555u64), -48)
        .unwrap(),
    std::f64::consts::PI
);
assert_eq!(
    Float::from_integer_mantissa_and_exponent(
        Natural::from_str("717897987691852588770249").unwrap(),
        0
    ).unwrap(),
    Natural::from(3u32).pow(50u64)
);
assert_eq!(
    Float::from_integer_mantissa_and_exponent(
        Natural::from_str("1067349099133908271875104088939").unwrap(),
        -179
    ).unwrap(),
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
source§

fn integer_mantissa(self) -> M

Extracts the integer mantissa from a number.
source§

impl<'a> IntegerMantissaAndExponent<Natural, i64, Float> for &'a Float

source§

fn integer_mantissa_and_exponent(self) -> (Natural, i64)

Returns a Float’s integer mantissa and exponent, taking the Float by reference.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = (\frac{|x|}{2^{e_i}}, e_i), $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.

The inverse operation is from_integer_mantissa_and_exponent.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!((&Float::ONE).integer_mantissa_and_exponent(), (Natural::ONE, 0));
assert_eq!(
    (&Float::from(std::f64::consts::PI)).integer_mantissa_and_exponent(),
    (Natural::from(884279719003555u64), -48)
);
assert_eq!(
    (&Float::from(Natural::from(3u32).pow(50u64))).integer_mantissa_and_exponent(),
    (Natural::from_str("717897987691852588770249").unwrap(), 0)
);
assert_eq!(
    (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
        .integer_mantissa_and_exponent(),
    (Natural::from_str("1067349099133908271875104088939").unwrap(), -179)
);
source§

fn integer_exponent(self) -> i64

Returns a Float’s integer exponent, taking the Float by reference.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = e_i, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!((&Float::ONE).integer_exponent(), 0);
assert_eq!((&Float::from(std::f64::consts::PI)).integer_exponent(), -48);
assert_eq!((&Float::from(Natural::from(3u32).pow(50u64))).integer_exponent(), 0);
assert_eq!(
    (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
        .integer_exponent(),
    -179
);
source§

fn from_integer_mantissa_and_exponent( integer_mantissa: Natural, integer_exponent: i64 ) -> Option<Float>

Constructs a Float from its integer mantissa and exponent.

When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer.

$$ f(x) = 2^{e_i}m_i. $$

The input does not have to be reduced; that is, the mantissa does not have to be odd.

The result is an Option, but for this trait implementation the result is always Some.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is integer_mantissa.significant_bits().

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(
    <&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
        Natural::ONE,
        0
    ).unwrap(),
    1
);
assert_eq!(
    <&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
        Natural::from(884279719003555u64),
        -48
    ).unwrap(),
    std::f64::consts::PI
);
assert_eq!(
    <&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
        Natural::from_str("717897987691852588770249").unwrap(),
        0
    ).unwrap(),
    Natural::from(3u32).pow(50u64)
);
assert_eq!(
    <&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
        Natural::from_str("1067349099133908271875104088939").unwrap(),
        -179
    ).unwrap(),
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
source§

fn integer_mantissa(self) -> M

Extracts the integer mantissa from a number.
source§

impl<'a> IsInteger for &'a Float

source§

fn is_integer(self) -> bool

Determines whether a Float is an integer.

$f(x) = x \in \Z$.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{One, OneHalf, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_float::Float;

assert_eq!(Float::ZERO.is_integer(), true);
assert_eq!(Float::ONE.is_integer(), true);
assert_eq!(Float::from(100).is_integer(), true);
assert_eq!(Float::from(-100).is_integer(), true);
assert_eq!(Float::ONE_HALF.is_integer(), false);
assert_eq!((-Float::ONE_HALF).is_integer(), false);
source§

impl IsPowerOf2 for Float

source§

fn is_power_of_2(&self) -> bool

Determines whether a Float is an integer power of 2.

$f(x) = (\exists n \in \Z : 2^n = x)$.

Floats that are NaN, infinite, or zero are not powers of 2.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::basic::traits::{NaN, One, OneHalf, Two};
use malachite_base::num::arithmetic::traits::IsPowerOf2;
use malachite_float::Float;

assert_eq!(Float::NAN.is_power_of_2(), false);

assert_eq!(Float::ONE.is_power_of_2(), true);
assert_eq!(Float::TWO.is_power_of_2(), true);
assert_eq!(Float::ONE_HALF.is_power_of_2(), true);
assert_eq!(Float::from(1024).is_power_of_2(), true);

assert_eq!(Float::from(3).is_power_of_2(), false);
assert_eq!(Float::from(1025).is_power_of_2(), false);
assert_eq!(Float::from(0.1f64).is_power_of_2(), false);
source§

impl LowerHex for Float

source§

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

Formats the value using the given formatter.
source§

impl Max for Float

The highest value representable by this type, positive infinity.

source§

const MAX: Float = Float::INFINITY

The maximum value of Self.
source§

impl Min for Float

The lowest value representable by this type, negative infinity.

source§

const MIN: Float = Float::NEGATIVE_INFINITY

The minimum value of Self.
source§

impl NaN for Float

The constant NaN.

source§

const NAN: Float = _

source§

impl Named for Float

source§

const NAME: &'static str = "Float"

The name of this type, as given by the stringify macro.

See the documentation for impl_named for more details.

source§

impl<'a> Neg for &'a Float

source§

fn neg(self) -> Float

Negates a Float, taking it by reference.

$$ f(x) = -x. $$

Special cases:

  • $f(\text{NaN}) = \text{NaN}$
  • $f(\infty) = -\infty$
  • $f(-\infty) = \infty$
  • $f(0.0) = -0.0$
  • $f(-0.0) = 0.0$
Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(ComparableFloat(-&Float::NAN), ComparableFloat(Float::NAN));
assert_eq!(-&Float::INFINITY, Float::NEGATIVE_INFINITY);
assert_eq!(-&Float::NEGATIVE_INFINITY, Float::INFINITY);
assert_eq!(ComparableFloat(-&Float::ZERO), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(ComparableFloat(-&Float::NEGATIVE_ZERO), ComparableFloat(Float::ZERO));
assert_eq!(-&Float::ONE, Float::NEGATIVE_ONE);
assert_eq!(-&Float::NEGATIVE_ONE, Float::ONE);
§

type Output = Float

The resulting type after applying the - operator.
source§

impl Neg for Float

source§

fn neg(self) -> Float

Negates a Float, taking it by value.

$$ f(x) = -x. $$

Special cases:

  • $f(\text{NaN}) = \text{NaN}$
  • $f(\infty) = -\infty$
  • $f(-\infty) = \infty$
  • $f(0.0) = -0.0$
  • $f(-0.0) = 0.0$
Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

assert_eq!(ComparableFloat(-Float::NAN), ComparableFloat(Float::NAN));
assert_eq!(-Float::INFINITY, Float::NEGATIVE_INFINITY);
assert_eq!(-Float::NEGATIVE_INFINITY, Float::INFINITY);
assert_eq!(ComparableFloat(-Float::ZERO), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(ComparableFloat(-Float::NEGATIVE_ZERO), ComparableFloat(Float::ZERO));
assert_eq!(-Float::ONE, Float::NEGATIVE_ONE);
assert_eq!(-Float::NEGATIVE_ONE, Float::ONE);
§

type Output = Float

The resulting type after applying the - operator.
source§

impl NegAssign for Float

source§

fn neg_assign(&mut self)

Negates a Float in place.

$$ x \gets -x. $$

Special cases:

  • $\text{NaN} \gets \text{NaN}$
  • $\infty \gets -\infty$
  • $-\infty \gets \infty$
  • $0.0 \gets -0.0$
  • $-0.0 \gets 0.0$
Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::NegAssign;
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::{ComparableFloat, Float};

let mut x = Float::NAN;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));

let mut x = Float::INFINITY;
x.neg_assign();
assert_eq!(x, Float::NEGATIVE_INFINITY);

let mut x = Float::NEGATIVE_INFINITY;
x.neg_assign();
assert_eq!(x, Float::INFINITY);

let mut x = Float::ZERO;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NEGATIVE_ZERO));

let mut x = Float::NEGATIVE_ZERO;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));

let mut x = Float::ONE;
x.neg_assign();
assert_eq!(x, Float::NEGATIVE_ONE);

let mut x = Float::NEGATIVE_ONE;
x.neg_assign();
assert_eq!(x, Float::ONE);
source§

impl NegativeInfinity for Float

The constant -Infinity.

source§

impl NegativeOne for Float

The constant -1.0, with precision 1.

source§

impl NegativeZero for Float

The constant -0.0, with precision 1.

source§

impl One for Float

The constant 1.0, with precision 1.

source§

const ONE: Float = _

source§

impl OneHalf for Float

The constant 0.5, with precision 1.

source§

impl PartialEq<Float> for Integer

source§

fn eq(&self, other: &Float) -> bool

Determines whether an Integer is equal to a Float.

No Integer is equal to infinity, negative infinity, or NaN. The Integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Integer::from(123) == Float::from(123));
assert!(Integer::from(-123) == Float::from(-123));
assert!(Integer::ONE != Float::ONE_HALF);
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 PartialEq<Float> for Natural

source§

fn eq(&self, other: &Float) -> bool

Determines whether a Natural is equal to a Float.

No Natural is equal to infinity, negative infinity, or NaN. The Natural zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Natural::from(123u32) == Float::from(123));
assert!(Natural::ONE != Float::ONE_HALF);
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 PartialEq<Float> for Rational

source§

fn eq(&self, other: &Float) -> bool

Determines whether a Rational is equal to a Float.

No Rational is equal to infinity, negative infinity, or NaN. The Rational zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_q::Rational;

assert!(Rational::from(123) == Float::from(123));
assert!(Rational::from(-123) == Float::from(-123));
assert!(Rational::ONE_HALF == Float::ONE_HALF);
assert!(Rational::from_unsigneds(1u8, 3) != Float::from(1.0f64 / 3.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 PartialEq<Float> for f32

source§

fn eq(&self, other: &Float) -> bool

Determines whether a primitive float is equal to a Float.

The primitive float infinity is equal to the Float infinity, and the primitive float negative infinity is equal to the Float negative infinity. The primitive float NaN is not equal to anything, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialEq<Float> for f64

source§

fn eq(&self, other: &Float) -> bool

Determines whether a primitive float is equal to a Float.

The primitive float infinity is equal to the Float infinity, and the primitive float negative infinity is equal to the Float negative infinity. The primitive float NaN is not equal to anything, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialEq<Float> for i128

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for i16

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for i32

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for i64

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for i8

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for isize

source§

fn eq(&self, other: &Float) -> bool

Determines whether a signed primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for u128

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for u16

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for u32

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for u64

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for u8

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Float> for usize

source§

fn eq(&self, other: &Float) -> bool

Determines whether an unsigned primitive integer is equal to a Float.

No primitive integer is equal to infinity, negative infinity, or NaN. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialEq<Integer> for Float

source§

fn eq(&self, other: &Integer) -> bool

Determines whether a Float is equal to an Integer.

Infinity, negative infinity, and NaN are not equal to any Integer. Both the Float zero and the Float negative zero are equal to the Integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Float::from(123) == Integer::from(123));
assert!(Float::from(-123) == Integer::from(-123));
assert!(Float::ONE_HALF != Integer::ONE);
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 PartialEq<Natural> for Float

source§

fn eq(&self, other: &Natural) -> bool

Determines whether a Float is equal to a Natural.

Infinity, negative infinity, and NaN are not equal to any Natural. Both the Float zero and the Float negative zero are equal to the Natural zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Float::from(123) == Natural::from(123u32));
assert!(Float::ONE_HALF != Natural::ONE);
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 PartialEq<Rational> for Float

source§

fn eq(&self, other: &Rational) -> bool

Determines whether a Float is equal to a Rational.

Infinity, negative infinity, and NaN are not equal to any Rational. Both the Float zero and the Float negative zero are equal to the Rational zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::OneHalf;
use malachite_float::Float;
use malachite_q::Rational;

assert!(Float::from(123) == Rational::from(123));
assert!(Float::from(-123) == Rational::from(-123));
assert!(Float::ONE_HALF == Rational::ONE_HALF);
assert!(Float::from(1.0f64 / 3.0) != Rational::from_unsigneds(1u8, 3));
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 PartialEq<f32> for Float

source§

fn eq(&self, other: &f32) -> bool

Determines whether a Float is equal to a primitive float.

The Float infinity is equal to the primitive float infinity, and the Float negative infinity is equal to the primitive float negative infinity. The Float NaN is not equal to anything, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialEq<f64> for Float

source§

fn eq(&self, other: &f64) -> bool

Determines whether a Float is equal to a primitive float.

The Float infinity is equal to the primitive float infinity, and the Float negative infinity is equal to the primitive float negative infinity. The Float NaN is not equal to anything, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialEq<i128> for Float

source§

fn eq(&self, other: &i128) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<i16> for Float

source§

fn eq(&self, other: &i16) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<i32> for Float

source§

fn eq(&self, other: &i32) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<i64> for Float

source§

fn eq(&self, other: &i64) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<i8> for Float

source§

fn eq(&self, other: &i8) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<isize> for Float

source§

fn eq(&self, other: &isize) -> bool

Determines whether a Float is equal to a signed primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<u128> for Float

source§

fn eq(&self, other: &u128) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<u16> for Float

source§

fn eq(&self, other: &u16) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<u32> for Float

source§

fn eq(&self, other: &u32) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<u64> for Float

source§

fn eq(&self, other: &u64) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<u8> for Float

source§

fn eq(&self, other: &u8) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq<usize> for Float

source§

fn eq(&self, other: &usize) -> bool

Determines whether a Float is equal to an unsigned primitive integer.

Infinity, negative infinity, and NaN are not equal to any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialEq for Float

source§

fn eq(&self, other: &Float) -> bool

Compares two Floats for equality.

This implementation follows the IEEE 754 standard. NaN is not equal to anything, not even itself. Positive zero is equal to negative zero. Floats with different precisions are equal if they represent the same numeric value.

For different equality behavior, consider using ComparableFloat or ComparableFloatRef.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{NaN, NegativeZero, One, Two, Zero};
use malachite_float::Float;

assert_ne!(Float::NAN, Float::NAN);
assert_eq!(Float::ZERO, Float::ZERO);
assert_eq!(Float::NEGATIVE_ZERO, Float::NEGATIVE_ZERO);
assert_eq!(Float::ZERO, Float::NEGATIVE_ZERO);

assert_eq!(Float::ONE, Float::ONE);
assert_ne!(Float::ONE, Float::TWO);
assert_eq!(Float::ONE, Float::one_prec(100));
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 PartialOrd<Float> for Integer

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an Integer to a Float.

No Integer is comparable to NaN. Every Integer is smaller than infinity and greater than negative infinity. The Integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Integer::from(100) > Float::from(80));
assert!(Integer::from(-100) < Float::from(-80));
assert!(Integer::from(100) < Float::INFINITY);
assert!(Integer::from(-100) > Float::NEGATIVE_INFINITY);
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 PartialOrd<Float> for Natural

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a Natural to a Float.

No Natural is comparable to NaN. Every Natural is smaller than infinity and greater than negative infinity. The Natural zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Natural::from(100u32) > Float::from(80));
assert!(Natural::from(100u32) < Float::INFINITY);
assert!(Natural::from(100u32) > Float::NEGATIVE_INFINITY);
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 PartialOrd<Float> for Rational

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an Rational to a Float.

No Rational is comparable to NaN. Every Rational is smaller than infinity and greater than negative infinity. The Rational zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_q::Rational;

assert!(Rational::from(100) > Float::from(80));
assert!(Rational::from(-100) < Float::from(-80));
assert!(Rational::from(100) < Float::INFINITY);
assert!(Rational::from(-100) > Float::NEGATIVE_INFINITY);
assert!(Rational::from_unsigneds(1u8, 3) > Float::from(1.0f64 / 3.0));
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 PartialOrd<Float> for f32

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a primitive float to a Float.

The primitive float NaN is not comparable to any primitive float, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialOrd<Float> for f64

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a primitive float to a Float.

The primitive float NaN is not comparable to any primitive float, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialOrd<Float> for i128

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for i16

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for i32

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for i64

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for i8

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for isize

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares a signed primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for u128

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for u16

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for u32

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for u64

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for u8

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Float> for usize

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares an unsigned primitive integer to a Float.

No integer is comparable to NaN. Every integer is smaller than infinity and greater than negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

Examples

See here.

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 PartialOrd<Integer> for Float

source§

fn partial_cmp(&self, other: &Integer) -> Option<Ordering>

Compares a Float to an Integer.

NaN is not comparable to any Integer. Infinity is greater than any Integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the Integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Float::from(80) < Integer::from(100));
assert!(Float::from(-80) > Integer::from(-100));
assert!(Float::INFINITY > Integer::from(100));
assert!(Float::NEGATIVE_INFINITY < Integer::from(-100));
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 PartialOrd<Natural> for Float

source§

fn partial_cmp(&self, other: &Natural) -> Option<Ordering>

Compares a Float to a Natural.

NaN is not comparable to any Natural. Infinity is greater than any Natural, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the Natural zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Float::from(80) < Natural::from(100u32));
assert!(Float::INFINITY > Natural::from(100u32));
assert!(Float::NEGATIVE_INFINITY < Natural::from(100u32));
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 PartialOrd<Rational> for Float

source§

fn partial_cmp(&self, other: &Rational) -> Option<Ordering>

Compares a Float to a Rational.

NaN is not comparable to any Rational. Infinity is greater than any Rational, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the Rational zero.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_q::Rational;

assert!(Float::from(80) < Rational::from(100));
assert!(Float::from(-80) > Rational::from(-100));
assert!(Float::INFINITY > Rational::from(100));
assert!(Float::NEGATIVE_INFINITY < Rational::from(-100));
assert!(Float::from(1.0f64 / 3.0) < Rational::from_unsigneds(1u8, 3));
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 PartialOrd<f32> for Float

source§

fn partial_cmp(&self, other: &f32) -> Option<Ordering>

Compares a Float to a primitive float.

The Float NaN is not comparable to any primitive float, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialOrd<f64> for Float

source§

fn partial_cmp(&self, other: &f64) -> Option<Ordering>

Compares a Float to a primitive float.

The Float NaN is not comparable to any primitive float, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

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 PartialOrd<i128> for Float

source§

fn partial_cmp(&self, other: &i128) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<i16> for Float

source§

fn partial_cmp(&self, other: &i16) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<i32> for Float

source§

fn partial_cmp(&self, other: &i32) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<i64> for Float

source§

fn partial_cmp(&self, other: &i64) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<i8> for Float

source§

fn partial_cmp(&self, other: &i8) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<isize> for Float

source§

fn partial_cmp(&self, other: &isize) -> Option<Ordering>

Compares a Float to a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<u128> for Float

source§

fn partial_cmp(&self, other: &u128) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<u16> for Float

source§

fn partial_cmp(&self, other: &u16) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<u32> for Float

source§

fn partial_cmp(&self, other: &u32) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<u64> for Float

source§

fn partial_cmp(&self, other: &u64) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<u8> for Float

source§

fn partial_cmp(&self, other: &u8) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd<usize> for Float

source§

fn partial_cmp(&self, other: &usize) -> Option<Ordering>

Compares a Float to an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity is greater than any primitive integer, and negative infinity is less. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

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 PartialOrd for Float

source§

fn partial_cmp(&self, other: &Float) -> Option<Ordering>

Compares two Floats.

This implementation follows the IEEE 754 standard. NaN is not comparable to anything, not even itself. Positive zero is equal to negative zero. Floats with different precisions are equal if they represent the same numeric value.

For different comparison behavior that provides a total order, consider using ComparableFloat or ComparableFloatRef.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero
};
use malachite_float::Float;
use std::cmp::Ordering;
use std::str::FromStr;

assert_eq!(Float::NAN.partial_cmp(&Float::NAN), None);
assert_eq!(Float::ZERO.partial_cmp(&Float::NEGATIVE_ZERO), Some(Ordering::Equal));
assert_eq!(Float::ONE.partial_cmp(&Float::one_prec(100)), Some(Ordering::Equal));
assert!(Float::INFINITY > Float::ONE);
assert!(Float::NEGATIVE_INFINITY < Float::ONE);
assert!(Float::ONE_HALF < Float::ONE);
assert!(Float::ONE_HALF > Float::NEGATIVE_ONE);
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 PartialOrdAbs<Float> for Integer

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an Integer and a Float.

No Integer is comparable to NaN. Every Integer is smaller in absolute value than infinity and negative infinity. The Integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Integer::from(100).gt_abs(&Float::from(80)));
assert!(Integer::from(100).lt_abs(&Float::INFINITY));
assert!(Integer::from(-100).lt_abs(&Float::INFINITY));
assert!(Integer::from(-100).lt_abs(&Float::NEGATIVE_INFINITY));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for Natural

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares a Natural to the absolute value of a Float.

No Natural is comparable to NaN. Every Natural is smaller in absolute value than infinity and negative infinity. The Natural zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Natural::from(100u32).gt_abs(&Float::from(80)));
assert!(Natural::from(100u32).lt_abs(&Float::INFINITY));
assert!(Natural::from(100u32).lt_abs(&Float::NEGATIVE_INFINITY));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for Rational

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a Rational and a Float.

No Rational is comparable to NaN. Every Rational is smaller in absolute value than infinity and negative infinity. The Rational zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_q::Rational;

assert!(Rational::from(100).gt_abs(&Float::from(80)));
assert!(Rational::from(-100).gt_abs(&Float::from(-80)));
assert!(Rational::from(100).lt_abs(&Float::INFINITY));
assert!(Rational::from(-100).lt_abs(&Float::NEGATIVE_INFINITY));
assert!(Rational::from_unsigneds(1u8, 3).gt_abs(&Float::from(1.0f64 / 3.0)));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for f32

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a primitive float and a Float.

The primitive float NaN is not comparable to any primitive float, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for f64

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a primitive float and a Float.

The primitive float NaN is not comparable to any primitive float, not even the Float NaN. Every primitive float zero is equal to every Float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for i128

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for i16

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for i32

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for i64

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for i8

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for isize

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for u128

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for u16

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for u32

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for u64

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for u8

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Float> for usize

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Float.

No primitive integer is comparable to NaN. Every primitive integer is smaller in absolute value than infinity and negative infinity. The integer zero is equal to both the Float zero and the Float negative zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits().

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Integer> for Float

source§

fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>

Compares the absolute values of a Float and an Integer.

NaN is not comparable to any Integer. Infinity and negative infinity are greater in absolute value than any Integer. Both the Float zero and the Float negative zero are equal to the Integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert!(Float::from(80).lt_abs(&Integer::from(100)));
assert!(Float::from(-80).lt_abs(&Integer::from(-100)));
assert!(Float::INFINITY.gt_abs(&Integer::from(100)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Integer::from(-100)));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Natural> for Float

source§

fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>

Compares the absolute value of a Float to a Natural.

NaN is not comparable to any Natural. Infinity and negative infinity are greater in absolute value than any Natural. Both the Float zero and the Float negative zero are equal to the Natural zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert!(Float::from(80).lt_abs(&Natural::from(100u32)));
assert!(Float::INFINITY.gt_abs(&Natural::from(100u32)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Natural::from(100u32)));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<Rational> for Float

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a Float and a Rational.

NaN is not comparable to any Rational. Infinity and negative infinity are greater in absolute value than any Rational. Both the Float zero and the Float negative zero are equal to the Rational zero.

Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_q::Rational;

assert!(Float::from(80).lt_abs(&Rational::from(100)));
assert!(Float::from(-80).lt_abs(&Rational::from(-100)));
assert!(Float::INFINITY.gt_abs(&Rational::from(100)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Rational::from(-100)));
assert!(Float::from(1.0f64 / 3.0).lt_abs(&Rational::from_unsigneds(1u8, 3)));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<f32> for Float

source§

fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>

Compares the absolute values of a Float and a primitive float.

The Float NaN is not comparable to any primitive float, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<f64> for Float

source§

fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>

Compares the absolute values of a Float and a primitive float.

The Float NaN is not comparable to any primitive float, not even the primitive float NaN. Every Float zero is equal to every primitive float zero, regardless of sign.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.sci_exponent().abs()).

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<i128> for Float

source§

fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<i16> for Float

source§

fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<i32> for Float

source§

fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<i64> for Float

source§

fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<i8> for Float

source§

fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<isize> for Float

source§

fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>

Compares the absolute values of a Float and a signed primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<u128> for Float

source§

fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<u16> for Float

source§

fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<u32> for Float

source§

fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<u64> for Float

source§

fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<u8> for Float

source§

fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs<usize> for Float

source§

fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>

Compares the absolute values of a Float and an unsigned primitive integer.

NaN is not comparable to any primitive integer. Infinity and negative infinity are greater in absolute value than any primitive integer. Both the Float zero and the Float negative zero are equal to the integer zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Examples

See here.

source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PartialOrdAbs for Float

source§

fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>

Compares the absolute values of two Floats.

This implementation follows the IEEE 754 standard. NaN is not comparable to anything, not even itself. Floats with different precisions are equal if they represent the same numeric value.

For different comparison behavior that provides a total order, consider using ComparableFloat or ComparableFloatRef.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero
};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use std::cmp::Ordering;
use std::str::FromStr;

assert_eq!(Float::NAN.partial_cmp_abs(&Float::NAN), None);
assert_eq!(Float::ZERO.partial_cmp_abs(&Float::NEGATIVE_ZERO), Some(Ordering::Equal));
assert_eq!(Float::ONE.partial_cmp_abs(&Float::one_prec(100)), Some(Ordering::Equal));
assert!(Float::INFINITY.gt_abs(&Float::ONE));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Float::ONE));
assert!(Float::ONE_HALF.lt_abs(&Float::ONE));
assert!(Float::ONE_HALF.lt_abs(&Float::NEGATIVE_ONE));
source§

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

Determines whether the absolute value of one number is less than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
source§

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

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
source§

impl PowerOf2<i64> for Float

source§

fn power_of_2(pow: i64) -> Float

Raises 2 to an integer power, returning a Float with precision 1.

To get a Float with a higher precision, try Float::power_of_2_prec.

$f(k) = 2^k$.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_float::Float;

assert_eq!(Float::power_of_2(0i64).to_string(), "1.0");
assert_eq!(Float::power_of_2(3i64).to_string(), "8.0");
assert_eq!(Float::power_of_2(100i64).to_string(), "1.0e30");
assert_eq!(Float::power_of_2(-3i64).to_string(), "0.1");
assert_eq!(Float::power_of_2(-100i64).to_string(), "8.0e-31");
source§

impl PowerOf2<u64> for Float

source§

fn power_of_2(pow: u64) -> Float

Raises 2 to an integer power, returning a Float with precision 1.

To get a Float with a higher precision, try Float::power_of_2_prec.

$f(k) = 2^k$.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_float::Float;

assert_eq!(Float::power_of_2(0u64).to_string(), "1.0");
assert_eq!(Float::power_of_2(3u64).to_string(), "8.0");
assert_eq!(Float::power_of_2(100u64).to_string(), "1.0e30");
source§

impl RawMantissaAndExponent<Natural, i64> for Float

source§

fn raw_mantissa_and_exponent(self) -> (Natural, i64)

Returns the raw mantissa and exponent of a Float, taking the Float by value.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of self. When self is finite and nonzero, the raw mantissa is an integer whose number of significant bits is a multiple of the limb width, and which is equal to the absolute value of self multiplied by some integer power of 2. The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of self.

The inverse operation is Self::from_raw_mantissa_and_exponent.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not finite or not zero.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;

if Limb::WIDTH == u64::WIDTH {
    let (m, e) = Float::ONE.raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "9223372036854775808");
    assert_eq!(e, 1);

    let (m, e) = Float::from(std::f64::consts::PI).raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "14488038916154245120");
    assert_eq!(e, 2);

    let (m, e) = Float::from(Natural::from(3u32).pow(50u64)).raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "202070319366191015160784900114134073344");
    assert_eq!(e, 80);

    let (m, e) = Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
        .raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "286514342137199872022965541161805021184");
    assert_eq!(e, -79);
}
source§

fn raw_exponent(self) -> i64

Returns the raw exponent of a Float, taking the Float by value.

The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of self.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not finite or not zero.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(Float::ONE.raw_exponent(), 1);
assert_eq!(Float::from(std::f64::consts::PI).raw_exponent(), 2);
assert_eq!(Float::from(Natural::from(3u32).pow(50u64)).raw_exponent(), 80);
assert_eq!(
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0.raw_exponent(),
    -79
);
source§

fn from_raw_mantissa_and_exponent( raw_mantissa: Natural, raw_exponent: i64 ) -> Float

Constructs a Float from its raw mantissa and exponent. The resulting Float is positive and has the smallest precision possible.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if raw_mantissa is zero, or if its number of significant bits is not divisible by the limb width.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
use std::str::FromStr;

if Limb::WIDTH == u64::WIDTH {
    assert_eq!(
        Float::from_raw_mantissa_and_exponent(Natural::from(9223372036854775808u64), 1),
        1
    );
    assert_eq!(
        Float::from_raw_mantissa_and_exponent(Natural::from(14488038916154245120u64), 2),
        std::f64::consts::PI
    );
    assert_eq!(
        Float::from_raw_mantissa_and_exponent(
            Natural::from_str("202070319366191015160784900114134073344").unwrap(),
            80
        ),
        Natural::from(3u32).pow(50u64)
    );
    assert_eq!(
        Float::from_raw_mantissa_and_exponent(
            Natural::from_str("286514342137199872022965541161805021184").unwrap(),
            -79
        ),
        Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
    );
}
source§

fn raw_mantissa(self) -> M

Extracts the raw mantissa from a number.
source§

impl<'a> RawMantissaAndExponent<Natural, i64, Float> for &'a Float

source§

fn raw_mantissa_and_exponent(self) -> (Natural, i64)

Returns the raw mantissa and exponent of a Float, taking the Float by reference.

The raw exponent and raw mantissa are the actual bit patterns used to represent the components of self. When self is finite and nonzero, the raw mantissa is an integer whose number of significant bits is a multiple of the limb width, and which is equal to the absolute value of self multiplied by some integer power of 2. The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of self.

The inverse operation is Float::from_raw_mantissa_and_exponent.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits().

Panics

Panics if the Float is not finite or not zero.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;

if Limb::WIDTH == u64::WIDTH {
    let (m, e) = (&Float::ONE).raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "9223372036854775808");
    assert_eq!(e, 1);

    let (m, e) = (&Float::from(std::f64::consts::PI)).raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "14488038916154245120");
    assert_eq!(e, 2);

    let (m, e) = (&Float::from(Natural::from(3u32).pow(50u64)))
        .raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "202070319366191015160784900114134073344");
    assert_eq!(e, 80);

    let (m, e) = (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
        .raw_mantissa_and_exponent();
    assert_eq!(m.to_string(), "286514342137199872022965541161805021184");
    assert_eq!(e, -79);
}
source§

fn raw_exponent(self) -> i64

Returns the raw exponent of a Float, taking the Float by reference.

The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of self.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not finite or not zero.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!((&Float::ONE).raw_exponent(), 1);
assert_eq!((&Float::from(std::f64::consts::PI)).raw_exponent(), 2);
assert_eq!((&Float::from(Natural::from(3u32).pow(50u64))).raw_exponent(), 80);
assert_eq!(
    (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0).raw_exponent(),
    -79
);
source§

fn from_raw_mantissa_and_exponent( raw_mantissa: Natural, raw_exponent: i64 ) -> Float

Constructs a Float from its raw mantissa and exponent. The resulting Float is positive and has the smallest precision possible.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if raw_mantissa is zero, or if its number of significant bits is not divisible by the limb width.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
use std::str::FromStr;

if Limb::WIDTH == u64::WIDTH {
    assert_eq!(
        <&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
            Natural::from(9223372036854775808u64),
            1
        ),
        1
    );
    assert_eq!(
        <&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
            Natural::from(14488038916154245120u64),
            2
        ),
        std::f64::consts::PI
    );
    assert_eq!(
        <&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
            Natural::from_str("202070319366191015160784900114134073344").unwrap(),
            80
    ),
        Natural::from(3u32).pow(50u64)
    );
    assert_eq!(
        <&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
            Natural::from_str("286514342137199872022965541161805021184").unwrap(),
            -79
        ),
        Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
    );
}
source§

fn raw_mantissa(self) -> M

Extracts the raw mantissa from a number.
source§

impl<'a> RoundingFrom<&'a Float> for Integer

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (Integer, Ordering)

Converts a Float to an Integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is NaN or infinite, the function will panic regardless of the rounding mode.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is NaN or infinite.

Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::rounding_from(&Float::from(1.5), RoundingMode::Floor).to_debug_string(),
    "(1, Less)"
);
assert_eq!(
    Integer::rounding_from(&Float::from(1.5), RoundingMode::Ceiling).to_debug_string(),
    "(2, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Float::from(1.5), RoundingMode::Nearest).to_debug_string(),
    "(2, Greater)"
);

assert_eq!(
    Integer::rounding_from(&Float::from(-1.5), RoundingMode::Floor).to_debug_string(),
    "(-2, Less)"
);
assert_eq!(
    Integer::rounding_from(&Float::from(-1.5), RoundingMode::Ceiling).to_debug_string(),
    "(-1, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Float::from(-1.5), RoundingMode::Nearest).to_debug_string(),
    "(-2, Less)"
);
source§

impl<'a> RoundingFrom<&'a Float> for Natural

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (Natural, Ordering)

Converts a Float to a Natural, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN or positive infinity, the function will panic regardless of the rounding mode.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, or if the Float is NaN or positive infinity.

Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(
    Natural::rounding_from(&Float::from(1.5), RoundingMode::Floor).to_debug_string(),
    "(1, Less)"
);
assert_eq!(
    Natural::rounding_from(&Float::from(1.5), RoundingMode::Ceiling).to_debug_string(),
    "(2, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Float::from(1.5), RoundingMode::Nearest).to_debug_string(),
    "(2, Greater)"
);

assert_eq!(
    Natural::rounding_from(&Float::NEGATIVE_INFINITY, RoundingMode::Down)
        .to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Float::NEGATIVE_INFINITY, RoundingMode::Ceiling)
        .to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Float::NEGATIVE_INFINITY, RoundingMode::Nearest)
        .to_debug_string(),
    "(0, Greater)"
);
source§

impl<'a> RoundingFrom<&'a Float> for f32

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (f32, Ordering)

Converts a Float to a primitive float, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not exactly equal to any float of the target type, and rm is Exact.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for f64

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (f64, Ordering)

Converts a Float to a primitive float, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not exactly equal to any float of the target type, and rm is Exact.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for i128

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (i128, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for i16

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (i16, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for i32

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (i32, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for i64

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (i64, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for i8

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (i8, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for isize

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (isize, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for u128

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (u128, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for u16

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (u16, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for u32

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (u32, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for u64

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (u64, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for u8

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (u8, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl<'a> RoundingFrom<&'a Float> for usize

source§

fn rounding_from(f: &'a Float, rm: RoundingMode) -> (usize, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for Integer

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (Integer, Ordering)

Converts a Float to an Integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is NaN or infinite, the function will panic regardless of the rounding mode.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is NaN or infinite.

Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::rounding_from(Float::from(1.5), RoundingMode::Floor).to_debug_string(),
    "(1, Less)"
);
assert_eq!(
    Integer::rounding_from(Float::from(1.5), RoundingMode::Ceiling).to_debug_string(),
    "(2, Greater)"
);
assert_eq!(
    Integer::rounding_from(Float::from(1.5), RoundingMode::Nearest).to_debug_string(),
    "(2, Greater)"
);

assert_eq!(
    Integer::rounding_from(Float::from(-1.5), RoundingMode::Floor).to_debug_string(),
    "(-2, Less)"
);
assert_eq!(
    Integer::rounding_from(Float::from(-1.5), RoundingMode::Ceiling).to_debug_string(),
    "(-1, Greater)"
);
assert_eq!(
    Integer::rounding_from(Float::from(-1.5), RoundingMode::Nearest).to_debug_string(),
    "(-2, Less)"
);
source§

impl RoundingFrom<Float> for Natural

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (Natural, Ordering)

Converts a Float to a Natural, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN or positive infinity, the function will panic regardless of the rounding mode.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, or if the Float is NaN or positive infinity.

Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(
    Natural::rounding_from(Float::from(1.5), RoundingMode::Floor).to_debug_string(),
    "(1, Less)"
);
assert_eq!(
    Natural::rounding_from(Float::from(1.5), RoundingMode::Ceiling).to_debug_string(),
    "(2, Greater)"
);
assert_eq!(
    Natural::rounding_from(Float::from(1.5), RoundingMode::Nearest).to_debug_string(),
    "(2, Greater)"
);

assert_eq!(
    Natural::rounding_from(Float::NEGATIVE_INFINITY, RoundingMode::Down).to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(Float::NEGATIVE_INFINITY, RoundingMode::Ceiling)
        .to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(Float::NEGATIVE_INFINITY, RoundingMode::Nearest)
        .to_debug_string(),
    "(0, Greater)"
);
source§

impl RoundingFrom<Float> for f32

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (f32, Ordering)

Converts a Float to a primitive float, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not exactly equal to any float of the target type, and rm is Exact.

Examples

See here.

source§

impl RoundingFrom<Float> for f64

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (f64, Ordering)

Converts a Float to a primitive float, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value. (Although a NaN is not comparable to anything, converting a NaN to a NaN will also return Ordering::Equals, indicating an exact conversion.)

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not exactly equal to any float of the target type, and rm is Exact.

Examples

See here.

source§

impl RoundingFrom<Float> for i128

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (i128, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for i16

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (i16, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for i32

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (i32, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for i64

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (i64, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for i8

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (i8, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for isize

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (isize, Ordering)

Converts a Float to a signed primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is less than the minimum representable value of the signed type (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the signed type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is smaller than the minimum representable value of the signed type and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the signed type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for u128

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (u128, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for u16

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (u16, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for u32

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (u32, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for u64

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (u64, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for u8

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (u8, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl RoundingFrom<Float> for usize

source§

fn rounding_from(f: Float, rm: RoundingMode) -> (usize, Ordering)

Converts a Float to an unsigned primitive integer, using a specified RoundingMode and taking the Float by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

If the Float is negative (including negative infinity), then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Float is greater than the maximum representable value of the unsigned type (including infinity), then it will be rounded to the maximum value when the RoundingMode is Floor, Down, or Nearest. Otherwise, this function will panic.

If the Float is NaN, the function will panic regardless of the rounding mode.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if the Float is not an integer and rm is Exact, or if the Float is less than zero and rm is not Down, Ceiling, or Nearest, if the Float is greater than the maximum representable value of the unsigned type and rm is not Down, Floor, or Nearest, or if the Float is NaN.

Examples

See here.

source§

impl SciMantissaAndExponent<Float, i64> for Float

source§

fn sci_mantissa_and_exponent(self) -> (Float, i64)

Returns a Float’s scientific mantissa and exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a Float. $$ f(x) = (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor). $$

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::ONE.sci_mantissa_and_exponent(), (Float::ONE, 0));

let (m, e) = Float::from(std::f64::consts::PI).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.5707963267948966");
assert_eq!(e, 1);

let (m, e) = Float::from(Natural::from(3u32).pow(50u64)).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.187662594419065093441695");
assert_eq!(e, 79);

let (m, e) = Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
    .sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.683979953059212693885095551367");
assert_eq!(e, -80);
source§

fn sci_exponent(self) -> i64

Returns a Float’s scientific exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. $$ f(x) = \lfloor \log_2 |x| \rfloor. $$

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::ONE.sci_exponent(), 0);
assert_eq!(Float::from(std::f64::consts::PI).sci_exponent(), 1);
assert_eq!(Float::from(Natural::from(3u32).pow(50u64)).sci_exponent(), 79);
assert_eq!(
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0.sci_exponent(),
    -80
);
source§

fn from_sci_mantissa_and_exponent( sci_mantissa: Float, sci_exponent: i64 ) -> Option<Float>

Constructs a Float from its scientific mantissa and exponent.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_i}m_i. $$

If the mantissa is zero or not finite, this function panics. If it is finite but not in the interval $[1, 2)$, this function returns None.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{FromStringBase, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::from_sci_mantissa_and_exponent(Float::ONE, 0).unwrap(), 1);
assert_eq!(
    Float::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.921fb54442d18#53").unwrap(),
        1
    ).unwrap(),
    std::f64::consts::PI
);
assert_eq!(
    Float::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.300aa7e1b65fa13bc792#80").unwrap(),
        79
    ).unwrap(),
    Natural::from(3u32).pow(50u64)
);
assert_eq!(
    Float::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.af194f6982497a23f9dc546d6#100").unwrap(),
        -80
    ).unwrap(),
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl<'a> SciMantissaAndExponent<Float, i64, Float> for &'a Float

source§

fn sci_mantissa_and_exponent(self) -> (Float, i64)

Returns a Float’s scientific mantissa and exponent, taking the Float by reference.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a Float. $$ f(x) = (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor). $$

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!((&Float::ONE).sci_mantissa_and_exponent(), (Float::ONE, 0));

let (m, e): (Float, i64) = (&Float::from(std::f64::consts::PI))
    .sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.5707963267948966");
assert_eq!(e, 1);

let (m, e): (Float, i64) = (&Float::from(Natural::from(3u32).pow(50u64)))
    .sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.187662594419065093441695");
assert_eq!(e, 79);

let (m, e): (Float, i64) =
    (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
        .sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.683979953059212693885095551367");
assert_eq!(e, -80);
source§

fn sci_exponent(self) -> i64

Returns a Float’s scientific exponent, taking the Float by reference.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. $$ f(x) = \lfloor \log_2 |x| \rfloor. $$

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is zero or not finite.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(&Float::ONE), 0);
assert_eq!(<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(
    &Float::from(std::f64::consts::PI)),
    1
);
assert_eq!(<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(
    &Float::from(Natural::from(3u32).pow(50u64))),
    79
);
assert_eq!(<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(
    &Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0),
    -80
);
source§

fn from_sci_mantissa_and_exponent( sci_mantissa: Float, sci_exponent: i64 ) -> Option<Float>

Constructs a Float from its scientific mantissa and exponent.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_i}m_i. $$

If the mantissa is zero or not finite, this function panics. If it is finite but not in the interval $[1, 2)$, this function returns None.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{FromStringBase, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Float::from_sci_mantissa_and_exponent(Float::ONE, 0).unwrap(), 1);
assert_eq!(
    <&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.921fb54442d18#53").unwrap(),
        1
    ).unwrap(),
    std::f64::consts::PI
);
assert_eq!(
    <&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.300aa7e1b65fa13bc792#80").unwrap(),
        79
    ).unwrap(),
    Natural::from(3u32).pow(50u64)
);
assert_eq!(
    <&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
        Float::from_string_base(16, "0x1.af194f6982497a23f9dc546d6#100").unwrap(),
        -80
    ).unwrap(),
    Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl<'a> SciMantissaAndExponent<f32, i64, Float> for &'a Float

source§

fn sci_mantissa_and_exponent(self) -> (f32, i64)

Returns a Float’s scientific mantissa and exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a primitive float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor). $$

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is zero or not finite.

Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: i64 ) -> Option<Float>

Constructs a Float from its scientific mantissa and exponent.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_i}m_i. $$

If the mantissa is zero or not finite, this function panics. If it is finite but not in the interval $[1, 2)$, this function returns None.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

fn sci_exponent(self) -> E

Extracts the scientific exponent from a number.
source§

impl<'a> SciMantissaAndExponent<f64, i64, Float> for &'a Float

source§

fn sci_mantissa_and_exponent(self) -> (f64, i64)

Returns a Float’s scientific mantissa and exponent, taking the Float by value.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a primitive float. The conversion might not be exact, so we round to the nearest float using the Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor). $$

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

Panics

Panics if self is zero or not finite.

Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: i64 ) -> Option<Float>

Constructs a Float from its scientific mantissa and exponent.

When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.

$$ f(x) = 2^{e_i}m_i. $$

If the mantissa is zero or not finite, this function panics. If it is finite but not in the interval $[1, 2)$, this function returns None.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

fn sci_exponent(self) -> E

Extracts the scientific exponent from a number.
source§

impl Sign for Float

source§

fn sign(&self) -> Ordering

Returns the sign of a Float.

Returns Greater if the sign is positive and Less if the sign is negative. Never returns Equal. Positive infinity and positive zero have a positive sign, and negative infinity and negative zero have a negative sign.

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is NaN.

Examples
use malachite_base::num::arithmetic::traits::Sign;
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero
};
use malachite_float::Float;
use std::cmp::Ordering;

assert_eq!(Float::INFINITY.sign(), Ordering::Greater);
assert_eq!(Float::NEGATIVE_INFINITY.sign(), Ordering::Less);
assert_eq!(Float::ZERO.sign(), Ordering::Greater);
assert_eq!(Float::NEGATIVE_ZERO.sign(), Ordering::Less);
assert_eq!(Float::ONE.sign(), Ordering::Greater);
assert_eq!(Float::NEGATIVE_ONE.sign(), Ordering::Less);
source§

impl<'a> SignificantBits for &'a Float

source§

fn significant_bits(self) -> u64

Returns the number of significant bits of a Float. This is defined as follows:

$$ f(\text{NaN}) = f(\pm\infty) = f(\pm 0.0) = 1, $$

and, if $x$ is finite and nonzero,

$$ f(x) = p, $$

where $p$ is the precision of $x$.

See also the complexity function.

Worst-case complexity

Constant time and additional memory.

Examples
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::Float;

assert_eq!(Float::NAN.significant_bits(), 1);
assert_eq!(Float::ONE.significant_bits(), 1);
assert_eq!(Float::one_prec(100).significant_bits(), 100);
assert_eq!(Float::from(std::f64::consts::PI).significant_bits(), 53);
assert_eq!(Float::power_of_2(100u64).significant_bits(), 1);
assert_eq!(Float::power_of_2(-100i64).significant_bits(), 1);
source§

impl<'a> TryFrom<&'a Float> for Integer

source§

fn try_from(f: &'a Float) -> Result<Integer, Self::Error>

Converts a Float to an Integer, taking the Float by reference. If the Float is not equal to an integer, an error is returned.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::SignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(Integer::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(Integer::try_from(&Float::from(123.0)).unwrap(), 123);
assert_eq!(Integer::try_from(&Float::from(-123.0)).unwrap(), -123);

assert_eq!(Integer::try_from(&Float::from(1.5)), Err(FloatNonIntegerOrOutOfRange));
assert_eq!(Integer::try_from(&Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Integer::try_from(&Float::NAN), Err(FloatInfiniteOrNan));
§

type Error = SignedFromFloatError

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

impl<'a> TryFrom<&'a Float> for Natural

source§

fn try_from(f: &'a Float) -> Result<Natural, Self::Error>

Converts a Float to a Natural, taking the Float by reference. If the Float is not equal to a non-negative integer, an error is returned.

Both positive and negative zero convert to a Natural zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::UnsignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(Natural::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(Natural::try_from(&Float::from(123.0)).unwrap(), 123);

assert_eq!(Natural::try_from(&Float::from(-123.0)), Err(FloatNegative));
assert_eq!(Natural::try_from(&Float::from(1.5)), Err(FloatNonIntegerOrOutOfRange));
assert_eq!(Natural::try_from(&Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Natural::try_from(&Float::NAN), Err(FloatInfiniteOrNan));
§

type Error = UnsignedFromFloatError

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

impl<'a> TryFrom<&'a Float> for Rational

source§

fn try_from(x: &'a Float) -> Result<Rational, Self::Error>

Converts a Float to a Rational, taking the Float by reference. If the Float is not finite, an error is returned.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::conversion::rational_from_float::RationalFromFloatError;
use malachite_float::Float;
use malachite_q::Rational;

assert_eq!(Rational::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(Rational::try_from(&Float::from(1.5)).unwrap().to_string(), "3/2");
assert_eq!(Rational::try_from(&Float::from(-1.5)).unwrap().to_string(), "-3/2");

assert_eq!(Rational::try_from(&Float::INFINITY), Err(RationalFromFloatError));
assert_eq!(Rational::try_from(&Float::NAN), Err(RationalFromFloatError));
§

type Error = RationalFromFloatError

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

impl<'a> TryFrom<&'a Float> for f32

source§

fn try_from(f: &'a Float) -> Result<f32, Self::Error>

Converts a Float to a primitive float, taking the Float by reference. If the Float is not equal to a primitive float of the given type, an error is returned.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

§

type Error = FloatFromFloatError

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

impl<'a> TryFrom<&'a Float> for f64

source§

fn try_from(f: &'a Float) -> Result<f64, Self::Error>

Converts a Float to a primitive float, taking the Float by reference. If the Float is not equal to a primitive float of the given type, an error is returned.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

§

type Error = FloatFromFloatError

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

impl<'a> TryFrom<&'a Float> for i128

source§

fn try_from(f: &'a Float) -> Result<i128, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for i16

source§

fn try_from(f: &'a Float) -> Result<i16, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for i32

source§

fn try_from(f: &'a Float) -> Result<i32, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for i64

source§

fn try_from(f: &'a Float) -> Result<i64, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for i8

source§

fn try_from(f: &'a Float) -> Result<i8, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for isize

source§

fn try_from(f: &'a Float) -> Result<isize, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by reference. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<'a> TryFrom<&'a Float> for u128

source§

fn try_from(f: &'a Float) -> Result<u128, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Float> for u16

source§

fn try_from(f: &'a Float) -> Result<u16, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Float> for u32

source§

fn try_from(f: &'a Float) -> Result<u32, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Float> for u64

source§

fn try_from(f: &'a Float) -> Result<u64, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Float> for u8

source§

fn try_from(f: &'a Float) -> Result<u8, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Float> for usize

source§

fn try_from(f: &'a Float) -> Result<usize, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by reference. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<'a> TryFrom<&'a Rational> for Float

source§

fn try_from(x: &'a Rational) -> Result<Float, Self::Error>

Converts a Rational to an Float, taking the Rational by reference. If the Rational’s denominator is not a power of 2, an error is returned.

The Float’s precision is the number of significant bits of the numerator of the Rational.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::conversion::primitive_float_from_rational::FloatFromRationalError;
use malachite_q::Rational;

assert_eq!(Float::try_from(&Rational::ZERO).unwrap(), 0);
assert_eq!(Float::try_from(&Rational::from_signeds(1, 8)).unwrap(), 0.125);
assert_eq!(Float::try_from(&Rational::from_signeds(-1, 8)).unwrap(), -0.125);

assert_eq!(Float::try_from(&Rational::from_signeds(1, 3)), Err(FloatFromRationalError));
assert_eq!(Float::try_from(&Rational::from_signeds(-1, 3)), Err(FloatFromRationalError));
§

type Error = FloatFromRationalError

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

impl TryFrom<Float> for Integer

source§

fn try_from(f: Float) -> Result<Integer, Self::Error>

Converts a Float to an Integer, taking the Float by value. If the Float is not equal to an integer, an error is returned.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::SignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;

assert_eq!(Integer::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(Integer::try_from(Float::from(123.0)).unwrap(), 123);
assert_eq!(Integer::try_from(Float::from(-123.0)).unwrap(), -123);

assert_eq!(Integer::try_from(Float::from(1.5)), Err(FloatNonIntegerOrOutOfRange));
assert_eq!(Integer::try_from(Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Integer::try_from(Float::NAN), Err(FloatInfiniteOrNan));
§

type Error = SignedFromFloatError

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

impl TryFrom<Float> for Natural

source§

fn try_from(f: Float) -> Result<Natural, Self::Error>

Converts a Float to a Natural, taking the Float by value. If the Float is not equal to a non-negative integer, an error is returned.

Both positive and negative zero convert to a Natural zero.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is f.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::UnsignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;

assert_eq!(Natural::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(Natural::try_from(Float::from(123.0)).unwrap(), 123);

assert_eq!(Natural::try_from(Float::from(-123.0)), Err(FloatNegative));
assert_eq!(Natural::try_from(Float::from(1.5)), Err(FloatNonIntegerOrOutOfRange));
assert_eq!(Natural::try_from(Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Natural::try_from(Float::NAN), Err(FloatInfiniteOrNan));
§

type Error = UnsignedFromFloatError

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

impl TryFrom<Float> for Rational

source§

fn try_from(x: Float) -> Result<Rational, Self::Error>

Converts a Float to a Rational, taking the Float by value. If the Float is not finite, an error is returned.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is x.complexity().

Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::conversion::rational_from_float::RationalFromFloatError;
use malachite_float::Float;
use malachite_q::Rational;

assert_eq!(Rational::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(Rational::try_from(Float::from(1.5)).unwrap().to_string(), "3/2");
assert_eq!(Rational::try_from(Float::from(-1.5)).unwrap().to_string(), "-3/2");

assert_eq!(Rational::try_from(Float::INFINITY), Err(RationalFromFloatError));
assert_eq!(Rational::try_from(Float::NAN), Err(RationalFromFloatError));
§

type Error = RationalFromFloatError

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

impl TryFrom<Float> for f32

source§

fn try_from(f: Float) -> Result<f32, Self::Error>

Converts a Float to a primitive float, taking the Float by value. If the Float is not equal to a primitive float of the given type, an error is returned.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

§

type Error = FloatFromFloatError

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

impl TryFrom<Float> for f64

source§

fn try_from(f: Float) -> Result<f64, Self::Error>

Converts a Float to a primitive float, taking the Float by value. If the Float is not equal to a primitive float of the given type, an error is returned.

Worst-case complexity

Constant time and additional memory.

Examples

See here.

§

type Error = FloatFromFloatError

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

impl TryFrom<Float> for i128

source§

fn try_from(f: Float) -> Result<i128, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for i16

source§

fn try_from(f: Float) -> Result<i16, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for i32

source§

fn try_from(f: Float) -> Result<i32, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for i64

source§

fn try_from(f: Float) -> Result<i64, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for i8

source§

fn try_from(f: Float) -> Result<i8, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for isize

source§

fn try_from(f: Float) -> Result<isize, Self::Error>

Converts a Float to a primitive signed integer, taking the Float by value. If the Float is not equal to a signed primitive integer of the given type, an error is returned.

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<Float> for u128

source§

fn try_from(f: Float) -> Result<u128, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Float> for u16

source§

fn try_from(f: Float) -> Result<u16, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Float> for u32

source§

fn try_from(f: Float) -> Result<u32, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Float> for u64

source§

fn try_from(f: Float) -> Result<u64, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Float> for u8

source§

fn try_from(f: Float) -> Result<u8, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Float> for usize

source§

fn try_from(f: Float) -> Result<usize, Self::Error>

Converts a Float to a primitive unsigned integer, taking the Float by value. If the Float is not equal to an unsigned primitive integer of the given type, an error is returned.

Both positive and negative zero convert to a primitive unsigned integer zero.

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<Rational> for Float

source§

fn try_from(x: Rational) -> Result<Float, Self::Error>

Converts a Rational to an Float, taking the Rational by value. If the Rational’s denominator is not a power of 2, an error is returned.

The Float’s precision is the number of significant bits of the numerator of the Rational.

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits().

Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::conversion::primitive_float_from_rational::FloatFromRationalError;
use malachite_q::Rational;

assert_eq!(Float::try_from(Rational::ZERO).unwrap(), 0);
assert_eq!(Float::try_from(Rational::from_signeds(1, 8)).unwrap(), 0.125);
assert_eq!(Float::try_from(Rational::from_signeds(-1, 8)).unwrap(), -0.125);

assert_eq!(Float::try_from(Rational::from_signeds(1, 3)), Err(FloatFromRationalError));
assert_eq!(Float::try_from(Rational::from_signeds(-1, 3)), Err(FloatFromRationalError));
§

type Error = FloatFromRationalError

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

impl Two for Float

The constant 2.0, with precision 1.

source§

const TWO: Float = _

source§

impl Zero for Float

The constant 0.0 (positive zero), with precision 1.

source§

const ZERO: Float = _

Auto Trait Implementations§

§

impl RefUnwindSafe for Float

§

impl Send for Float

§

impl Sync for Float

§

impl Unpin for Float

§

impl UnwindSafe for Float

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<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> Same for T

§

type Output = T

Should always be Self
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> ToLowerHexString for T
where T: LowerHex,

source§

fn to_lower_hex_string(&self) -> String

Returns the String produced by Ts LowerHex implementation.

Examples
use malachite_base::strings::ToLowerHexString;

assert_eq!(50u64.to_lower_hex_string(), "32");
assert_eq!((-100i16).to_lower_hex_string(), "ff9c");
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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

source§

fn wrapping_into(self) -> U