Struct malachite_q::Rational

source ·
pub struct Rational { /* private fields */ }
Expand description

A rational number.

Rationals whose numerator and denominator have 64 significant bits or fewer 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 Rational

source

pub fn approx_log(&self) -> f64

Calculates the approximate natural logarithm of a positive Rational.

$f(x) = (1+\epsilon)(\log x)$, where $|\epsilon| < 2^{-52}.$

§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, PowerOf2};
use malachite_base::num::float::NiceFloat;
use malachite_q::Rational;

assert_eq!(NiceFloat(Rational::from(10i32).approx_log()), NiceFloat(2.3025850929940455));
assert_eq!(
    NiceFloat(Rational::from(10i32).pow(100u64).approx_log()),
    NiceFloat(230.25850929940455)
);
assert_eq!(
    NiceFloat(Rational::power_of_2(1000000u64).approx_log()),
    NiceFloat(693147.1805599453)
);
assert_eq!(
    NiceFloat(Rational::power_of_2(-1000000i64).approx_log()),
    NiceFloat(-693147.1805599453)
);

This is equivalent to fmpz_dlog from fmpz/dlog.c, FLINT 2.7.1.

source§

impl Rational

source

pub fn floor_log_base_2_abs(&self) -> i64

Returns the floor of the base-2 logarithm of the absolute value of a nonzero Rational.

$f(x) = \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.

§Examples
use malachite_q::Rational;

assert_eq!(Rational::from(3u32).floor_log_base_2_abs(), 1);
assert_eq!(Rational::from_signeds(1, 3).floor_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(1, 4).floor_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(1, 5).floor_log_base_2_abs(), -3);

assert_eq!(Rational::from(-3).floor_log_base_2_abs(), 1);
assert_eq!(Rational::from_signeds(-1, 3).floor_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(-1, 4).floor_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(-1, 5).floor_log_base_2_abs(), -3);
source

pub fn ceiling_log_base_2_abs(&self) -> i64

Returns the ceiling of the base-2 logarithm of the absolute value of a nonzero Rational.

$f(x) = \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 less than or equal to zero.

§Examples
use malachite_q::Rational;

assert_eq!(Rational::from(3u32).ceiling_log_base_2_abs(), 2);
assert_eq!(Rational::from_signeds(1, 3).ceiling_log_base_2_abs(), -1);
assert_eq!(Rational::from_signeds(1, 4).ceiling_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(1, 5).ceiling_log_base_2_abs(), -2);

assert_eq!(Rational::from(-3).ceiling_log_base_2_abs(), 2);
assert_eq!(Rational::from_signeds(-1, 3).ceiling_log_base_2_abs(), -1);
assert_eq!(Rational::from_signeds(-1, 4).ceiling_log_base_2_abs(), -2);
assert_eq!(Rational::from_signeds(-1, 5).ceiling_log_base_2_abs(), -2);
source§

impl Rational

source

pub fn cmp_complexity(&self, other: &Rational) -> Ordering

Compares two Rationals according to their complexity.

Complexity is defined as follows: If two Rationals have different denominators, then the one with the larger denominator is more complex. If they have the same denominator, then the one whose numerator is further from zero is more complex. Finally, if $q > 0$, then $q$ is simpler than $-q$.

The Rationals ordered by complexity look like this: $$ 0, 1, -1, 2, -2, \ldots, 1/2, -1/2, 3/2, -3/2, \ldots, 1/3, -1/3, 2/3, -2/3, \ldots, \ldots. $$ This order is a well-order, and the order type of the Rationals under this order is $\omega^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_q::Rational;
use std::cmp::Ordering;

assert_eq!(
    Rational::from_signeds(1, 2).cmp_complexity(&Rational::from_signeds(1, 3)),
    Ordering::Less
);
assert_eq!(
    Rational::from_signeds(1, 2).cmp_complexity(&Rational::from_signeds(3, 2)),
    Ordering::Less
);
assert_eq!(
    Rational::from_signeds(1, 2).cmp_complexity(&Rational::from_signeds(-1, 2)),
    Ordering::Less
);
source§

impl Rational

source

pub fn from_continued_fraction<I: Iterator<Item = Natural>>( floor: Integer, xs: I ) -> Rational

Converts a finite continued fraction to a Rational, taking the inputs by value.

The input has two components. The first is the first value of the continued fraction, which may be any Integer and is equal to the floor of the Rational. The second is an iterator of the remaining values, which must all be positive. Using the standard notation for continued fractions, the first value is the number before the semicolon, and the second value contains the remaining numbers.

Each rational number has two continued fraction representations. Either one is a valid input.

$f(a_0, (a_1, a_2, a_3, \ldots)) = [a_0; a_1, a_2, a_3, \ldots]$.

§Worst-case complexity

$T(n, m) = O((nm)^2 \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is max(floor.significant_bits(), xs.map(Natural::significant_bits).max()), and $m$ is xs.count().

§Panics

Panics if any Natural in xs is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

let xs = vec_from_str("[1, 2]").unwrap().into_iter();
assert_eq!(Rational::from_continued_fraction(Integer::ZERO, xs).to_string(), "2/3");

let xs = vec_from_str("[7, 16]").unwrap().into_iter();
assert_eq!(Rational::from_continued_fraction(Integer::from(3), xs).to_string(), "355/113");
source

pub fn from_continued_fraction_ref<'a, I: Iterator<Item = &'a Natural>>( floor: &Integer, xs: I ) -> Rational

Converts a finite continued fraction to a Rational, taking the inputs by reference.

The input has two components. The first is the first value of the continued fraction, which may be any Integer and is equal to the floor of the Rational. The second is an iterator of the remaining values, which must all be positive. Using the standard notation for continued fractions, the first value is the number before the semicolon, and the second value contains the remaining numbers.

Each rational number has two continued fraction representations. Either one is a valid input.

$f(a_0, (a_1, a_2, a_3, \ldots)) = [a_0; a_1, a_2, a_3, \ldots]$.

§Worst-case complexity

$T(n, m) = O((nm)^2 \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is max(floor.significant_bits(), xs.map(Natural::significant_bits).max()), and $m$ is xs.count().

§Panics

Panics if any Natural in xs is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

let xs = vec_from_str("[1, 2]").unwrap();
assert_eq!(
    Rational::from_continued_fraction_ref(&Integer::ZERO, xs.iter()).to_string(),
    "2/3"
);

let xs = vec_from_str("[7, 16]").unwrap();
assert_eq!(
    Rational::from_continued_fraction_ref(&Integer::from(3), xs.iter()).to_string(),
    "355/113"
);
source§

impl Rational

source

pub fn digits(&self, base: &Natural) -> (Vec<Natural>, RationalDigits)

Returns the base-$b$ digits of a Rational.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is an iterator of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(b-1)$s.

If the Rational has a small denominator, it may be more efficient to use to_digits or into_digits instead. These functions compute the entire repeating portion of the repeating digits.

For example, consider these two expressions:

  • Rational::from_signeds(1, 7).digits(Natural::from(10u32)).1.nth(1000)
  • Rational::from_signeds(1, 7).into_digits(Natural::from(10u32)).1[1000]

Both get the thousandth digit after the decimal point of 1/7. The first way explicitly calculates each digit after the decimal point, whereas the second way determines that 1/7 is 0.(142857), with the 142857 repeating, and takes 1000 % 6 == 4 to determine that the thousandth digit is 5. But when the Rational has a large denominator, the second way is less efficient.

§Worst-case complexity per iteration

$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(), base.significant_bits()).

§Panics

Panics if base is less than 2.

§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(prefix_to_string(after_point, 10), "[]");

let (before_point, after_point) =
        Rational::from_signeds(22, 7).digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(prefix_to_string(after_point, 10), "[1, 4, 2, 8, 5, 7, 1, 4, 2, 8, ...]");
source§

impl Rational

source

pub fn from_digits( base: &Natural, before_point: Vec<Natural>, after_point: RationalSequence<Natural> ) -> Rational

Converts base-$b$ digits to a Rational. The inputs are taken by value.

The input consists of the digits of the integer portion of the Rational and the digits of the fractional portion. The integer-portion digits are ordered from least- to most-significant, and the fractional-portion digits from most- to least.

The fractional-portion digits may end in infinitely many zeros or $(b-1)$s; these are handled correctly.

§Worst-case complexity

$T(n, m) = O(nm \log (nm)^2 \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is max(before_point.len(), after_point.component_len()), and $m$ is base.significant_bits().

§Panics

Panics if base is less than 2.

§Examples
use malachite_base::rational_sequences::RationalSequence;
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let before_point = vec_from_str("[3]").unwrap();
let after_point = RationalSequence::from_vecs(
    Vec::new(),
    vec_from_str("[1, 4, 2, 8, 5, 7]").unwrap(),
);
assert_eq!(
    Rational::from_digits(&Natural::from(10u32), before_point, after_point).to_string(),
    "22/7"
);

// 21.34565656...
let before_point = vec_from_str("[1, 2]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[3, 4]").unwrap(),
    vec_from_str("[5, 6]").unwrap(),
);
assert_eq!(
    Rational::from_digits(&Natural::from(10u32), before_point, after_point).to_string(),
    "105661/4950"
);
source

pub fn from_digits_ref( base: &Natural, before_point: &[Natural], after_point: &RationalSequence<Natural> ) -> Rational

Converts base-$b$ digits to a Rational. The inputs are taken by reference.

The input consists of the digits of the integer portion of the Rational and the digits of the fractional portion. The integer-portion digits are ordered from least- to most-significant, and the fractional-portion digits from most- to least.

The fractional-portion digits may end in infinitely many zeros or $(b-1)$s; these are handled correctly.

§Worst-case complexity

$T(n, m) = O(nm \log (nm)^2 \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is max(before_point.len(), after_point.component_len()), and $m$ is base.significant_bits().

§Panics

Panics if base is less than 2.

§Examples
use malachite_base::rational_sequences::RationalSequence;
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let before_point = vec_from_str("[3]").unwrap();
let after_point = RationalSequence::from_vecs(
    Vec::new(),
    vec_from_str("[1, 4, 2, 8, 5, 7]").unwrap(),
);
assert_eq!(
    Rational::from_digits_ref(&Natural::from(10u32), &before_point, &after_point)
        .to_string(),
    "22/7"
);

// 21.34565656...
let before_point = vec_from_str("[1, 2]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[3, 4]").unwrap(),
    vec_from_str("[5, 6]").unwrap(),
);
assert_eq!(
    Rational::from_digits_ref(&Natural::from(10u32), &before_point, &after_point)
        .to_string(),
    "105661/4950"
);
source§

impl Rational

source

pub fn from_power_of_2_digits( log_base: u64, before_point: Vec<Natural>, after_point: RationalSequence<Natural> ) -> Rational

Converts base-$2^k$ digits to a Rational. The inputs are taken by value.

The input consists of the digits of the integer portion of the Rational and the digits of the fractional portion. The integer-portion digits are ordered from least- to most-significant, and the fractional-portion digits from most- to least.

The fractional-portion digits may end in infinitely many zeros or $(2^k-1)$s; these are handled correctly.

§Worst-case complexity

$T(n, m) = O(nm)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is max(before_point.len(), after_point.component_len()), and $m$ is base.significant_bits().

§Panics

Panics if log_base is zero.

§Examples
use malachite_base::rational_sequences::RationalSequence;
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;

let before_point = vec_from_str("[1, 1]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[0]").unwrap(),
    vec_from_str("[0, 0, 1]").unwrap(),
);
assert_eq!(
    Rational::from_power_of_2_digits(1, before_point, after_point).to_string(),
    "43/14"
);

// 21.34565656..._32
let before_point = vec_from_str("[1, 2]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[3, 4]").unwrap(),
    vec_from_str("[5, 6]").unwrap(),
);
assert_eq!(
    Rational::from_power_of_2_digits(5, before_point, after_point).to_string(),
    "34096673/523776"
);
source

pub fn from_power_of_2_digits_ref( log_base: u64, before_point: &[Natural], after_point: &RationalSequence<Natural> ) -> Rational

Converts base-$2^k$ digits to a Rational. The inputs are taken by reference.

The input consists of the digits of the integer portion of the Rational and the digits of the fractional portion. The integer-portion digits are ordered from least- to most-significant, and the fractional-portion digits from most- to least.

The fractional-portion digits may end in infinitely many zeros or $(2^k-1)$s; these are handled correctly.

§Worst-case complexity

$T(n, m) = O(nm)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is max(before_point.len(), after_point.component_len()), and $m$ is base.significant_bits().

§Panics

Panics if log_base is zero.

§Examples
use malachite_base::rational_sequences::RationalSequence;
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;

let before_point = vec_from_str("[1, 1]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[0]").unwrap(),
    vec_from_str("[0, 0, 1]").unwrap(),
);
assert_eq!(
    Rational::from_power_of_2_digits_ref(1, &before_point, &after_point).to_string(),
    "43/14"
);

// 21.34565656..._32
let before_point = vec_from_str("[1, 2]").unwrap();
let after_point = RationalSequence::from_vecs(
    vec_from_str("[3, 4]").unwrap(),
    vec_from_str("[5, 6]").unwrap(),
);
assert_eq!(
    Rational::from_power_of_2_digits_ref(5, &before_point, &after_point).to_string(),
    "34096673/523776"
);
source§

impl Rational

source

pub fn power_of_2_digits( &self, log_base: u64 ) -> (Vec<Natural>, RationalPowerOf2Digits)

Returns the base-$2^k$ digits of a Rational.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is an iterator of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(2^k-1)$s.

If the Rational has a small denominator, it may be more efficient to use to_power_of_2_digits or into_power_of_2_digits instead. These functions compute the entire repeating portion of the repeating digits.

For example, consider these two expressions:

  • Rational::from_signeds(1, 7).power_of_2_digits(1).1.nth(1000)
  • Rational::from_signeds(1, 7).into_power_of_2_digits(1).1[1000]

Both get the thousandth digit after the binary point of 1/7. The first way explicitly calculates each bit after the binary point, whereas the second way determines that 1/7 is 0.(001), with the 001 repeating, and takes 1000 % 3 == 1 to determine that the thousandth bit is 0. But when the Rational has a large denominator, the second way is less efficient.

§Worst-case complexity per iteration

$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(), base).

§Panics

Panics if log_base is zero.

§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(prefix_to_string(after_point, 10), "[]");

let (before_point, after_point) = Rational::from_signeds(22, 7).power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(prefix_to_string(after_point, 10), "[0, 0, 1, 0, 0, 1, 0, 0, 1, 0, ...]");

let (before_point, after_point) = Rational::from_signeds(22, 7).power_of_2_digits(10);
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(
    prefix_to_string(after_point, 10),
    "[146, 292, 585, 146, 292, 585, 146, 292, 585, 146, ...]"
);
source§

impl Rational

source

pub fn into_digits( self, base: &Natural ) -> (Vec<Natural>, RationalSequence<Natural>)

Returns the base-$b$ digits of a Rational, taking the Rational by value.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is a RationalSequence of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(b-1)$s.

The fractional portion may be very large; the length of the repeating part may be almost as large as the denominator. If the Rational has a large denominator, consider using digits instead, which returns an iterator. That function computes the fractional digits lazily and doesn’t need to compute the entire repeating part.

§Worst-case complexity

$T(n, m) = O(m2^n)$

$M(n, m) = O(m2^n)$

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

§Panics

Panics if base is less than 2.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).into_digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[]");

let (before_point, after_point) =
        Rational::from_signeds(22, 7).into_digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[[1, 4, 2, 8, 5, 7]]");
source

pub fn to_digits( &self, base: &Natural ) -> (Vec<Natural>, RationalSequence<Natural>)

Returns the base-$b$ digits of a Rational, taking the Rational by reference.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is a RationalSequence of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(b-1)$s.

The fractional portion may be very large; the length of the repeating part may be almost as large as the denominator. If the Rational has a large denominator, consider using digits instead, which returns an iterator. That function computes the fractional digits lazily and doesn’t need to compute the entire repeating part.

§Worst-case complexity

$T(n, m) = O(m2^n)$

$M(n, m) = O(m2^n)$

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

§Panics

Panics if base is less than 2.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).to_digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[]");

let (before_point, after_point) =
        Rational::from_signeds(22, 7).to_digits(&Natural::from(10u32));
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[[1, 4, 2, 8, 5, 7]]");
source§

impl Rational

source

pub fn into_power_of_2_digits( self, log_base: u64 ) -> (Vec<Natural>, RationalSequence<Natural>)

Returns the base-$2^k$ digits of a Rational, taking the Rational by value.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is a RationalSequence of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(2^k-1)$s.

The fractional portion may be very large; the length of the repeating part may be almost as large as the denominator. If the Rational has a large denominator, consider using power_of_2_digits instead, which returns an iterator. That function computes the fractional digits lazily and doesn’t need to compute the entire repeating part.

§Worst-case complexity

$T(n, m) = O(m2^n)$

$M(n, m) = O(m2^n)$

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

§Panics

Panics if log_base is zero.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).into_power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(after_point.to_string(), "[]");

let (before_point, after_point) = Rational::from_signeds(22, 7).into_power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(after_point.to_string(), "[[0, 0, 1]]");

let (before_point, after_point) = Rational::from_signeds(22, 7).into_power_of_2_digits(10);
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[[146, 292, 585]]");
source

pub fn to_power_of_2_digits( &self, log_base: u64 ) -> (Vec<Natural>, RationalSequence<Natural>)

Returns the base-$2^k$ digits of a Rational, taking the Rational by reference.

The output has two components. The first is a Vec of the digits of the integer portion of the Rational, least- to most-significant. The second is a RationalSequence of the digits of the fractional portion.

The output is in its simplest form: the integer-portion digits do not end with a zero, and the fractional-portion digits do not end with infinitely many zeros or $(2^k-1)$s.

The fractional portion may be very large; the length of the repeating part may be almost as large as the denominator. If the Rational has a large denominator, consider using power_of_2_digits instead, which returns an iterator. That function computes the fractional digits lazily and doesn’t need to compute the entire repeating part.

§Worst-case complexity

$T(n, m) = O(m2^n)$

$M(n, m) = O(m2^n)$

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

§Panics

Panics if log_base is zero.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

let (before_point, after_point) = Rational::from(3u32).to_power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(after_point.to_string(), "[]");

let (before_point, after_point) = Rational::from_signeds(22, 7).to_power_of_2_digits(1);
assert_eq!(before_point.to_debug_string(), "[1, 1]");
assert_eq!(after_point.to_string(), "[[0, 0, 1]]");

let (before_point, after_point) = Rational::from_signeds(22, 7).to_power_of_2_digits(10);
assert_eq!(before_point.to_debug_string(), "[3]");
assert_eq!(after_point.to_string(), "[[146, 292, 585]]");
source§

impl Rational

source

pub fn try_from_float_simplest<T: PrimitiveFloat>( x: T ) -> Result<Rational, RationalFromPrimitiveFloatError>

Converts a primitive float to the simplest Rational that rounds to that value.

To be more specific: Suppose the floating-point input is $x$. If $x$ is an integer, its Rational equivalent is returned. Otherwise, this function finds $a$ and $b$, which are the floating point predecessor and successor of $x$, and finds the simplest Rational in the open interval $(\frac{x + a}{2}, \frac{x + b}{2})$. “Simplicity” refers to low complexity. See Rational::cmp_complexity for a definition of complexity.

For example, 0.1f32 is converted to $1/10$ rather than to the exact value of the float, which is $13421773/134217728$. If you want the exact value, use Rational::from instead.

If the floating point value cannot be NaN or infinite, and error is returned.

§Worst-case complexity

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

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

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

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::conversion::from_primitive_float::RationalFromPrimitiveFloatError;
use malachite_q::Rational;

assert_eq!(Rational::try_from_float_simplest(0.0).to_debug_string(), "Ok(0)");
assert_eq!(Rational::try_from_float_simplest(1.5).to_debug_string(), "Ok(3/2)");
assert_eq!(Rational::try_from_float_simplest(-1.5).to_debug_string(), "Ok(-3/2)");
assert_eq!(Rational::try_from_float_simplest(0.1f32).to_debug_string(), "Ok(1/10)");
assert_eq!(Rational::try_from_float_simplest(0.33333334f32).to_debug_string(), "Ok(1/3)");
assert_eq!(
    Rational::try_from_float_simplest(f32::NAN),
    Err(RationalFromPrimitiveFloatError)
);
source§

impl Rational

source

pub const fn const_from_unsigneds( numerator: Limb, denominator: Limb ) -> Rational

Converts twoLimbs, representing a numerator and a denominator, to a Rational.

If denominator is zero, None is returned.

This function is const, so it may be used to define constants. When called at runtime, it is slower than Rational::from_unsigneds.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

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

§Examples
use malachite_q::Rational;

const TWO_THIRDS: Rational = Rational::const_from_unsigneds(2, 3);
assert_eq!(TWO_THIRDS, Rational::from_unsigneds(2u32, 3));

const TWO_THIRDS_ALT: Rational = Rational::const_from_unsigneds(22, 33);
assert_eq!(TWO_THIRDS, Rational::from_unsigneds(2u32, 3));
source

pub const fn const_from_signeds( numerator: SignedLimb, denominator: SignedLimb ) -> Rational

Converts twoSignedLimbs, representing a numerator and a denominator, to a Rational.

If denominator is zero, None is returned.

This function is const, so it may be used to define constants. When called at runtime, it is slower than Rational::from_signeds.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

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

§Examples
use malachite_q::Rational;

const NEGATIVE_TWO_THIRDS: Rational = Rational::const_from_signeds(-2, 3);
assert_eq!(NEGATIVE_TWO_THIRDS, Rational::from_signeds(-2, 3));

const NEGATIVE_TWO_THIRDS_ALT: Rational = Rational::const_from_signeds(-22, 33);
assert_eq!(NEGATIVE_TWO_THIRDS, Rational::from_signeds(-2, 3));
source

pub fn from_naturals(numerator: Natural, denominator: Natural) -> Rational

Converts two Naturals to a Rational, taking the Naturals by value.

The Naturals become the Rational’s numerator and denominator. Only non-negative Rationals can be produced with this function.

The denominator may not be zero.

The input Naturals may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Rational::from_naturals(Natural::from(4u32), Natural::from(6u32)).to_string(),
    "2/3"
);
assert_eq!(Rational::from_naturals(Natural::ZERO, Natural::from(6u32)), 0);
source

pub fn from_naturals_ref(numerator: &Natural, denominator: &Natural) -> Rational

Converts two Naturals to a Rational, taking the Naturals by reference.

The Naturals become the Rational’s numerator and denominator. Only non-negative Rationals can be produced with this function.

The denominator may not be zero.

The input Naturals may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Rational::from_naturals_ref(&Natural::from(4u32), &Natural::from(6u32)).to_string(),
    "2/3"
);
assert_eq!(Rational::from_naturals_ref(&Natural::ZERO, &Natural::from(6u32)), 0);
source

pub fn from_unsigneds<T: PrimitiveUnsigned>( numerator: T, denominator: T ) -> Rational
where Natural: From<T>,

Converts two unsigned primitive integers to a Rational.

The integers become the Rational’s numerator and denominator. Only non-negative Rationals can be produced with this function.

The denominator may not be zero.

The input integers may have common factors; this function reduces them.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::from_unsigneds(4u32, 6).to_string(), "2/3");
assert_eq!(Rational::from_unsigneds(0u32, 6), 0);
source

pub fn from_integers(numerator: Integer, denominator: Integer) -> Rational

Converts two Integers to a Rational, taking the Integers by value.

The absolute values of the Integers become the Rational’s numerator and denominator. The sign of the Rational is the sign of the Integers’ quotient.

The denominator may not be zero.

The input Integers may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Rational::from_integers(Integer::from(4), Integer::from(6)).to_string(),
    "2/3"
);
assert_eq!(
    Rational::from_integers(Integer::from(4), Integer::from(-6)).to_string(),
    "-2/3"
);
assert_eq!(Rational::from_integers(Integer::ZERO, Integer::from(6)), 0);
assert_eq!(Rational::from_integers(Integer::ZERO, Integer::from(-6)), 0);
source

pub fn from_integers_ref(numerator: &Integer, denominator: &Integer) -> Rational

Converts two Integers to a Rational, taking the Integers by reference.

The absolute values of the Integers become the Rational’s numerator and denominator. The sign of the Rational is the sign of the Integers’ quotient.

The denominator may not be zero.

The input Integers may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Rational::from_integers_ref(&Integer::from(4), &Integer::from(6)).to_string(),
    "2/3"
);
assert_eq!(
    Rational::from_integers_ref(&Integer::from(4), &Integer::from(-6)).to_string(),
    "-2/3"
);
assert_eq!(Rational::from_integers_ref(&Integer::ZERO, &Integer::from(6)), 0);
assert_eq!(Rational::from_integers_ref(&Integer::ZERO, &Integer::from(-6)), 0);
source

pub fn from_signeds<T: PrimitiveSigned>( numerator: T, denominator: T ) -> Rational
where Integer: From<T>,

Converts two signed primitive integers to a [Rational].

The absolute values of the integers become the Rational’s numerator and denominator. The sign of the Rational is the sign of the integers’ quotient.

The denominator may not be zero.

The input integers may have common factors; this function reduces them.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::from_signeds(4i8, 6).to_string(), "2/3");
assert_eq!(Rational::from_signeds(4i8, -6).to_string(), "-2/3");
assert_eq!(Rational::from_signeds(0i8, 6), 0);
assert_eq!(Rational::from_signeds(0i8, -6), 0);
source

pub fn from_sign_and_naturals( sign: bool, numerator: Natural, denominator: Natural ) -> Rational

Converts a sign and two Naturals to a Rational, taking the Naturals by value.

The Naturals become the Rational’s numerator and denominator, and the sign indicates whether the Rational should be non-negative. If the numerator is zero, then the Rational will be non-negative regardless of the sign.

The denominator may not be zero.

The input Naturals may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Rational::from_sign_and_naturals(
        true,
        Natural::from(4u32),
        Natural::from(6u32)
    ).to_string(),
    "2/3"
);
assert_eq!(
    Rational::from_sign_and_naturals(
        false,
        Natural::from(4u32),
        Natural::from(6u32)
    ).to_string(),
    "-2/3"
);
source

pub fn from_sign_and_naturals_ref( sign: bool, numerator: &Natural, denominator: &Natural ) -> Rational

Converts a sign and two Naturals to a Rational, taking the Naturals by reference.

The Naturals become the Rational’s numerator and denominator, and the sign indicates whether the Rational should be non-negative. If the numerator is zero, then the Rational will be non-negative regardless of the sign.

The denominator may not be zero.

The input Naturals may have common factors; this function reduces them.

§Worst-case complexity

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

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

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Rational::from_sign_and_naturals_ref(
        true,
        &Natural::from(4u32),
        &Natural::from(6u32)
    ).to_string(),
    "2/3"
);
assert_eq!(
    Rational::from_sign_and_naturals_ref(
        false,
        &Natural::from(4u32),
        &Natural::from(6u32)
    ).to_string(),
    "-2/3"
);
source

pub fn from_sign_and_unsigneds<T: PrimitiveUnsigned>( sign: bool, numerator: T, denominator: T ) -> Rational
where Natural: From<T>,

Converts a sign and two primitive unsigned integers to a Rational.

The integers become the Rational’s numerator and denominator, and the sign indicates whether the Rational should be non-negative. If the numerator is zero, then the Rational will be non-negative regardless of the sign.

The denominator may not be zero.

The input integers may have common factors; this function reduces them.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

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

§Panics

Panics if denominator is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::from_sign_and_unsigneds(true, 4u32, 6).to_string(), "2/3");
assert_eq!(Rational::from_sign_and_unsigneds(false, 4u32, 6).to_string(), "-2/3");
source§

impl Rational

source

pub const fn const_from_unsigned(x: Limb) -> Rational

Converts a Limb to a Rational.

This function is const, so it may be used to define constants.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;

const TEN: Rational = Rational::const_from_unsigned(10);
assert_eq!(TEN, 10);
source

pub const fn const_from_signed(x: SignedLimb) -> Rational

Converts a SignedLimb to a Rational.

This function is const, so it may be used to define constants.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;

const TEN: Rational = Rational::const_from_signed(10);
assert_eq!(TEN, 10);

const NEGATIVE_TEN: Rational = Rational::const_from_signed(-10);
assert_eq!(NEGATIVE_TEN, -10);
source§

impl Rational

source

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

Returns a Rational’s scientific mantissa and exponent, taking the Rational by value. An Ordering is also returned, indicating whether the returned mantissa and exponent represent a value that is less than, equal to, or greater than the absolute value of the Rational.

The Rational’s sign is ignored. This means that, for example, that rounding using Floor is equivalent to rounding using Down, even if the Rational is negative.

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 \log n \log\log n)$

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

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_q::Rational;
use std::cmp::Ordering;

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

test(
    Rational::from_signeds(1, 3),
    RoundingMode::Floor,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Down,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Ceiling,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Up,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Nearest,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Exact,
    None
);

test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Floor,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Down,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Ceiling,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Up,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Nearest,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(-1, 3),
    RoundingMode::Exact,
    None
);
source

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

Returns a Rational’s scientific mantissa and exponent, taking the Rational by reference. An Ordering is also returned, indicating whether the returned 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 \log n \log\log n)$

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

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_q::Rational;
use std::cmp::Ordering;

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

test(
    Rational::from_signeds(1, 3),
    RoundingMode::Floor,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Down,
    Some((1.3333333, -2, Ordering::Less))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Ceiling,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Up,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Nearest,
    Some((1.3333334, -2, Ordering::Greater))
);
test(
    Rational::from_signeds(1, 3),
    RoundingMode::Exact,
    None
);
source§

impl Rational

source

pub fn mutate_numerator<F: FnOnce(&mut Natural) -> T, T>(&mut self, f: F) -> T

Mutates the numerator of a Rational using a provided closure, and then returns whatever the closure returns.

After the closure executes, this function reduces the Rational.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let mut q = Rational::from_signeds(22, 7);
let ret = q.mutate_numerator(|x| {
    *x -= Natural::ONE;
    true
});
assert_eq!(q, 3);
assert_eq!(ret, true);
source

pub fn mutate_denominator<F: FnOnce(&mut Natural) -> T, T>(&mut self, f: F) -> T

Mutates the denominator of a Rational using a provided closure.

After the closure executes, this function reduces the Rational.

§Panics

Panics if the closure sets the denominator to zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let mut q = Rational::from_signeds(22, 7);
let ret = q.mutate_denominator(|x| {
    *x -= Natural::ONE;
    true
});
assert_eq!(q.to_string(), "11/3");
assert_eq!(ret, true);
source

pub fn mutate_numerator_and_denominator<F: FnOnce(&mut Natural, &mut Natural) -> T, T>( &mut self, f: F ) -> T

Mutates the numerator and denominator of a Rational using a provided closure.

After the closure executes, this function reduces the Rational.

§Panics

Panics if the closure sets the denominator to zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

let mut q = Rational::from_signeds(22, 7);
let ret = q.mutate_numerator_and_denominator(|x, y| {
    *x -= Natural::ONE;
    *y -= Natural::ONE;
    true
});
assert_eq!(q.to_string(), "7/2");
assert_eq!(ret, true);
source§

impl Rational

source

pub fn from_sci_string_simplest_with_options( s: &str, options: FromSciStringOptions ) -> Option<Rational>

Converts a string, possibly in scientfic notation, to a Rational. This function finds the simplest Rational which rounds to the target string according to the precision implied by the string.

Use FromSciStringOptions to specify the base (from 2 to 36, inclusive). The rounding mode option is ignored.

If the base is greater than 10, the higher digits are represented by the letters 'a' through 'z' or 'A' through 'Z'; the case doesn’t matter and doesn’t need to be consistent.

Exponents are allowed, and are indicated using the character 'e' or 'E'. If the base is 15 or greater, an ambiguity arises where it may not be clear whether 'e' is a digit or an exponent indicator. To resolve this ambiguity, always use a '+' or '-' sign after the exponent indicator when the base is 15 or greater.

The exponent itself is always parsed using base 10.

Decimal (or other-base) points are allowed.

If the string is unparseable, None is returned.

Here’s a more precise description of the function’s behavior. Suppose we are using base $b$, and the literal value of the string (as parsed by from_sci_string) is $q$, and the implied scale is $s$ (meaning $s$ digits are provided after the point; if the string is "123.456", then $s$ is 3). Then this function computes $\epsilon = b^{-s}/2$ and finds the simplest Rational in the closed interval $[q - \epsilon, q + \epsilon]$. The simplest Rational is the one with minimal denominator; if there are multiple such Rationals, the one with the smallest absolute numerator is chosen.

The following discussion assumes base 10.

This method allows the function to convert "0.333" to $1/3$, since $1/3$ is the simplest Rational in the interval $[0.3325, 0.3335]$. But note that if the scale of the input is low, some unexpected behavior may occur. For example, "0.1" will be converted into $1/7$ rather than $1/10$, since $1/7$ is the simplest Rational in $[0.05, 0.15]$. If you’d prefer that result be $1/10$, you have a few options:

§Worst-case complexity

$T(n, m) = O(m^n n \log m (\log n + \log\log m))$

$M(n, m) = O(m^n n \log m)$

where $T$ is time, $M$ is additional memory, $n$ is s.len(), and $m$ is options.base.

§Examples
use malachite_base::num::conversion::string::options::FromSciStringOptions;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;

let mut options = FromSciStringOptions::default();
options.set_base(16);
assert_eq!(Rational::from_sci_string_simplest_with_options("ff", options).unwrap(), 255);
assert_eq!(
    Rational::from_sci_string_simplest_with_options("ffE+5", options).unwrap(),
    267386880
);
// 1/4105 is 0.000ff705..._16
assert_eq!(
    Rational::from_sci_string_simplest_with_options("ffE-5", options).unwrap().to_string(),
    "1/4105"
);
source

pub fn from_sci_string_simplest(s: &str) -> Option<Rational>

Converts a string, possibly in scientfic notation, to a Rational. This function finds the simplest Rational which rounds to the target string according to the precision implied by the string.

The string is parsed using base 10. To use other bases, try from_sci_string_simplest_with_options instead.

Exponents are allowed, and are indicated using the character 'e' or 'E'.

The exponent itself is also parsed using base 10.

Decimal points are allowed.

If the string is unparseable, None is returned.

Here’s a more precise description of the function’s behavior. Suppose that the literal value of the string (as parsed by from_sci_string) is $q$, and the implied scale is $s$ (meaning $s$ digits are provided after the point; if the string is "123.456", then $s$ is 3). Then this function computes $\epsilon = 10^{-s}/2$ and finds the simplest Rational in the closed interval $[q - \epsilon, q + \epsilon]$. The simplest Rational is the one with minimal denominator; if there are multiple such Rationals, the one with the smallest absolute numerator is chosen.

This method allows the function to convert "0.333" to $1/3$, since $1/3$ is the simplest Rational in the interval $[0.3325, 0.3335]$. But note that if the scale of the input is low, some unexpected behavior may occur. For example, "0.1" will be converted into $1/7$ rather than $1/10$, since $1/7$ is the simplest Rational in $[0.05, 0.15]$. If you’d prefer that result be $1/10$, you have a few options:

§Worst-case complexity

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

$M(n) = O(10^n n)$

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

§Examples
use malachite_q::Rational;

assert_eq!(Rational::from_sci_string_simplest("123").unwrap(), 123);
assert_eq!(Rational::from_sci_string_simplest("0.1").unwrap().to_string(), "1/7");
assert_eq!(Rational::from_sci_string_simplest("0.10").unwrap().to_string(), "1/10");
assert_eq!(Rational::from_sci_string_simplest("0.333").unwrap().to_string(), "1/3");
assert_eq!(Rational::from_sci_string_simplest("1.2e5").unwrap(), 120000);
assert_eq!(Rational::from_sci_string_simplest("1.2e-5").unwrap().to_string(), "1/80000");
source§

impl Rational

source

pub fn length_after_point_in_small_base(&self, base: u8) -> Option<u64>

When expanding a Rational in a small base $b$, determines how many digits after the decimal (or other-base) point are in the base-$b$ expansion.

If the expansion is non-terminating, this method returns None. This happens iff the Rational’s denominator has prime factors not present in $b$.

§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 base is less than 2 or greater than 36.

§Examples
use malachite_q::Rational;

// 3/8 is 0.375 in base 10.
assert_eq!(Rational::from_signeds(3, 8).length_after_point_in_small_base(10), Some(3));
// 1/20 is 0.05 in base 10.
assert_eq!(Rational::from_signeds(1, 20).length_after_point_in_small_base(10), Some(2));
// 1/7 is non-terminating in base 10.
assert_eq!(Rational::from_signeds(1, 7).length_after_point_in_small_base(10), None);
// 1/7 is 0.3 in base 21.
assert_eq!(Rational::from_signeds(1, 7).length_after_point_in_small_base(21), Some(1));
source§

impl Rational

source

pub fn to_numerator(&self) -> Natural

Extracts the numerator of a Rational, taking the Rational by reference and cloning.

§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_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::from_str("2/3").unwrap().to_numerator(), 2);
assert_eq!(Rational::from_str("0").unwrap().to_numerator(), 0);
source

pub fn to_denominator(&self) -> Natural

Extracts the denominator of a Rational, taking the Rational by reference and cloning.

§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_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::from_str("2/3").unwrap().to_denominator(), 3);
assert_eq!(Rational::from_str("0").unwrap().to_denominator(), 1);
source

pub fn to_numerator_and_denominator(&self) -> (Natural, Natural)

Extracts the numerator and denominator of a Rational, taking the Rational by reference and cloning.

§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::strings::ToDebugString;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(
    Rational::from_str("2/3").unwrap().to_numerator_and_denominator().to_debug_string(),
    "(2, 3)"
);
assert_eq!(
    Rational::from_str("0").unwrap().to_numerator_and_denominator().to_debug_string(),
    "(0, 1)"
);
source

pub fn into_numerator(self) -> Natural

Extracts the numerator of a Rational, taking the Rational by value.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::from_str("2/3").unwrap().into_numerator(), 2);
assert_eq!(Rational::from_str("0").unwrap().into_numerator(), 0);
source

pub fn into_denominator(self) -> Natural

Extracts the denominator of a Rational, taking the Rational by value.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::from_str("2/3").unwrap().into_denominator(), 3);
assert_eq!(Rational::from_str("0").unwrap().into_denominator(), 1);
source

pub fn into_numerator_and_denominator(self) -> (Natural, Natural)

Extracts the numerator and denominator of a Rational, taking the Rational by value.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(
    Rational::from_str("2/3").unwrap().into_numerator_and_denominator().to_debug_string(),
    "(2, 3)"
);
assert_eq!(
    Rational::from_str("0").unwrap().into_numerator_and_denominator().to_debug_string(),
    "(0, 1)"
);
source

pub const fn numerator_ref(&self) -> &Natural

Returns a reference to the numerator of a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(*Rational::from_str("2/3").unwrap().numerator_ref(), 2);
assert_eq!(*Rational::from_str("0").unwrap().numerator_ref(), 0);
source

pub const fn denominator_ref(&self) -> &Natural

Returns a reference to the denominator of a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(*Rational::from_str("2/3").unwrap().denominator_ref(), 3);
assert_eq!(*Rational::from_str("0").unwrap().denominator_ref(), 1);
source

pub const fn numerator_and_denominator_ref(&self) -> (&Natural, &Natural)

Returns references to the numeraror and denominator of a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(
    Rational::from_str("2/3").unwrap().numerator_and_denominator_ref().to_debug_string(),
    "(2, 3)"
);
assert_eq!(
    Rational::from_str("0").unwrap().numerator_and_denominator_ref().to_debug_string(),
    "(0, 1)"
);

Trait Implementations§

source§

impl<'a> Abs for &'a Rational

source§

fn abs(self) -> Rational

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

$$ f(x) = |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::Abs;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!((&Rational::ZERO).abs(), 0);
assert_eq!((&Rational::from_signeds(22, 7)).abs().to_string(), "22/7");
assert_eq!((&Rational::from_signeds(-22, 7)).abs().to_string(), "22/7");
§

type Output = Rational

source§

impl Abs for Rational

source§

fn abs(self) -> Rational

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

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.abs(), 0);
assert_eq!(Rational::from_signeds(22, 7).abs().to_string(), "22/7");
assert_eq!(Rational::from_signeds(-22, 7).abs().to_string(), "22/7");
§

type Output = Rational

source§

impl AbsAssign for Rational

source§

fn abs_assign(&mut self)

Replaces a Rational with its absolute value.

$$ x \gets |x|. $$

§Examples
use malachite_base::num::arithmetic::traits::AbsAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::ZERO;
x.abs_assign();
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x.abs_assign();
assert_eq!(x.to_string(), "22/7");

let mut x = Rational::from_signeds(-22, 7);
x.abs_assign();
assert_eq!(x.to_string(), "22/7");
source§

impl<'a, 'b> Add<&'a Rational> for &'b Rational

source§

fn add(self, other: &'a Rational) -> Rational

Adds two Rationals, taking both by reference.

$$ f(x, y) = x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF + &Rational::ONE_HALF, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) + &Rational::from_signeds(99, 100)).to_string(),
    "2893/700"
);
§

type Output = Rational

The resulting type after applying the + operator.
source§

impl<'a> Add<&'a Rational> for Rational

source§

fn add(self, other: &'a Rational) -> Rational

Adds two Rationals, taking both by the first by value and the second by reference.

$$ f(x, y) = x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF + &Rational::ONE_HALF, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) + &Rational::from_signeds(99, 100)).to_string(),
    "2893/700"
);
§

type Output = Rational

The resulting type after applying the + operator.
source§

impl<'a> Add<Rational> for &'a Rational

source§

fn add(self, other: Rational) -> Rational

Adds two Rationals, taking the first by reference and the second by value

$$ f(x, y) = x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF + Rational::ONE_HALF, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) + Rational::from_signeds(99, 100)).to_string(),
    "2893/700"
);
§

type Output = Rational

The resulting type after applying the + operator.
source§

impl Add for Rational

source§

fn add(self, other: Rational) -> Rational

Adds two Rationals, taking both by value.

$$ f(x, y) = x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF + Rational::ONE_HALF, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) + Rational::from_signeds(99, 100)).to_string(),
    "2893/700"
);
§

type Output = Rational

The resulting type after applying the + operator.
source§

impl<'a> AddAssign<&'a Rational> for Rational

source§

fn add_assign(&mut self, other: &'a Rational)

Adds a Rational to a Rational in place, taking the Rational on the right-hand side by reference.

$$ x \gets x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x += &Rational::ONE_HALF;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x += &Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "2893/700");
source§

impl AddAssign for Rational

source§

fn add_assign(&mut self, other: Rational)

Adds a Rational to a Rational in place, taking the Rational on the right-hand side by value.

$$ x \gets x + y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x += Rational::ONE_HALF;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x += Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "2893/700");
source§

impl<'a> Approximate for &'a Rational

source§

fn approximate(self, max_denominator: &Natural) -> Rational

Finds the best approximation of a Rational using a denominator no greater than a specified maximum, taking the Rational by reference.

Let $f(x, d) = p/q$, with $p$ and $q$ relatively prime. Then the following properties hold:

  • $q \leq d$
  • For all $n \in \Z$ and all $m \in \Z$ with $0 < m \leq d$, $|x - p/q| \leq |x - n/m|$.
  • If $|x - n/m| = |x - p/q|$, then $q \leq m$.
  • If $|x - n/q| = |x - p/q|$, then $p$ is even and $n$ is either equal to $p$ or odd.
§Worst-case complexity

$T(n) = O(n^2 \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()).

§Panics
  • If max_denominator is zero.
§Examples
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_nz::natural::Natural;
use malachite_q::arithmetic::traits::Approximate;
use malachite_q::Rational;

assert_eq!(
    (&Rational::exact_from(std::f64::consts::PI)).approximate(&Natural::from(1000u32))
            .to_string(),
    "355/113"
);
assert_eq!(
    (&Rational::from_signeds(333i32, 1000)).approximate(&Natural::from(100u32))
            .to_string(),
    "1/3"
);
§Implementation notes

This algorithm follows the description in https://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations. One part of the algorithm not mentioned in that article is that if the last term $n$ in the continued fraction needs to be reduced, the optimal replacement term $m$ may be found using division.

source§

impl Approximate for Rational

source§

fn approximate(self, max_denominator: &Natural) -> Rational

Finds the best approximation of a Rational using a denominator no greater than a specified maximum, taking the Rational by value.

Let $f(x, d) = p/q$, with $p$ and $q$ relatively prime. Then the following properties hold:

  • $q \leq d$
  • For all $n \in \Z$ and all $m \in \Z$ with $0 < m \leq d$, $|x - p/q| \leq |x - n/m|$.
  • If $|x - n/m| = |x - p/q|$, then $q \leq m$.
  • If $|x - n/q| = |x - p/q|$, then $p$ is even and $n$ is either equal to $p$ or odd.
§Worst-case complexity

$T(n) = O(n^2 \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()).

§Panics
  • If max_denominator is zero.
§Examples
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_nz::natural::Natural;
use malachite_q::arithmetic::traits::Approximate;
use malachite_q::Rational;

assert_eq!(
    Rational::exact_from(std::f64::consts::PI).approximate(&Natural::from(1000u32))
        .to_string(),
    "355/113"
);
assert_eq!(
    Rational::from_signeds(333i32, 1000).approximate(&Natural::from(100u32)).to_string(),
    "1/3"
);
§Implementation notes

This algorithm follows the description in https://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations. One part of the algorithm not mentioned in that article is that if the last term $n$ in the continued fraction needs to be reduced, the optimal replacement term $m$ may be found using division.

source§

impl ApproximateAssign for Rational

source§

fn approximate_assign(&mut self, max_denominator: &Natural)

Finds the best approximation of a Rational using a denominator no greater than a specified maximum, mutating the Rational in place.

See Rational::approximate for more information.

§Worst-case complexity

$T(n) = O(n^2 \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()).

§Panics
  • If max_denominator is zero.
§Examples
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_nz::natural::Natural;
use malachite_q::arithmetic::traits::ApproximateAssign;
use malachite_q::Rational;

let mut x = Rational::exact_from(std::f64::consts::PI);
x.approximate_assign(&Natural::from(1000u32));
assert_eq!(x.to_string(), "355/113");

let mut x = Rational::from_signeds(333i32, 1000);
x.approximate_assign(&Natural::from(100u32));
assert_eq!(x.to_string(), "1/3");
source§

impl<'a> Ceiling for &'a Rational

source§

fn ceiling(self) -> Integer

Finds the ceiling of a Rational, taking the Rational by reference.

$$ f(x) = \lceil x \rceil. $$

§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::arithmetic::traits::Ceiling;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!((&Rational::ZERO).ceiling(), 0);
assert_eq!((&Rational::from_signeds(22, 7)).ceiling(), 4);
assert_eq!((&Rational::from_signeds(-22, 7)).ceiling(), -3);
§

type Output = Integer

source§

impl Ceiling for Rational

source§

fn ceiling(self) -> Integer

Finds the ceiling of a Rational, taking the Rational by value.

$$ f(x) = \lceil x \rceil. $$

§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::arithmetic::traits::Ceiling;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.ceiling(), 0);
assert_eq!(Rational::from_signeds(22, 7).ceiling(), 4);
assert_eq!(Rational::from_signeds(-22, 7).ceiling(), -3);
§

type Output = Integer

source§

impl CeilingAssign for Rational

source§

fn ceiling_assign(&mut self)

Replaces a Rational with its ceiling.

$$ x \gets \lceil x \rceil. $$

§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::arithmetic::traits::CeilingAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::ZERO;
x.ceiling_assign();
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x.ceiling_assign();
assert_eq!(x, 4);

let mut x = Rational::from_signeds(-22, 7);
x.ceiling_assign();
assert_eq!(x, -3);
source§

impl<'a, 'b> CeilingLogBase<&'b Rational> for &'a Rational

source§

fn ceiling_log_base(self, base: &Rational) -> i64

Returns the ceiling of the base-$b$ logarithm of a positive Rational.

Note that this function may be slow if the base is very close to 1.

$f(x, b) = \lceil\log_b x\rceil$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is base.significant_bits(), and $m$ is $|\log_b x|$, where $b$ is base and $x$ is x.

§Panics

Panics if self less than or equal to zero or base is 1.

§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBase;
use malachite_q::Rational;

assert_eq!(Rational::from(80u32).ceiling_log_base(&Rational::from(3u32)), 4);
assert_eq!(Rational::from(81u32).ceiling_log_base(&Rational::from(3u32)), 4);
assert_eq!(Rational::from(82u32).ceiling_log_base(&Rational::from(3u32)), 5);
assert_eq!(Rational::from(4294967296u64).ceiling_log_base(&Rational::from(10u32)), 10);
assert_eq!(
    Rational::from_signeds(936851431250i64, 1397).ceiling_log_base(&Rational::from(10u32)),
    9
);
assert_eq!(
    Rational::from_signeds(5153632, 16807)
            .ceiling_log_base(&Rational::from_signeds(22, 7)),
    5
);
§

type Output = i64

source§

impl<'a> CeilingLogBase2 for &'a Rational

source§

fn ceiling_log_base_2(self) -> i64

Returns the ceiling of the base-2 logarithm of a positive Rational.

$f(x) = \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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBase2;
use malachite_q::Rational;

assert_eq!(Rational::from(3u32).ceiling_log_base_2(), 2);
assert_eq!(Rational::from_signeds(1, 3).ceiling_log_base_2(), -1);
assert_eq!(Rational::from_signeds(1, 4).ceiling_log_base_2(), -2);
assert_eq!(Rational::from_signeds(1, 5).ceiling_log_base_2(), -2);
§

type Output = i64

source§

impl<'a> CeilingLogBasePowerOf2<i64> for &'a Rational

source§

fn ceiling_log_base_power_of_2(self, pow: i64) -> i64

Returns the ceiling of the base-$2^k$ logarithm of a positive Rational.

$k$ may be negative.

$f(x, p) = \lceil\log_{2^p} x\rceil$.

§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 less than or equal to 0 or pow is 0.

§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBasePowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::from(100).ceiling_log_base_power_of_2(2), 4);
assert_eq!(Rational::from(4294967296u64).ceiling_log_base_power_of_2(8), 4);

// 4^(-2) < 1/10 < 4^(-1)
assert_eq!(Rational::from_signeds(1, 10).ceiling_log_base_power_of_2(2), -1);
// (1/4)^2 < 1/10 < (1/4)^1
assert_eq!(Rational::from_signeds(1, 10).ceiling_log_base_power_of_2(-2), 2);
§

type Output = i64

source§

impl<'a, 'b> CheckedDiv<&'a Rational> for &'b Rational

source§

fn checked_div(self, other: &'a Rational) -> Option<Rational>

Divides a Rational by another Rational, taking both by reference. Returns None when the second Rational is zero, Some otherwise.

$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \frac{x}{y} \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_q::Rational;

assert_eq!((&Rational::TWO).checked_div(&Rational::TWO).unwrap(), 1);
assert_eq!((&Rational::TWO).checked_div(&Rational::ZERO), None);
assert_eq!(
    (&Rational::from_signeds(22, 7)).checked_div(&Rational::from_signeds(99, 100)).unwrap()
        .to_string(),
    "200/63"
);
§

type Output = Rational

source§

impl<'a> CheckedDiv<&'a Rational> for Rational

source§

fn checked_div(self, other: &'a Rational) -> Option<Rational>

Divides a Rational by another Rational, taking the first by value and the second by reference. Returns None when the second Rational is zero, Some otherwise.

$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \frac{x}{y} \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_q::Rational;

assert_eq!(Rational::TWO.checked_div(&Rational::TWO).unwrap(), 1);
assert_eq!(Rational::TWO.checked_div(&Rational::ZERO), None);
assert_eq!(
    (Rational::from_signeds(22, 7).checked_div(&Rational::from_signeds(99, 100))).unwrap()
        .to_string(),
    "200/63"
);
§

type Output = Rational

source§

impl<'a> CheckedDiv<Rational> for &'a Rational

source§

fn checked_div(self, other: Rational) -> Option<Rational>

Divides a Rational by another Rational, taking the first by reference and the second by value. Returns None when the second Rational is zero, Some otherwise.

$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \frac{x}{y} \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_q::Rational;

assert_eq!((&Rational::TWO).checked_div(Rational::TWO).unwrap(), 1);
assert_eq!((&Rational::TWO).checked_div(Rational::ZERO), None);
assert_eq!(
    (&Rational::from_signeds(22, 7)).checked_div(Rational::from_signeds(99, 100)).unwrap()
        .to_string(),
    "200/63"
);
§

type Output = Rational

source§

impl CheckedDiv for Rational

source§

fn checked_div(self, other: Rational) -> Option<Rational>

Divides a Rational by another Rational, taking both by value. Returns None when the second Rational is zero, Some otherwise.

$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \frac{x}{y} \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_q::Rational;

assert_eq!(Rational::TWO.checked_div(Rational::TWO).unwrap(), 1);
assert_eq!(Rational::TWO.checked_div(Rational::ZERO), None);
assert_eq!(
    (Rational::from_signeds(22, 7).checked_div(Rational::from_signeds(99, 100))).unwrap()
        .to_string(),
    "200/63"
);
§

type Output = Rational

source§

impl<'a, 'b> CheckedLogBase<&'b Rational> for &'a Rational

source§

fn checked_log_base(self, base: &Rational) -> Option<i64>

Returns the base-$b$ logarithm of a positive Rational. If the Rational is not a power of $b$, then None is returned.

Note that this function may be slow if the base is very close to 1.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\log_b x) & \text{if} \quad \log_b x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is base.significant_bits(), and $m$ is $|\log_b x|$, where $b$ is base and $x$ is x.

§Panics

Panics if self less than or equal to zero or base is 1.

§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBase;
use malachite_q::Rational;

assert_eq!(Rational::from(80u32).checked_log_base(&Rational::from(3u32)), None);
assert_eq!(Rational::from(81u32).checked_log_base(&Rational::from(3u32)), Some(4));
assert_eq!(Rational::from(82u32).checked_log_base(&Rational::from(3u32)), None);
assert_eq!(Rational::from(4294967296u64).checked_log_base(&Rational::from(10u32)), None);
assert_eq!(
    Rational::from_signeds(936851431250i64, 1397).checked_log_base(&Rational::from(10u32)),
    None
);
assert_eq!(
    Rational::from_signeds(5153632, 16807)
            .checked_log_base(&Rational::from_signeds(22, 7)),
    Some(5)
);
§

type Output = i64

source§

impl<'a> CheckedLogBase2 for &'a Rational

source§

fn checked_log_base_2(self) -> Option<i64>

Returns the base-2 logarithm of a positive Rational. If the Rational is not a power of 2, then None is returned.

$$ f(x) = \begin{cases} \operatorname{Some}(\log_2 x) & \text{if} \quad \log_2 x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBase2;
use malachite_q::Rational;

assert_eq!(Rational::from(3u32).checked_log_base_2(), None);
assert_eq!(Rational::from_signeds(1, 3).checked_log_base_2(), None);
assert_eq!(Rational::from_signeds(1, 4).checked_log_base_2(), Some(-2));
assert_eq!(Rational::from_signeds(1, 5).checked_log_base_2(), None);
§

type Output = i64

source§

impl<'a> CheckedLogBasePowerOf2<i64> for &'a Rational

source§

fn checked_log_base_power_of_2(self, pow: i64) -> Option<i64>

Returns the base-$2^k$ logarithm of a positive Rational. If the Rational is not a power of $2^k$, then None is returned.

$k$ may be negative.

$$ f(x, p) = \begin{cases} \operatorname{Some}(\log_{2^p} x) & \text{if} \quad \log_{2^p} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§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 0 or pow is 0.

§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBasePowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::from(100).checked_log_base_power_of_2(2), None);
assert_eq!(Rational::from(4294967296u64).checked_log_base_power_of_2(8), Some(4));

// 4^(-2) < 1/10 < 4^(-1)
assert_eq!(Rational::from_signeds(1, 10).checked_log_base_power_of_2(2), None);
assert_eq!(Rational::from_signeds(1, 16).checked_log_base_power_of_2(2), Some(-2));
// (1/4)^2 < 1/10 < (1/4)^1
assert_eq!(Rational::from_signeds(1, 10).checked_log_base_power_of_2(-2), None);
assert_eq!(Rational::from_signeds(1, 16).checked_log_base_power_of_2(-2), Some(2));
§

type Output = i64

source§

impl<'a> CheckedRoot<i64> for &'a Rational

source§

fn checked_root(self, pow: i64) -> Option<Rational>

Returns the the $n$th root of a Rational, or None if the Rational is not a perfect $n$th power. The Rational is taken by reference.

$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

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

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

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

§Panics

Panics if exp is zero, if exp is even and self is negative, or if self is zero and exp is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!((&Rational::from(999i32)).checked_root(3i64).to_debug_string(), "None");
assert_eq!((&Rational::from(1000i32)).checked_root(3i64).to_debug_string(), "Some(10)");
assert_eq!((&Rational::from(1001i32)).checked_root(3i64).to_debug_string(), "None");
assert_eq!((&Rational::from(-1000i32)).checked_root(3i64).to_debug_string(), "Some(-10)");
assert_eq!((&Rational::from_signeds(22, 7)).checked_root(3i64).to_debug_string(), "None");
assert_eq!(
    (&Rational::from_signeds(27, 8)).checked_root(3i64).to_debug_string(),
    "Some(3/2)"
);
assert_eq!(
    (&Rational::from_signeds(-27, 8)).checked_root(3i64).to_debug_string(),
    "Some(-3/2)"
);

assert_eq!((&Rational::from(1000i32)).checked_root(-3i64).to_debug_string(), "Some(1/10)");
assert_eq!(
    (&Rational::from_signeds(-27, 8)).checked_root(-3i64).to_debug_string(),
    "Some(-2/3)"
);
§

type Output = Rational

source§

impl CheckedRoot<i64> for Rational

source§

fn checked_root(self, pow: i64) -> Option<Rational>

Returns the the $n$th root of a Rational, or None if the Rational is not a perfect $n$th power. The Rational is taken by value.

$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

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

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

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

§Panics

Panics if exp is zero, if exp is even and self is negative, or if self is zero and exp is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(Rational::from(999i32).checked_root(3i64).to_debug_string(), "None");
assert_eq!(Rational::from(1000i32).checked_root(3i64).to_debug_string(), "Some(10)");
assert_eq!(Rational::from(1001i32).checked_root(3i64).to_debug_string(), "None");
assert_eq!(Rational::from(-1000i32).checked_root(3i64).to_debug_string(), "Some(-10)");
assert_eq!(Rational::from_signeds(22, 7).checked_root(3i64).to_debug_string(), "None");
assert_eq!(
    Rational::from_signeds(27, 8).checked_root(3i64).to_debug_string(),
    "Some(3/2)"
);
assert_eq!(
    Rational::from_signeds(-27, 8).checked_root(3i64).to_debug_string(),
    "Some(-3/2)"
);

assert_eq!(Rational::from(1000i32).checked_root(-3i64).to_debug_string(), "Some(1/10)");
assert_eq!(
    Rational::from_signeds(-27, 8).checked_root(-3i64).to_debug_string(),
    "Some(-2/3)"
);
§

type Output = Rational

source§

impl<'a> CheckedRoot<u64> for &'a Rational

source§

fn checked_root(self, pow: u64) -> Option<Rational>

Returns the the $n$th root of a Rational, or None if the Rational is not a perfect $n$th power. The Rational is taken by reference.

$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

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

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

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

§Panics

Panics if exp is zero, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(Rational::from(999i32).checked_root(3u64).to_debug_string(), "None");
assert_eq!(Rational::from(1000i32).checked_root(3u64).to_debug_string(), "Some(10)");
assert_eq!(Rational::from(1001i32).checked_root(3u64).to_debug_string(), "None");
assert_eq!(Rational::from(-1000i32).checked_root(3u64).to_debug_string(), "Some(-10)");
assert_eq!(Rational::from_signeds(22, 7).checked_root(3u64).to_debug_string(), "None");
assert_eq!(
    Rational::from_signeds(27, 8).checked_root(3u64).to_debug_string(),
    "Some(3/2)"
);
assert_eq!(
    Rational::from_signeds(-27, 8).checked_root(3u64).to_debug_string(),
    "Some(-3/2)"
);
§

type Output = Rational

source§

impl CheckedRoot<u64> for Rational

source§

fn checked_root(self, pow: u64) -> Option<Rational>

Returns the the $n$th root of a Rational, or None if the Rational is not a perfect $n$th power. The Rational is taken by value.

$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

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

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

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

§Panics

Panics if exp is zero, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(Rational::from(999i32).checked_root(3u64).to_debug_string(), "None");
assert_eq!(Rational::from(1000i32).checked_root(3u64).to_debug_string(), "Some(10)");
assert_eq!(Rational::from(1001i32).checked_root(3u64).to_debug_string(), "None");
assert_eq!(Rational::from(-1000i32).checked_root(3u64).to_debug_string(), "Some(-10)");
assert_eq!(Rational::from_signeds(22, 7).checked_root(3u64).to_debug_string(), "None");
assert_eq!(
    Rational::from_signeds(27, 8).checked_root(3u64).to_debug_string(),
    "Some(3/2)"
);
assert_eq!(
    Rational::from_signeds(-27, 8).checked_root(3u64).to_debug_string(),
    "Some(-3/2)"
);
§

type Output = Rational

source§

impl<'a> CheckedSqrt for &'a Rational

source§

fn checked_sqrt(self) -> Option<Rational>

Returns the the square root of a Rational, or None if it is not a perfect square. The Rational is taken by reference.

$$ f(x) = \begin{cases} \operatorname{Some}(sqrt{x}) & \text{if} \quad \sqrt{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§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 self.significant_bits().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!((&Rational::from(99u8)).checked_sqrt().to_debug_string(), "None");
assert_eq!((&Rational::from(100u8)).checked_sqrt().to_debug_string(), "Some(10)");
assert_eq!((&Rational::from(101u8)).checked_sqrt().to_debug_string(), "None");
assert_eq!((&Rational::from_signeds(22, 7)).checked_sqrt().to_debug_string(), "None");
assert_eq!((&Rational::from_signeds(25, 9)).checked_sqrt().to_debug_string(), "Some(5/3)");
§

type Output = Rational

source§

impl CheckedSqrt for Rational

source§

fn checked_sqrt(self) -> Option<Rational>

Returns the the square root of a Rational, or None if it is not a perfect square. The Rational is taken by value.

$$ f(x) = \begin{cases} \operatorname{Some}(sqrt{x}) & \text{if} \quad \sqrt{x} \in \mathbb{Q}, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§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 self.significant_bits().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(Rational::from(99u8).checked_sqrt().to_debug_string(), "None");
assert_eq!(Rational::from(100u8).checked_sqrt().to_debug_string(), "Some(10)");
assert_eq!(Rational::from(101u8).checked_sqrt().to_debug_string(), "None");
assert_eq!(Rational::from_signeds(22, 7).checked_sqrt().to_debug_string(), "None");
assert_eq!(Rational::from_signeds(25, 9).checked_sqrt().to_debug_string(), "Some(5/3)");
§

type Output = Rational

source§

impl Clone for Rational

source§

fn clone(&self) -> Rational

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> ContinuedFraction for &'a Rational

source§

fn continued_fraction(self) -> (Integer, RationalContinuedFraction)

Returns the continued fraction of a Rational, taking the Rational by reference.

The output has two components. The first is the first value of the continued fraction, which may be any Integer and is equal to the floor of the Rational. The second is an iterator that produces the remaining values, which are all positive. Using the standard notation for continued fractions, the first value is the number before the semicolon, and the second value produces the remaining numbers.

Each rational number has two continued fraction representations. The shorter of the two representations (the one that does not end in 1) is returned.

$f(x) = (a_0, (a_1, a_2, \ldots, a_3)),$ where $x = [a_0; a_1, a_2, \ldots, a_3]$ and $a_3 \neq 1$.

The output length is $O(n)$, where $n$ is self.significant_bits().

§Worst-case complexity per iteration

$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 self.significant_bits().

§Examples
use itertools::Itertools;
use malachite_base::strings::ToDebugString;
use malachite_q::conversion::traits::ContinuedFraction;
use malachite_q::Rational;

let (head, tail) = (&Rational::from_signeds(2, 3)).continued_fraction();
let tail = tail.collect_vec();
assert_eq!(head, 0);
assert_eq!(tail.to_debug_string(), "[1, 2]");

let (head, tail) = (&Rational::from_signeds(355, 113)).continued_fraction();
let tail = tail.collect_vec();
assert_eq!(head, 3);
assert_eq!(tail.to_debug_string(), "[7, 16]");
§

type CF = RationalContinuedFraction

source§

impl ContinuedFraction for Rational

source§

fn continued_fraction(self) -> (Integer, RationalContinuedFraction)

Returns the continued fraction of a Rational, taking the Rational by value.

The output has two components. The first is the first value of the continued fraction, which may be any Integer and is equal to the floor of the Rational. The second is an iterator that produces the remaining values, which are all positive. Using the standard notation for continued fractions, the first value is the number before the semicolon, and the second value produces the remaining numbers.

Each rational number has two continued fraction representations. The shorter of the two representations (the one that does not end in 1) is returned.

$f(x) = (a_0, (a_1, a_2, \ldots, a_3)),$ where $x = [a_0; a_1, a_2, \ldots, a_3]$ and $a_3 \neq 1$.

The output length is $O(n)$, where $n$ is self.significant_bits().

§Worst-case complexity per iteration

$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 self.significant_bits().

§Examples
use itertools::Itertools;
use malachite_base::strings::ToDebugString;
use malachite_q::conversion::traits::ContinuedFraction;
use malachite_q::Rational;

let (head, tail) = Rational::from_signeds(2, 3).continued_fraction();
let tail = tail.collect_vec();
assert_eq!(head, 0);
assert_eq!(tail.to_debug_string(), "[1, 2]");

let (head, tail) = Rational::from_signeds(355, 113).continued_fraction();
let tail = tail.collect_vec();
assert_eq!(head, 3);
assert_eq!(tail.to_debug_string(), "[7, 16]");
§

type CF = RationalContinuedFraction

source§

impl<'a> Convergents for &'a Rational

source§

fn convergents(self) -> RationalConvergents

Returns the convergents of a Rational, taking the Rational by reference.

The convergents of a number are the sequence of rational numbers whose continued fractions are the prefixes of the number’s continued fraction. The first convergent is the floor of the number. The sequence of convergents is finite iff the number is rational, in which case the last convergent is the number itself. Each convergent is closer to the number than the previous convergent is. The even-indexed convergents are less than or equal to the number, and the odd-indexed ones are greater than or equal to it.

$f(x) = ([a_0; a_1, a_2, \ldots, a_i])_{i=0}^{n}$, where $x = [a_0; a_1, a_2, \ldots, a_n]$ and $a_n \neq 1$.

The output length is $O(n)$, where $n$ is self.significant_bits().

§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 self.significant_bits().

§Examples
use itertools::Itertools;
use malachite_base::strings::ToDebugString;
use malachite_q::conversion::traits::Convergents;
use malachite_q::Rational;

assert_eq!(
    (&Rational::from_signeds(2, 3)).convergents().collect_vec().to_debug_string(),
    "[0, 1, 2/3]"
);
assert_eq!(
    (&Rational::from_signeds(355, 113)).convergents().collect_vec().to_debug_string(),
    "[3, 22/7, 355/113]",
);
§

type C = RationalConvergents

source§

impl Convergents for Rational

source§

fn convergents(self) -> RationalConvergents

Returns the convergents of a Rational, taking the Rational by value.

The convergents of a number are the sequence of rational numbers whose continued fractions are the prefixes of the number’s continued fraction. The first convergent is the floor of the number. The sequence of convergents is finite iff the number is rational, in which case the last convergent is the number itself. Each convergent is closer to the number than the previous convergent is. The even-indexed convergents are less than or equal to the number, and the odd-indexed ones are greater than or equal to it.

$f(x) = ([a_0; a_1, a_2, \ldots, a_i])_{i=0}^{n}$, where $x = [a_0; a_1, a_2, \ldots, a_n]$ and $a_n \neq 1$.

The output length is $O(n)$, where $n$ is self.significant_bits().

§Worst-case complexity per iteration

$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 self.significant_bits().

§Examples
use itertools::Itertools;
use malachite_base::strings::ToDebugString;
use malachite_q::conversion::traits::Convergents;
use malachite_q::Rational;

assert_eq!(
    Rational::from_signeds(2, 3).convergents().collect_vec().to_debug_string(),
    "[0, 1, 2/3]"
);
assert_eq!(
    Rational::from_signeds(355, 113).convergents().collect_vec().to_debug_string(),
    "[3, 22/7, 355/113]",
);
§

type C = RationalConvergents

source§

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

source§

fn convertible_from(x: &Rational) -> bool

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(Integer::convertible_from(&Rational::from(123)), true);
assert_eq!(Integer::convertible_from(&Rational::from(-123)), true);
assert_eq!(Integer::convertible_from(&Rational::from_signeds(22, 7)), false);
source§

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

source§

fn convertible_from(x: &Rational) -> bool

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(Natural::convertible_from(&Rational::from(123)), true);
assert_eq!(Natural::convertible_from(&Rational::from(-123)), false);
assert_eq!(Natural::convertible_from(&Rational::from_signeds(22, 7)), false);
source§

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

source§

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

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

source§

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

source§

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

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

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

source§

fn convertible_from(value: &Rational) -> bool

Determines whether a Rational can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl ConvertibleFrom<Rational> for f32

source§

fn convertible_from(value: Rational) -> bool

Determines whether a Rational can be exactly converted to a primitive float, taking the Rational by value.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

source§

impl ConvertibleFrom<Rational> for f64

source§

fn convertible_from(value: Rational) -> bool

Determines whether a Rational can be exactly converted to a primitive float, taking the Rational by value.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

source§

impl ConvertibleFrom<f32> for Rational

source§

fn convertible_from(x: f32) -> bool

Determines whether a primitive float can be converted to a Rational. (It can if it is finite.)

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl ConvertibleFrom<f64> for Rational

source§

fn convertible_from(x: f64) -> bool

Determines whether a primitive float can be converted to a Rational. (It can if it is finite.)

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl Debug for Rational

source§

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

Converts a Rational to a String.

This is the same implementation as for Display.

§Worst-case complexity

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

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

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

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.to_debug_string(), "0");
assert_eq!(Rational::from(123).to_debug_string(), "123");
assert_eq!(Rational::from_signeds(22, 7).to_debug_string(), "22/7");
source§

impl Default for Rational

source§

fn default() -> Rational

The default value of a Rational, 0.

source§

impl DenominatorsInClosedInterval for Rational

source§

fn denominators_in_closed_interval( a: Rational, b: Rational ) -> DenominatorsInClosedRationalInterval

Returns an iterator of all denominators that appear in the Rationals contained in a closed interval.

For example, consider the interval $[1/3, 1/2]$. It contains no integers, so no Rationals with denominator 1. It does contain Rationals with denominators 2 and 3 (the endpoints). It contains none with denominator 4, but it does contain $2/5$. It contains none with denominator 6 (though $1/3$ and $1/2$ are $2/6$ and $3/6$, those representations are not reduced). It contains $3/7$, $3/8$, and $4/9$ but none with denominator 10 ($0.4$ does not count because it is $2/5$). It contains all denominators greater than 10, so the complete list is $2, 3, 5, 7, 8, 9, 11, 12, 13, \ldots$.

§Worst-case complexity per iteration

$T(n, i) = O(n + \log i)$

$M(n, i) = O(n + \log i)$

where $T$ is time, $M$ is additional memory, $i$ is the iteration number, and $n$ is max(a.significant_bits(), b.significant_bits()).

§Panics

Panics if $a \geq b$.

use malachite_base::iterators::prefix_to_string;
use malachite_base::num::basic::traits::{One, Two};
use malachite_q::arithmetic::traits::DenominatorsInClosedInterval;
use malachite_q::Rational;

assert_eq!(
    prefix_to_string(
        Rational::denominators_in_closed_interval(
            Rational::ONE,
            Rational::TWO
        ),
        20
    ),
    "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...]"
);
assert_eq!(
    prefix_to_string(
        Rational::denominators_in_closed_interval(
            Rational::from_signeds(1, 3),
            Rational::from_signeds(1, 2)
        ),
        20
    ),
    "[2, 3, 5, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, ...]"
);
assert_eq!(
    prefix_to_string(
        Rational::denominators_in_closed_interval(
            Rational::from_signeds(1, 1000001),
            Rational::from_signeds(1, 1000000)
        ),
        20
    ),
    "[1000000, 1000001, 3000001, 3000002, 4000001, 4000003, 5000001, 5000002, 5000003, \
    5000004, 6000001, 6000005, 7000001, 7000002, 7000003, 7000004, 7000005, 7000006, \
    8000001, 8000003, ...]"
);
§

type Denominators = DenominatorsInClosedRationalInterval

source§

impl Display for Rational

source§

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

Converts a Rational to a String.

§Worst-case complexity

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

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

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

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::ZERO.to_string(), "0");
assert_eq!(Rational::from(123).to_string(), "123");
assert_eq!(Rational::from_str("22/7").unwrap().to_string(), "22/7");
source§

impl<'a, 'b> Div<&'a Rational> for &'b Rational

source§

fn div(self, other: &'a Rational) -> Rational

Divides a Rational by another Rational, taking both by reference.

$$ f(x, y) = \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

assert_eq!(&Rational::TWO / &Rational::TWO, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) / &Rational::from_signeds(99, 100)).to_string(),
    "200/63"
);
§

type Output = Rational

The resulting type after applying the / operator.
source§

impl<'a> Div<&'a Rational> for Rational

source§

fn div(self, other: &'a Rational) -> Rational

Divides a Rational by another Rational, taking the first by value and the second by reference.

$$ f(x, y) = \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

assert_eq!(Rational::TWO / &Rational::TWO, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) / &Rational::from_signeds(99, 100)).to_string(),
    "200/63"
);
§

type Output = Rational

The resulting type after applying the / operator.
source§

impl<'a> Div<Rational> for &'a Rational

source§

fn div(self, other: Rational) -> Rational

Divides a Rational by another Rational, taking the first by reference and the second by value.

$$ f(x, y) = \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

assert_eq!(&Rational::TWO / Rational::TWO, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) / Rational::from_signeds(99, 100)).to_string(),
    "200/63"
);
§

type Output = Rational

The resulting type after applying the / operator.
source§

impl Div for Rational

source§

fn div(self, other: Rational) -> Rational

Divides a Rational by another Rational, taking both by value.

$$ f(x, y) = \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

assert_eq!(Rational::TWO / Rational::TWO, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) / Rational::from_signeds(99, 100)).to_string(),
    "200/63"
);
§

type Output = Rational

The resulting type after applying the / operator.
source§

impl<'a> DivAssign<&'a Rational> for Rational

source§

fn div_assign(&mut self, other: &'a Rational)

Divides a Rational by a Rational in place, taking the Rational on the right-hand side by reference.

$$ x \gets \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

let mut x = Rational::TWO;
x /= &Rational::TWO;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x /= &Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "200/63");
source§

impl DivAssign for Rational

source§

fn div_assign(&mut self, other: Rational)

Divides a Rational by a Rational in place, taking the Rational on the right-hand side by value.

$$ x \gets \frac{x}{y}. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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()).

§Panics

Panics if the second Rational is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_q::Rational;

let mut x = Rational::TWO;
x /= Rational::TWO;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x /= Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "200/63");
source§

impl<'a> Floor for &'a Rational

source§

fn floor(self) -> Integer

Finds the floor of a Rational, taking the Rational by reference.

$$ f(x) = \lfloor x \rfloor. $$

§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::arithmetic::traits::Floor;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!((&Rational::ZERO).floor(), 0);
assert_eq!((&Rational::from_signeds(22, 7)).floor(), 3);
assert_eq!((&Rational::from_signeds(-22, 7)).floor(), -4);
§

type Output = Integer

source§

impl Floor for Rational

source§

fn floor(self) -> Integer

Finds the floor of a Rational, taking the Rational by value.

$$ f(x) = \lfloor x \rfloor. $$

§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::arithmetic::traits::Floor;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.floor(), 0);
assert_eq!(Rational::from_signeds(22, 7).floor(), 3);
assert_eq!(Rational::from_signeds(-22, 7).floor(), -4);
§

type Output = Integer

source§

impl FloorAssign for Rational

source§

fn floor_assign(&mut self)

Replaces a Rational with its floor.

$$ x \gets \lfloor x \rfloor. $$

§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::arithmetic::traits::FloorAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;
use std::str::FromStr;

let mut x = Rational::ZERO;
x.floor_assign();
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x.floor_assign();
assert_eq!(x, 3);

let mut x = Rational::from_signeds(-22, 7);
x.floor_assign();
assert_eq!(x, -4);
source§

impl<'a, 'b> FloorLogBase<&'b Rational> for &'a Rational

source§

fn floor_log_base(self, base: &Rational) -> i64

Returns the floor of the base-$b$ logarithm of a positive Rational.

Note that this function may be slow if the base is very close to 1.

$f(x, b) = \lfloor\log_b x\rfloor$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is base.significant_bits(), and $m$ is $|\log_b x|$, where $b$ is base and $x$ is x.

§Panics

Panics if self less than or equal to zero or base is 1.

§Examples
use malachite_base::num::arithmetic::traits::FloorLogBase;
use malachite_q::Rational;

assert_eq!(Rational::from(80u32).floor_log_base(&Rational::from(3u32)), 3);
assert_eq!(Rational::from(81u32).floor_log_base(&Rational::from(3u32)), 4);
assert_eq!(Rational::from(82u32).floor_log_base(&Rational::from(3u32)), 4);
assert_eq!(Rational::from(4294967296u64).floor_log_base(&Rational::from(10u32)), 9);
assert_eq!(
    Rational::from_signeds(936851431250i64, 1397).floor_log_base(&Rational::from(10u32)),
    8
);
assert_eq!(
    Rational::from_signeds(5153632, 16807).floor_log_base(&Rational::from_signeds(22, 7)),
    5
);
§

type Output = i64

source§

impl<'a> FloorLogBase2 for &'a Rational

source§

fn floor_log_base_2(self) -> i64

Returns the floor of the base-2 logarithm of a positive Rational.

$f(x) = \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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::FloorLogBase2;
use malachite_q::Rational;

assert_eq!(Rational::from(3u32).floor_log_base_2(), 1);
assert_eq!(Rational::from_signeds(1, 3).floor_log_base_2(), -2);
assert_eq!(Rational::from_signeds(1, 4).floor_log_base_2(), -2);
assert_eq!(Rational::from_signeds(1, 5).floor_log_base_2(), -3);
§

type Output = i64

source§

impl<'a> FloorLogBasePowerOf2<i64> for &'a Rational

source§

fn floor_log_base_power_of_2(self, pow: i64) -> i64

Returns the floor of the base-$2^k$ logarithm of a positive Rational.

$k$ may be negative.

$f(x, k) = \lfloor\log_{2^k} 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 less than or equal to 0 or pow is 0.

§Examples
use malachite_base::num::arithmetic::traits::FloorLogBasePowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::from(100).floor_log_base_power_of_2(2), 3);
assert_eq!(Rational::from(4294967296u64).floor_log_base_power_of_2(8), 4);

// 4^(-2) < 1/10 < 4^(-1)
assert_eq!(Rational::from_signeds(1, 10).floor_log_base_power_of_2(2), -2);
// (1/4)^2 < 1/10 < (1/4)^1
assert_eq!(Rational::from_signeds(1, 10).floor_log_base_power_of_2(-2), 1);
§

type Output = i64

source§

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

source§

fn from(value: &'a Integer) -> Rational

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(Rational::from(&Integer::from(123)), 123);
assert_eq!(Rational::from(&Integer::from(-123)), -123);
source§

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

source§

fn from(value: &'a Natural) -> Rational

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(Rational::from(&Natural::from(123u32)), 123);
source§

impl From<Integer> for Rational

source§

fn from(value: Integer) -> Rational

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(Rational::from(Integer::from(123)), 123);
assert_eq!(Rational::from(Integer::from(-123)), -123);
source§

impl From<Natural> for Rational

source§

fn from(value: Natural) -> Rational

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(Rational::from(Natural::from(123u32)), 123);
source§

impl From<bool> for Rational

source§

fn from(b: bool) -> Rational

Converts a bool to 0 or 1.

This function is known as the Iverson bracket.

$$ f(P) = [P] = \begin{cases} 1 & \text{if} \quad P, \\ 0 & \text{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_q::Rational;

assert_eq!(Rational::from(false), 0);
assert_eq!(Rational::from(true), 1);
source§

impl From<i128> for Rational

source§

fn from(i: i128) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<i16> for Rational

source§

fn from(i: i16) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<i32> for Rational

source§

fn from(i: i32) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<i64> for Rational

source§

fn from(i: i64) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<i8> for Rational

source§

fn from(i: i8) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<isize> for Rational

source§

fn from(i: isize) -> Rational

Converts a signed primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<u128> for Rational

source§

fn from(u: u128) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<u16> for Rational

source§

fn from(u: u16) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<u32> for Rational

source§

fn from(u: u32) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<u64> for Rational

source§

fn from(u: u64) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<u8> for Rational

source§

fn from(u: u8) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl From<usize> for Rational

source§

fn from(u: usize) -> Rational

Converts an unsigned primitive integer to a Rational.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

source§

impl FromSciString for Rational

source§

fn from_sci_string_with_options( s: &str, options: FromSciStringOptions ) -> Option<Rational>

Converts a string, possibly in scientfic notation, to a Rational.

Use FromSciStringOptions to specify the base (from 2 to 36, inclusive). The rounding mode option is ignored.

If the base is greater than 10, the higher digits are represented by the letters 'a' through 'z' or 'A' through 'Z'; the case doesn’t matter and doesn’t need to be consistent.

Exponents are allowed, and are indicated using the character 'e' or 'E'. If the base is 15 or greater, an ambiguity arises where it may not be clear whether 'e' is a digit or an exponent indicator. To resolve this ambiguity, always use a '+' or '-' sign after the exponent indicator when the base is 15 or greater.

The exponent itself is always parsed using base 10.

Decimal (or other-base) points are allowed.

If the string is unparseable, None is returned.

This function is very literal; given "0.333", it will return $333/1000$ rather than $1/3$. If you’d prefer that it return $1/3$, consider using from_sci_string_simplest instead. However, that function has its quirks too: given "0.1", it will not return $1/10$ (see its documentation for an explanation of this behavior). This function does return $1/10$.

§Worst-case complexity

$T(n, m) = O(m^n n \log m (\log n + \log\log m))$

$M(n, m) = O(m^n n \log m)$

where $T$ is time, $M$ is additional memory, $n$ is s.len(), and $m$ is options.base.

§Examples
use malachite_base::num::conversion::string::options::FromSciStringOptions;
use malachite_base::num::conversion::traits::FromSciString;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;

assert_eq!(Rational::from_sci_string("123").unwrap(), 123);
assert_eq!(Rational::from_sci_string("0.1").unwrap().to_string(), "1/10");
assert_eq!(Rational::from_sci_string("0.10").unwrap().to_string(), "1/10");
assert_eq!(Rational::from_sci_string("0.333").unwrap().to_string(), "333/1000");
assert_eq!(Rational::from_sci_string("1.2e5").unwrap(), 120000);
assert_eq!(Rational::from_sci_string("1.2e-5").unwrap().to_string(), "3/250000");

let mut options = FromSciStringOptions::default();
options.set_base(16);
assert_eq!(Rational::from_sci_string_with_options("ff", options).unwrap(), 255);
assert_eq!(Rational::from_sci_string_with_options("ffE+5", options).unwrap(), 267386880);
assert_eq!(
    Rational::from_sci_string_with_options("ffE-5", options).unwrap().to_string(),
    "255/1048576"
);
source§

fn from_sci_string(s: &str) -> Option<Self>

Converts a &str, possibly in scientific notation, to a number, using the default FromSciStringOptions.
source§

impl FromStr for Rational

source§

fn from_str(s: &str) -> Result<Rational, ()>

Converts an string to a Rational.

If the string does not represent a valid Rational, an Err is returned. The numerator and denominator do not need to be in lowest terms, but the denominator must be nonzero. A negative sign is only allowed at the 0th position of the string.

§Worst-case complexity

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

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

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

§Examples
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::from_str("123456").unwrap(), 123456);
assert_eq!(Rational::from_str("00123456").unwrap(), 123456);
assert_eq!(Rational::from_str("0").unwrap(), 0);
assert_eq!(Rational::from_str("-123456").unwrap(), -123456);
assert_eq!(Rational::from_str("-00123456").unwrap(), -123456);
assert_eq!(Rational::from_str("-0").unwrap(), 0);
assert_eq!(Rational::from_str("22/7").unwrap().to_string(), "22/7");
assert_eq!(Rational::from_str("01/02").unwrap().to_string(), "1/2");
assert_eq!(Rational::from_str("3/21").unwrap().to_string(), "1/7");
assert_eq!(Rational::from_str("-22/7").unwrap().to_string(), "-22/7");
assert_eq!(Rational::from_str("-01/02").unwrap().to_string(), "-1/2");
assert_eq!(Rational::from_str("-3/21").unwrap().to_string(), "-1/7");

assert!(Rational::from_str("").is_err());
assert!(Rational::from_str("a").is_err());
assert!(Rational::from_str("1/0").is_err());
assert!(Rational::from_str("/1").is_err());
assert!(Rational::from_str("1/").is_err());
assert!(Rational::from_str("--1").is_err());
assert!(Rational::from_str("1/-2").is_err());
§

type Err = ()

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

impl Hash for Rational

source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

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

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

impl<'a> IsInteger for &'a Rational

source§

fn is_integer(self) -> bool

Determines whether a Rational is an integer.

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.is_integer(), true);
assert_eq!(Rational::ONE.is_integer(), true);
assert_eq!(Rational::from(100).is_integer(), true);
assert_eq!(Rational::from(-100).is_integer(), true);
assert_eq!(Rational::from_signeds(22, 7).is_integer(), false);
assert_eq!(Rational::from_signeds(-22, 7).is_integer(), false);
source§

impl IsPowerOf2 for Rational

source§

fn is_power_of_2(&self) -> bool

Determines whether a Rational is an integer power of 2.

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

§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::IsPowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::from(0x80).is_power_of_2(), true);
assert_eq!(Rational::from_signeds(1, 8).is_power_of_2(), true);
assert_eq!(Rational::from_signeds(-1, 8).is_power_of_2(), false);
assert_eq!(Rational::from_signeds(22, 7).is_power_of_2(), false);
source§

impl<'a, 'b> Mul<&'a Rational> for &'b Rational

source§

fn mul(self, other: &'a Rational) -> Rational

Multiplies two Rationals, taking both by reference.

$$ f(x, y) = xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::{OneHalf, Two};
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF * &Rational::TWO, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) * &Rational::from_signeds(99, 100)).to_string(),
    "1089/350"
);
§

type Output = Rational

The resulting type after applying the * operator.
source§

impl<'a> Mul<&'a Rational> for Rational

source§

fn mul(self, other: &'a Rational) -> Rational

Multiplies two Rationals, taking the first by value and the second by reference.

$$ f(x, y) = xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::{OneHalf, Two};
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF * &Rational::TWO, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) * &Rational::from_signeds(99, 100)).to_string(),
    "1089/350"
);
§

type Output = Rational

The resulting type after applying the * operator.
source§

impl<'a> Mul<Rational> for &'a Rational

source§

fn mul(self, other: Rational) -> Rational

Multiplies two Rationals, taking the first by reference and the second by value.

$$ f(x, y) = xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::{OneHalf, Two};
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF * Rational::TWO, 1);
assert_eq!(
    (&Rational::from_signeds(22, 7) * Rational::from_signeds(99, 100)).to_string(),
    "1089/350"
);
§

type Output = Rational

The resulting type after applying the * operator.
source§

impl Mul for Rational

source§

fn mul(self, other: Rational) -> Rational

Multiplies two Rationals, taking both by value.

$$ f(x, y) = xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::{OneHalf, Two};
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF * Rational::TWO, 1);
assert_eq!(
    (Rational::from_signeds(22, 7) * Rational::from_signeds(99, 100)).to_string(),
    "1089/350"
);
§

type Output = Rational

The resulting type after applying the * operator.
source§

impl<'a> MulAssign<&'a Rational> for Rational

source§

fn mul_assign(&mut self, other: &'a Rational)

Multiplies a Rational by a Rational in place, taking the Rational on the right-hand side by reference.

$$ x \gets xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^3 \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::{OneHalf, Two};
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x *= &Rational::TWO;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x *= &Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "1089/350");
source§

impl MulAssign for Rational

source§

fn mul_assign(&mut self, other: Rational)

Multiplies a Rational by a Rational in place, taking the Rational on the right-hand side by value.

$$ x \gets xy. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::{OneHalf, Two};
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x *= Rational::TWO;
assert_eq!(x, 1);

let mut x = Rational::from_signeds(22, 7);
x *= Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "1089/350");
source§

impl Named for Rational

source§

const NAME: &'static str = "Rational"

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 Rational

source§

fn neg(self) -> Rational

Negates a Rational, taking it by reference.

$$ f(x) = -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::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(-&Rational::ZERO, 0);
assert_eq!((-&Rational::from_signeds(22, 7)).to_string(), "-22/7");
assert_eq!((-&Rational::from_signeds(-22, 7)).to_string(), "22/7");
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl Neg for Rational

source§

fn neg(self) -> Rational

Negates a Rational, taking it by value.

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

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(-Rational::ZERO, 0);
assert_eq!((-Rational::from_signeds(22, 7)).to_string(), "-22/7");
assert_eq!((-Rational::from_signeds(-22, 7)).to_string(), "22/7");
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl NegAssign for Rational

source§

fn neg_assign(&mut self)

Negates a Rational in place.

$$ x \gets -x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::NegAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::ZERO;
x.neg_assign();
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x.neg_assign();
assert_eq!(x.to_string(), "-22/7");

let mut x = Rational::from_signeds(-22, 7);
x.neg_assign();
assert_eq!(x.to_string(), "22/7");
source§

impl NegativeOne for Rational

The constant -1.

source§

impl<'a> NextPowerOf2 for &'a Rational

source§

fn next_power_of_2(self) -> Rational

Finds the smallest power of 2 greater than or equal to a Rational. The Rational is taken by reference.

$f(x) = 2^{\lceil \log_2 x \rceil}$.

§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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::NextPowerOf2;
use malachite_q::Rational;

assert_eq!((&Rational::from(123)).next_power_of_2(), 128);
assert_eq!((&Rational::from_signeds(1, 10)).next_power_of_2().to_string(), "1/8");
§

type Output = Rational

source§

impl NextPowerOf2 for Rational

source§

fn next_power_of_2(self) -> Rational

Finds the smallest power of 2 greater than or equal to a Rational. The Rational is taken by value.

$f(x) = 2^{\lceil \log_2 x \rceil}$.

§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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::NextPowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::from(123).next_power_of_2(), 128);
assert_eq!(Rational::from_signeds(1, 10).next_power_of_2().to_string(), "1/8");
§

type Output = Rational

source§

impl NextPowerOf2Assign for Rational

source§

fn next_power_of_2_assign(&mut self)

Finds the smallest power of 2 greater than or equal to a Rational. The Rational is taken by reference.

$f(x) = 2^{\lceil \log_2 x \rceil}$.

§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 less than or equal to zero.

§Examples
use malachite_base::num::arithmetic::traits::NextPowerOf2Assign;
use malachite_q::Rational;
use std::str::FromStr;

let mut x = Rational::from(123);
x.next_power_of_2_assign();
assert_eq!(x, 128);

let mut x = Rational::from_signeds(1, 10);
x.next_power_of_2_assign();
assert_eq!(x.to_string(), "1/8");
source§

impl One for Rational

The constant 1.

source§

impl OneHalf for Rational

The constant 1/2.

source§

impl Ord for Rational

source§

fn cmp(&self, other: &Rational) -> Ordering

Compares two Rationals.

§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::OneHalf;
use malachite_q::Rational;
use std::str::FromStr;

assert!(Rational::from_str("2/3").unwrap() > Rational::ONE_HALF);
assert!(Rational::from_str("-2/3").unwrap() < Rational::ONE_HALF);
1.21.0 · source§

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

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

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

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

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

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

impl OrdAbs for Rational

source§

fn cmp_abs(&self, other: &Rational) -> Ordering

Compares the absolute values of two Rationals.

§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::OneHalf;
use malachite_base::num::comparison::traits::OrdAbs;
use malachite_q::Rational;
use std::cmp::Ordering;
use std::str::FromStr;

assert_eq!(
    Rational::from_str("2/3").unwrap().cmp_abs(&Rational::ONE_HALF),
    Ordering::Greater
);
assert_eq!(
    Rational::from_str("-2/3").unwrap().cmp_abs(&Rational::ONE_HALF),
    Ordering::Greater
);
source§

impl PartialEq<Integer> for Rational

source§

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

Determines whether a Rational is equal to an Integer.

§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_nz::integer::Integer;
use malachite_q::Rational;

assert!(Rational::from(-123) == Integer::from(-123));
assert!(Rational::from_signeds(22, 7) != Integer::from(5));
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 Rational

source§

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

Determines whether a Rational is equal to a Natural.

§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_nz::natural::Natural;
use malachite_q::Rational;

assert!(Rational::from(123) == Natural::from(123u32));
assert!(Rational::from_signeds(22, 7) != Natural::from(5u32));
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 Integer

source§

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

Determines whether an Integer is equal to a Rational.

§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_nz::integer::Integer;
use malachite_q::Rational;

assert!(Integer::from(-123) == Rational::from(-123));
assert!(Integer::from(5) != Rational::from_signeds(22, 7));
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 Natural

source§

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

Determines whether a Natural is equal to a Rational.

§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_nz::natural::Natural;
use malachite_q::Rational;

assert!(Natural::from(123u32) == Rational::from(123));
assert!(Natural::from(5u32) != Rational::from_signeds(22, 7));
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 f32

source§

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

Determines whether a primitive float is equal to a Rational.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.sci_exponent().abs(), other.significant_bits()), and $m$ is self.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<Rational> for f64

source§

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

Determines whether a primitive float is equal to a Rational.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.sci_exponent().abs(), other.significant_bits()), and $m$ is self.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<Rational> for i128

source§

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

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

§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<Rational> for i16

source§

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

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

§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<Rational> for i32

source§

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

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

§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<Rational> for i64

source§

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

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

§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<Rational> for i8

source§

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

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

§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<Rational> for isize

source§

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

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

§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<Rational> for u128

source§

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

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

§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<Rational> for u16

source§

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

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

§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<Rational> for u32

source§

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

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

§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<Rational> for u64

source§

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

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

§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<Rational> for u8

source§

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

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

§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<Rational> for usize

source§

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

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

§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<f32> for Rational

source§

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

Determines whether a Rational is equal to a primitive float.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.sci_exponent().abs()), and $m$ is 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 Rational

source§

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

Determines whether a Rational is equal to a primitive float.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.sci_exponent().abs()), and $m$ is 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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

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

§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 Rational

source§

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

This method tests for self and other values to be equal, and is used by ==.
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<Integer> for Rational

source§

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

Compares a Rational to an Integer.

§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_nz::integer::Integer;
use malachite_q::Rational;

assert!(Rational::from_signeds(22, 7) > Integer::from(3));
assert!(Rational::from_signeds(22, 7) < Integer::from(4));
assert!(Rational::from_signeds(-22, 7) < Integer::from(-3));
assert!(Rational::from_signeds(-22, 7) > Integer::from(-4));
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 Rational

source§

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

Compares a Rational to a Natural.

§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_nz::natural::Natural;
use malachite_q::Rational;

assert!(Rational::from_signeds(22, 7) > Natural::from(3u32));
assert!(Rational::from_signeds(22, 7) < Natural::from(4u32));
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 Integer

source§

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

Compares an Integer to a Rational.

§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_nz::integer::Integer;
use malachite_q::Rational;

assert!(Integer::from(3) < Rational::from_signeds(22, 7));
assert!(Integer::from(4) > Rational::from_signeds(22, 7));
assert!(Integer::from(-3) > Rational::from_signeds(-22, 7));
assert!(Integer::from(-4) < Rational::from_signeds(-22, 7));
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 Natural

source§

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

Compares a Natural to a Rational.

§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_nz::natural::Natural;
use malachite_q::Rational;

assert!(Natural::from(3u32) < Rational::from_signeds(22, 7));
assert!(Natural::from(4u32) > Rational::from_signeds(22, 7));
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 f32

source§

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

Compares a primitive float to a Rational.

§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(other.sci_exponent().abs(), 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<Rational> for f64

source§

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

Compares a primitive float to a Rational.

§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(other.sci_exponent().abs(), 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<Rational> for i128

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for i16

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for i32

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for i64

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for i8

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for isize

source§

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

Compares a signed primitive integer to a Rational.

§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 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<Rational> for u128

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<Rational> for u16

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<Rational> for u32

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<Rational> for u64

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<Rational> for u8

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<Rational> for usize

source§

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

Compares an unsigned primitive integer to a Rational.

§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 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<f32> for Rational

source§

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

Compares a Rational to a primitive float.

§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.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 Rational

source§

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

Compares a Rational to a primitive float.

§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.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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to a signed primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares a Rational to an unsigned primitive integer.

§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 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 Rational

source§

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

Compares two Rationals.

See the documentation for the Ord implementation.

1.0.0 · source§

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

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

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

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

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

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

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

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

impl PartialOrdAbs<Integer> for Rational

source§

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

Compares the absolute values of a Rational and an Integer.

§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::comparison::traits::PartialOrdAbs;
use malachite_nz::integer::Integer;
use malachite_q::Rational;
use std::cmp::Ordering;

assert_eq!(
    Rational::from_signeds(22, 7).partial_cmp_abs(&Integer::from(3)),
    Some(Ordering::Greater)
);
assert_eq!(
    Rational::from_signeds(-22, 7).partial_cmp_abs(&Integer::from(-3)),
    Some(Ordering::Greater)
);
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 Rational

source§

fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>

Compares the absolute values of a Rational and a Natural.

§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::comparison::traits::PartialOrdAbs;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::cmp::Ordering;

assert_eq!(
    Rational::from_signeds(22, 7).partial_cmp_abs(&Natural::from(3u32)),
    Some(Ordering::Greater)
);
assert_eq!(
    Rational::from_signeds(-22, 7).partial_cmp_abs(&Natural::from(3u32)),
    Some(Ordering::Greater)
);
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 Integer

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an Integer and a Rational.

§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::comparison::traits::PartialOrdAbs;
use malachite_nz::integer::Integer;
use malachite_q::Rational;
use std::cmp::Ordering;

assert_eq!(
    Integer::from(3).partial_cmp_abs(&Rational::from_signeds(22, 7)),
    Some(Ordering::Less)
);
assert_eq!(
    Integer::from(-3).partial_cmp_abs(&Rational::from_signeds(-22, 7)),
    Some(Ordering::Less)
);
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 Natural

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a Natural and a Rational.

§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::comparison::traits::PartialOrdAbs;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::cmp::Ordering;

assert_eq!(
    Natural::from(3u32).partial_cmp_abs(&Rational::from_signeds(22, 7)),
    Some(Ordering::Less)
);
assert_eq!(
    Natural::from(3u32).partial_cmp_abs(&Rational::from_signeds(-22, 7)),
    Some(Ordering::Less)
);
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 f32

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a primitive float and a Rational.

§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.sci_exponent().abs(), 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<Rational> for f64

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a primitive float and a Rational.

§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.sci_exponent().abs(), 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<Rational> for i128

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for i16

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for i32

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for i64

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for i8

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for isize

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a Rational.

§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 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<Rational> for u128

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<Rational> for u16

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<Rational> for u32

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<Rational> for u64

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<Rational> for u8

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<Rational> for usize

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a Rational.

§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 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<f32> for Rational

source§

fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>

Compares the absolute values of a Rational and a primitive float.

§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.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 Rational

source§

fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>

Compares the absolute values of a Rational and a primitive float.

§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.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 Rational

source§

fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>

Compares the absolute values of a Rational and a signed primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>

Compares the absolute values of a Rational and an unsigned primitive integer.

§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 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 Rational

source§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of two Rationals.

See the documentation for the OrdAbs implementation.

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<'a> Pow<i64> for &'a Rational

source§

fn pow(self, exp: i64) -> Rational

Raises a Rational to a power, taking the Rational by reference.

$f(x, n) = x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Panics

Panics if self is zero and exp is negative.

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!((&Rational::from_signeds(22, 7)).pow(3i64).to_string(), "10648/343");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(3i64).to_string(), "-10648/343");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(4i64).to_string(), "234256/2401");
assert_eq!((&Rational::from_signeds(22, 7)).pow(-3i64).to_string(), "343/10648");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(-3i64).to_string(), "-343/10648");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(-4i64).to_string(), "2401/234256");
§

type Output = Rational

source§

impl Pow<i64> for Rational

source§

fn pow(self, exp: i64) -> Rational

Raises a Rational to a power, taking the Rational by value.

$f(x, n) = x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Panics

Panics if self is zero and exp is negative.

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::from_signeds(22, 7).pow(3i64).to_string(), "10648/343");
assert_eq!(Rational::from_signeds(-22, 7).pow(3i64).to_string(), "-10648/343");
assert_eq!(Rational::from_signeds(-22, 7).pow(4i64).to_string(), "234256/2401");
assert_eq!(Rational::from_signeds(22, 7).pow(-3i64).to_string(), "343/10648");
assert_eq!(Rational::from_signeds(-22, 7).pow(-3i64).to_string(), "-343/10648");
assert_eq!(Rational::from_signeds(-22, 7).pow(-4i64).to_string(), "2401/234256");
§

type Output = Rational

source§

impl<'a> Pow<u64> for &'a Rational

source§

fn pow(self, exp: u64) -> Rational

Raises a Rational to a power, taking the Rational by reference.

$f(x, n) = x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!((&Rational::from_signeds(22, 7)).pow(3u64).to_string(), "10648/343");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(3u64).to_string(), "-10648/343");
assert_eq!((&Rational::from_signeds(-22, 7)).pow(4u64).to_string(), "234256/2401");
§

type Output = Rational

source§

impl Pow<u64> for Rational

source§

fn pow(self, exp: u64) -> Rational

Raises a Rational to a power, taking the Rational by value.

$f(x, n) = x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::from_signeds(22, 7).pow(3u64).to_string(), "10648/343");
assert_eq!(Rational::from_signeds(-22, 7).pow(3u64).to_string(), "-10648/343");
assert_eq!(Rational::from_signeds(-22, 7).pow(4u64).to_string(), "234256/2401");
§

type Output = Rational

source§

impl PowAssign<i64> for Rational

source§

fn pow_assign(&mut self, exp: i64)

Raises a Rational to a power in place.

$x \gets x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Panics

Panics if self is zero and exp is negative.

§Examples
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(3i64);
assert_eq!(x.to_string(), "10648/343");

let mut x = Rational::from_signeds(-22, 7);
x.pow_assign(3i64);
assert_eq!(x.to_string(), "-10648/343");

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(4i64);
assert_eq!(x.to_string(), "234256/2401");

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(-3i64);
assert_eq!(x.to_string(), "343/10648");

let mut x = Rational::from_signeds(-22, 7);
x.pow_assign(-3i64);
assert_eq!(x.to_string(), "-343/10648");

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(-4i64);
assert_eq!(x.to_string(), "2401/234256");
source§

impl PowAssign<u64> for Rational

source§

fn pow_assign(&mut self, exp: u64)

Raises a Rational to a power in place.

$x \gets x^n$.

§Worst-case complexity

$T(n, m) = O(nm \log (nm) \log\log (nm))$

$M(n, m) = O(nm \log (nm))$

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

§Examples
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(3u64);
assert_eq!(x.to_string(), "10648/343");

let mut x = Rational::from_signeds(-22, 7);
x.pow_assign(3u64);
assert_eq!(x.to_string(), "-10648/343");

let mut x = Rational::from_signeds(22, 7);
x.pow_assign(4u64);
assert_eq!(x.to_string(), "234256/2401");
source§

impl PowerOf2<i64> for Rational

source§

fn power_of_2(pow: i64) -> Rational

Raises 2 to an integer power.

$f(k) = 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::power_of_2(0i64), 1);
assert_eq!(Rational::power_of_2(3i64), 8);
assert_eq!(Rational::power_of_2(100i64).to_string(), "1267650600228229401496703205376");
assert_eq!(Rational::power_of_2(-3i64).to_string(), "1/8");
assert_eq!(Rational::power_of_2(-100i64).to_string(), "1/1267650600228229401496703205376");
source§

impl PowerOf2<u64> for Rational

source§

fn power_of_2(pow: u64) -> Rational

Raises 2 to an integer power.

$f(k) = 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_q::Rational;

assert_eq!(Rational::power_of_2(0u64), 1);
assert_eq!(Rational::power_of_2(3u64), 8);
assert_eq!(Rational::power_of_2(100u64).to_string(), "1267650600228229401496703205376");
source§

impl<'a> Product<&'a Rational> for Rational

source§

fn product<I>(xs: I) -> Rational
where I: Iterator<Item = &'a Rational>,

Multiplies together all the Rationals in an iterator of Rational references.

$$ f((x_i)_ {i=0}^{n-1}) = \prod_ {i=0}^{n-1} x_i. $$

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, and $n$ is Rational::sum(xs.map(Rational::significant_bits)).

§Examples
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;
use std::iter::Product;

assert_eq!(
    Rational::product(
        vec_from_str::<Rational>("[1, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10]")
            .unwrap().iter()
    ).to_string(),
    "1/5"
);
source§

impl Product for Rational

source§

fn product<I>(xs: I) -> Rational
where I: Iterator<Item = Rational>,

Multiplies together all the Rationals in an iterator.

$$ f((x_i)_ {i=0}^{n-1}) = \prod_ {i=0}^{n-1} x_i. $$

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, and $n$ is Rational::sum(xs.map(Rational::significant_bits)).

§Examples
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;
use std::iter::Product;

assert_eq!(
    Rational::product(
        vec_from_str::<Rational>("[1, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10]")
            .unwrap().into_iter()
    ).to_string(),
    "1/5"
);
source§

impl<'a> Reciprocal for &'a Rational

source§

fn reciprocal(self) -> Rational

Reciprocates a Rational, taking it by reference.

$$ f(x) = 1/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::Reciprocal;
use malachite_q::Rational;

assert_eq!((&Rational::from_signeds(22, 7)).reciprocal().to_string(), "7/22");
assert_eq!((&Rational::from_signeds(7, 22)).reciprocal().to_string(), "22/7");
§

type Output = Rational

source§

impl Reciprocal for Rational

source§

fn reciprocal(self) -> Rational

Reciprocates a Rational, taking it by value.

$$ f(x) = 1/x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::Reciprocal;
use malachite_q::Rational;

assert_eq!(Rational::from_signeds(22, 7).reciprocal().to_string(), "7/22");
assert_eq!(Rational::from_signeds(7, 22).reciprocal().to_string(), "22/7");
§

type Output = Rational

source§

impl ReciprocalAssign for Rational

source§

fn reciprocal_assign(&mut self)

Reciprocates a Rational in place.

$$ x \gets 1/x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::ReciprocalAssign;
use malachite_q::Rational;

let mut x = Rational::from_signeds(22, 7);
x.reciprocal_assign();
assert_eq!(x.to_string(), "7/22");

let mut x = Rational::from_signeds(7, 22);
x.reciprocal_assign();
assert_eq!(x.to_string(), "22/7");
source§

impl<'a, 'b> RoundToMultiple<&'b Rational> for &'a Rational

source§

fn round_to_multiple( self, other: &'b Rational, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of another Rational, according to a specified rounding mode. Both Rationals are taken by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{y}$:

$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$

$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$

$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \Z$.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(
    (&Rational::from(-5)).round_to_multiple(&Rational::ZERO, RoundingMode::Down)
        .to_debug_string(),
    "(0, Greater)"
);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);
assert_eq!(
    (&q).round_to_multiple(&hundredth, RoundingMode::Down).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    (&q).round_to_multiple(&hundredth, RoundingMode::Floor).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    (&q).round_to_multiple(&hundredth, RoundingMode::Up).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    (&q).round_to_multiple(&hundredth, RoundingMode::Ceiling).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    (&q).round_to_multiple(&hundredth, RoundingMode::Nearest).to_debug_string(),
    "(157/50, Less)"
);
§

type Output = Rational

source§

impl<'a> RoundToMultiple<&'a Rational> for Rational

source§

fn round_to_multiple( self, other: &'a Rational, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of another Rational, according to a specified rounding mode. The first Rational is taken by value and the second by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{y}$:

$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$

$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$

$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \Z$.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(
    Rational::from(-5).round_to_multiple(&Rational::ZERO, RoundingMode::Down)
        .to_debug_string(),
    "(0, Greater)"
);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);
assert_eq!(
    q.clone().round_to_multiple(&hundredth, RoundingMode::Down).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    q.clone().round_to_multiple(&hundredth, RoundingMode::Floor).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    q.clone().round_to_multiple(&hundredth, RoundingMode::Up).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple(&hundredth, RoundingMode::Ceiling).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple(&hundredth, RoundingMode::Nearest).to_debug_string(),
    "(157/50, Less)"
);
§

type Output = Rational

source§

impl<'a> RoundToMultiple<Rational> for &'a Rational

source§

fn round_to_multiple( self, other: Rational, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of another Rational, according to a specified rounding mode. The first Rational is taken by reference and the second by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{y}$:

$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$

$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$

$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \Z$.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(
    (&Rational::from(-5)).round_to_multiple(Rational::ZERO, RoundingMode::Down)
        .to_debug_string(),
    "(0, Greater)"
);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);
assert_eq!(
    (&q).round_to_multiple(hundredth.clone(), RoundingMode::Down).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    (&q).round_to_multiple(hundredth.clone(), RoundingMode::Floor).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    (&q).round_to_multiple(hundredth.clone(), RoundingMode::Up).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    (&q).round_to_multiple(hundredth.clone(), RoundingMode::Ceiling).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    (&q).round_to_multiple(hundredth.clone(), RoundingMode::Nearest).to_debug_string(),
    "(157/50, Less)"
);
§

type Output = Rational

source§

impl RoundToMultiple for Rational

source§

fn round_to_multiple( self, other: Rational, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of another Rational, according to a specified rounding mode. Both Rationals are taken by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{y}$:

$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$

$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$

$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \Z$.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

assert_eq!(
    Rational::from(-5).round_to_multiple(Rational::ZERO, RoundingMode::Down)
        .to_debug_string(),
    "(0, Greater)"
);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);
assert_eq!(
    q.clone().round_to_multiple(hundredth.clone(), RoundingMode::Down).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    q.clone().round_to_multiple(hundredth.clone(), RoundingMode::Floor).to_debug_string(),
    "(157/50, Less)"
);
assert_eq!(
    q.clone().round_to_multiple(hundredth.clone(), RoundingMode::Up).to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple(hundredth.clone(), RoundingMode::Ceiling)
        .to_debug_string(),
    "(63/20, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple(hundredth.clone(), RoundingMode::Nearest)
        .to_debug_string(),
    "(157/50, Less)"
);
§

type Output = Rational

source§

impl<'a> RoundToMultipleAssign<&'a Rational> for Rational

source§

fn round_to_multiple_assign( &mut self, other: &'a Rational, rm: RoundingMode ) -> Ordering

Rounds a Rational to an integer multiple of another Rational in place, according to a specified rounding mode. The Rational on the right-hand side is taken by reference. An Ordering is returned, indicating whether the returned value is less than, equal to, or greater than the original value.

See the RoundToMultiple documentation for details.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;
use std::cmp::Ordering;

let mut x = Rational::from(-5);
assert_eq!(
    x.round_to_multiple_assign(&Rational::ZERO, RoundingMode::Down),
    Ordering::Greater
);
assert_eq!(x, 0);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);

let mut x = q.clone();
assert_eq!(x.round_to_multiple_assign(&hundredth, RoundingMode::Down), Ordering::Less);
assert_eq!(x.to_string(), "157/50");

let mut x = q.clone();
assert_eq!(x.round_to_multiple_assign(&hundredth, RoundingMode::Floor), Ordering::Less);
assert_eq!(x.to_string(), "157/50");

let mut x = q.clone();
assert_eq!(x.round_to_multiple_assign(&hundredth, RoundingMode::Up), Ordering::Greater);
assert_eq!(x.to_string(), "63/20");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(&hundredth, RoundingMode::Ceiling),
    Ordering::Greater
);
assert_eq!(x.to_string(), "63/20");

let mut x = q.clone();
assert_eq!(x.round_to_multiple_assign(&hundredth, RoundingMode::Nearest), Ordering::Less);
assert_eq!(x.to_string(), "157/50");
source§

impl RoundToMultipleAssign for Rational

source§

fn round_to_multiple_assign( &mut self, other: Rational, rm: RoundingMode ) -> Ordering

Rounds a Rational to an integer multiple of another Rational in place, according to a specified rounding mode. The Rational on the right-hand side is taken by value. An Ordering is returned, indicating whether the returned value is less than, equal to, or greater than the original value.

See the RoundToMultiple documentation for details.

§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 self.significant_bits().

§Panics
  • If rm is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;
use std::cmp::Ordering;

let mut x = Rational::from(-5);
assert_eq!(
    x.round_to_multiple_assign(Rational::ZERO, RoundingMode::Down),
    Ordering::Greater)
;
assert_eq!(x, 0);

let q = Rational::exact_from(std::f64::consts::PI);
let hundredth = Rational::from_signeds(1, 100);

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(hundredth.clone(), RoundingMode::Down),
    Ordering::Less
);
assert_eq!(x.to_string(), "157/50");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(hundredth.clone(), RoundingMode::Floor),
    Ordering::Less
);
assert_eq!(x.to_string(), "157/50");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(hundredth.clone(), RoundingMode::Up),
    Ordering::Greater
);
assert_eq!(x.to_string(), "63/20");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(hundredth.clone(), RoundingMode::Ceiling),
    Ordering::Greater
);
assert_eq!(x.to_string(), "63/20");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_assign(hundredth.clone(), RoundingMode::Nearest),
    Ordering::Less
);
assert_eq!(x.to_string(), "157/50");
source§

impl<'a> RoundToMultipleOfPowerOf2<i64> for &'a Rational

source§

fn round_to_multiple_of_power_of_2( self, pow: i64, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of $2^k$ according to a specified rounding mode. The Rational is taken by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{2^k}$:

$f(x, k, \mathrm{Down}) = 2^k \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = 2^k \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$

$f(x, k, \mathrm{Ceiling}) = 2^k \lceil q \rceil.$

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, k, \mathrm{Exact}) = 2^k q$, but panics if $q \notin \Z$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH).

§Panics

Panics if rm is Exact, but self is not a multiple of the power of 2.

§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

let q = Rational::exact_from(std::f64::consts::PI);
assert_eq!(
    (&q).round_to_multiple_of_power_of_2(-3, RoundingMode::Floor).to_debug_string(),
    "(25/8, Less)"
);
assert_eq!(
    (&q).round_to_multiple_of_power_of_2(-3, RoundingMode::Down).to_debug_string(),
    "(25/8, Less)"
);
assert_eq!(
    (&q).round_to_multiple_of_power_of_2(-3, RoundingMode::Ceiling).to_debug_string(),
    "(13/4, Greater)"
);
assert_eq!(
    (&q).round_to_multiple_of_power_of_2(-3, RoundingMode::Up).to_debug_string(),
    "(13/4, Greater)"
);
assert_eq!(
    (&q).round_to_multiple_of_power_of_2(-3, RoundingMode::Nearest).to_debug_string(),
    "(25/8, Less)"
);
§

type Output = Rational

source§

impl RoundToMultipleOfPowerOf2<i64> for Rational

source§

fn round_to_multiple_of_power_of_2( self, pow: i64, rm: RoundingMode ) -> (Rational, Ordering)

Rounds a Rational to an integer multiple of $2^k$ according to a specified rounding mode. The Rational is taken by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

Let $q = \frac{x}{2^k}$:

$f(x, k, \mathrm{Down}) = 2^k \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = 2^k \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$

$f(x, k, \mathrm{Ceiling}) = 2^k \lceil q \rceil.$

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$

$f(x, k, \mathrm{Exact}) = 2^k q$, but panics if $q \notin \Z$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH).

§Panics

Panics if rm is Exact, but self is not a multiple of the power of 2.

§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;

let q = Rational::exact_from(std::f64::consts::PI);
assert_eq!(
    q.clone().round_to_multiple_of_power_of_2(-3, RoundingMode::Floor).to_debug_string(),
    "(25/8, Less)"
);
assert_eq!(
    q.clone().round_to_multiple_of_power_of_2(-3, RoundingMode::Down).to_debug_string(),
    "(25/8, Less)"
);
assert_eq!(
    q.clone().round_to_multiple_of_power_of_2(-3, RoundingMode::Ceiling).to_debug_string(),
    "(13/4, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple_of_power_of_2(-3, RoundingMode::Up).to_debug_string(),
    "(13/4, Greater)"
);
assert_eq!(
    q.clone().round_to_multiple_of_power_of_2(-3, RoundingMode::Nearest).to_debug_string(),
    "(25/8, Less)"
);
§

type Output = Rational

source§

impl RoundToMultipleOfPowerOf2Assign<i64> for Rational

source§

fn round_to_multiple_of_power_of_2_assign( &mut self, pow: i64, rm: RoundingMode ) -> Ordering

Rounds a Rational to a multiple of $2^k$ in place, according to a specified rounding mode. An Ordering is returned, indicating whether the returned value is less than, equal to, or greater than the original value.

See the RoundToMultipleOfPowerOf2 documentation for details.

but the latter should be used as it is clearer and more efficient.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH).

§Panics

Panics if rm is Exact, but self is not a multiple of the power of 2.

§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;
use std::cmp::Ordering;

let q = Rational::exact_from(std::f64::consts::PI);

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_of_power_of_2_assign(-3, RoundingMode::Floor),
    Ordering::Less
);
assert_eq!(x.to_string(), "25/8");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_of_power_of_2_assign(-3, RoundingMode::Down),
    Ordering::Less
);
assert_eq!(x.to_string(), "25/8");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_of_power_of_2_assign(-3, RoundingMode::Ceiling),
    Ordering::Greater
);
assert_eq!(x.to_string(), "13/4");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_of_power_of_2_assign(-3, RoundingMode::Up),
    Ordering::Greater
);
assert_eq!(x.to_string(), "13/4");

let mut x = q.clone();
assert_eq!(
    x.round_to_multiple_of_power_of_2_assign(-3, RoundingMode::Nearest),
    Ordering::Less
);
assert_eq!(x.to_string(), "25/8");
source§

impl<'a> RoundingFrom<&'a Rational> for Integer

source§

fn rounding_from(x: &Rational, rm: RoundingMode) -> (Integer, Ordering)

Converts a Rational to an Integer, using a specified RoundingMode and taking the Rational by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

§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 x.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Integer::rounding_from(&Rational::from(123), RoundingMode::Exact).to_debug_string(),
    "(123, Equal)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from(-123), RoundingMode::Exact).to_debug_string(),
    "(-123, Equal)"
);

assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(-3, Greater)"
);
source§

impl<'a> RoundingFrom<&'a Rational> for Natural

source§

fn rounding_from(x: &Rational, rm: RoundingMode) -> (Natural, Ordering)

Converts a Rational to a Natural, using a specified RoundingMode and taking the Rational 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 Rational is negative, then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

§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 x.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, or if the Rational is less than zero and rm is not Down, Ceiling, or Nearest.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Natural::rounding_from(&Rational::from(123), RoundingMode::Exact).to_debug_string(),
    "(123, Equal)"
);

assert_eq!(
    Natural::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from_signeds(22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Natural::rounding_from(&Rational::from(-123), RoundingMode::Down).to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from(-123), RoundingMode::Ceiling).to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(&Rational::from(-123), RoundingMode::Nearest).to_debug_string(),
    "(0, Greater)"
);
source§

impl<'a> RoundingFrom<&'a Rational> for f32

source§

fn rounding_from(value: &'a Rational, rm: RoundingMode) -> (f32, Ordering)

Converts a Rational to a value of a primitive float according to a specified RoundingMode, taking the Rational by reference.

  • If the rounding mode is Floor, the largest float less than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If it is smaller than the minimum finite float, then negative infinity is returned. If it is between zero and the minimum positive float, then positive zero is returned.
  • If the rounding mode is Ceiling, the smallest float greater than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then positive infinity is returned. If it is smaller than the minimum finite float, then the minimum finite float is returned. If it is between zero and the maximum negative float, then negative zero is returned.
  • If the rounding mode is Down, then the rounding proceeds as with Floor if the Rational is non-negative and as with Ceiling if the Rational is negative. If the Rational is between the maximum negative float and the minimum positive float, then positive zero is returned when the Rational is non-negative and negative zero otherwise.
  • If the rounding mode is Up, then the rounding proceeds as with Ceiling if the Rational is non-negative and as with Floor if the Rational is negative. Positive zero is only returned when the Rational is zero, and negative zero is never returned.
  • If the rounding mode is Nearest, then the nearest float is returned. If the Rational is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If the Rational is closer to zero than to any float (or if there is a tie between zero and another float), then positive or negative zero is returned, depending on the Rational’s sign.
§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 value.significant_bits().

§Panics

Panics if the rounding mode is Exact and value cannot be represented exactly.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for f64

source§

fn rounding_from(value: &'a Rational, rm: RoundingMode) -> (f64, Ordering)

Converts a Rational to a value of a primitive float according to a specified RoundingMode, taking the Rational by reference.

  • If the rounding mode is Floor, the largest float less than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If it is smaller than the minimum finite float, then negative infinity is returned. If it is between zero and the minimum positive float, then positive zero is returned.
  • If the rounding mode is Ceiling, the smallest float greater than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then positive infinity is returned. If it is smaller than the minimum finite float, then the minimum finite float is returned. If it is between zero and the maximum negative float, then negative zero is returned.
  • If the rounding mode is Down, then the rounding proceeds as with Floor if the Rational is non-negative and as with Ceiling if the Rational is negative. If the Rational is between the maximum negative float and the minimum positive float, then positive zero is returned when the Rational is non-negative and negative zero otherwise.
  • If the rounding mode is Up, then the rounding proceeds as with Ceiling if the Rational is non-negative and as with Floor if the Rational is negative. Positive zero is only returned when the Rational is zero, and negative zero is never returned.
  • If the rounding mode is Nearest, then the nearest float is returned. If the Rational is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If the Rational is closer to zero than to any float (or if there is a tie between zero and another float), then positive or negative zero is returned, depending on the Rational’s sign.
§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 value.significant_bits().

§Panics

Panics if the rounding mode is Exact and value cannot be represented exactly.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for i128

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (i128, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for i16

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (i16, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for i32

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (i32, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for i64

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (i64, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for i8

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (i8, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for isize

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (isize, Ordering)

Converts a Rational to a signed integer, using a specified RoundingMode.

If the Rational is smaller than the minimum value of the unsigned type, then it will be rounded to the minimum value when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than T::MIN and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for u128

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (u128, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for u16

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (u16, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for u32

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (u32, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for u64

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (u64, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for u8

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (u8, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl<'a> RoundingFrom<&'a Rational> for usize

source§

fn rounding_from(value: &Rational, rm: RoundingMode) -> (usize, Ordering)

Converts a Rational to an unsigned integer, using a specified RoundingMode.

If the Rational is negative, then it will be rounded to zero when rm is Ceiling, Down, or Nearest. Otherwise, this function will panic.

If the Rational is larger than the maximum value of the unsigned type, then it will be rounded to the maximum value when rm is Floor, Down, or Nearest. Otherwise, this function will panic.

§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 value.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, if the Rational is less than zero and rm is not Down, Ceiling, or Nearest, or if the Rational is greater than T::MAX and rm is not Down, Floor, or Nearest.

§Examples

See here.

source§

impl RoundingFrom<Rational> for Integer

source§

fn rounding_from(x: Rational, rm: RoundingMode) -> (Integer, Ordering)

Converts a Rational to an Integer, using a specified RoundingMode and taking the Rational by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original value.

§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 x.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Integer::rounding_from(Rational::from(123), RoundingMode::Exact).to_debug_string(),
    "(123, Equal)"
);
assert_eq!(
    Integer::rounding_from(Rational::from(-123), RoundingMode::Exact).to_debug_string(),
    "(-123, Equal)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(-3, Greater)"
);
source§

impl RoundingFrom<Rational> for Natural

source§

fn rounding_from(x: Rational, rm: RoundingMode) -> (Natural, Ordering)

Converts a Rational to a Natural, using a specified RoundingMode and taking the Rational 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 Rational is negative, then it will be rounded to zero when the RoundingMode is Ceiling, Down, or Nearest. Otherwise, this function will panic.

§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 x.significant_bits().

§Panics

Panics if the Rational is not an integer and rm is Exact, or if the Rational is less than zero and rm is not Down, Ceiling, or Nearest.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use malachite_q::Rational;

assert_eq!(
    Natural::rounding_from(Rational::from(123), RoundingMode::Exact).to_debug_string(),
    "(123, Equal)"
);

assert_eq!(
    Natural::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Floor)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Natural::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Down)
        .to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Natural::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Ceiling)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Natural::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Up)
        .to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Natural::rounding_from(Rational::from_signeds(22, 7), RoundingMode::Nearest)
        .to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Natural::rounding_from(Rational::from(-123), RoundingMode::Down).to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(Rational::from(-123), RoundingMode::Ceiling).to_debug_string(),
    "(0, Greater)"
);
assert_eq!(
    Natural::rounding_from(Rational::from(-123), RoundingMode::Nearest).to_debug_string(),
    "(0, Greater)"
);
source§

impl RoundingFrom<Rational> for f32

source§

fn rounding_from(value: Rational, rm: RoundingMode) -> (f32, Ordering)

Converts a Rational to a value of a primitive float according to a specified RoundingMode, taking the Rational by value.

  • If the rounding mode is Floor, the largest float less than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If it is smaller than the minimum finite float, then negative infinity is returned. If it is between zero and the minimum positive float, then positive zero is returned.
  • If the rounding mode is Ceiling, the smallest float greater than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then positive infinity is returned. If it is smaller than the minimum finite float, then the minimum finite float is returned. If it is between zero and the maximum negative float, then negative zero is returned.
  • If the rounding mode is Down, then the rounding proceeds as with Floor if the Rational is non-negative and as with Ceiling if the Rational is negative. If the Rational is between the maximum negative float and the minimum positive float, then positive zero is returned when the Rational is non-negative and negative zero otherwise.
  • If the rounding mode is Up, then the rounding proceeds as with Ceiling if the Rational is non-negative and as with Floor if the Rational is negative. Positive zero is only returned when the Rational is zero, and negative zero is never returned.
  • If the rounding mode is Nearest, then the nearest float is returned. If the Rational is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If the Rational is closer to zero than to any float (or if there is a tie between zero and another float), then positive or negative zero is returned, depending on the Rational’s sign.
§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 value.significant_bits().

§Panics

Panics if the rounding mode is Exact and value cannot be represented exactly.

§Examples

See here.

source§

impl RoundingFrom<Rational> for f64

source§

fn rounding_from(value: Rational, rm: RoundingMode) -> (f64, Ordering)

Converts a Rational to a value of a primitive float according to a specified RoundingMode, taking the Rational by value.

  • If the rounding mode is Floor, the largest float less than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If it is smaller than the minimum finite float, then negative infinity is returned. If it is between zero and the minimum positive float, then positive zero is returned.
  • If the rounding mode is Ceiling, the smallest float greater than or equal to the Rational is returned. If the Rational is greater than the maximum finite float, then positive infinity is returned. If it is smaller than the minimum finite float, then the minimum finite float is returned. If it is between zero and the maximum negative float, then negative zero is returned.
  • If the rounding mode is Down, then the rounding proceeds as with Floor if the Rational is non-negative and as with Ceiling if the Rational is negative. If the Rational is between the maximum negative float and the minimum positive float, then positive zero is returned when the Rational is non-negative and negative zero otherwise.
  • If the rounding mode is Up, then the rounding proceeds as with Ceiling if the Rational is non-negative and as with Floor if the Rational is negative. Positive zero is only returned when the Rational is zero, and negative zero is never returned.
  • If the rounding mode is Nearest, then the nearest float is returned. If the Rational is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If the Rational is greater than the maximum finite float, then the maximum finite float is returned. If the Rational is closer to zero than to any float (or if there is a tie between zero and another float), then positive or negative zero is returned, depending on the Rational’s sign.
§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 value.significant_bits().

§Panics

Panics if the rounding mode is Exact and value cannot be represented exactly.

§Examples

See here.

source§

impl SciMantissaAndExponent<f32, i64> for Rational

source§

fn sci_mantissa_and_exponent(self) -> (f32, i64)

Returns a Rational’s scientific mantissa and exponent, taking the Rational by 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 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 \log n \log\log n)$

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

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

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns a Rational’s scientific exponent, taking the Rational by 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 Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx \lfloor \log_2 x \rfloor. $$

§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 self.significant_bits().

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: i64 ) -> Option<Rational>

Constructs a Rational from its scientific mantissa and exponent.

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$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

All finite floats can be represented using Rationals, so no rounding is needed.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl<'a> SciMantissaAndExponent<f32, i64, Rational> for &'a Rational

source§

fn sci_mantissa_and_exponent(self) -> (f32, i64)

Returns a Rational’s scientific mantissa and exponent, taking the Rational by reference.

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 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 \log n \log\log n)$

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

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

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns a Rational’s scientific exponent, taking the Rational by reference.

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 Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx \lfloor \log_2 x \rfloor. $$

§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 self.significant_bits().

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: i64 ) -> Option<Rational>

Constructs a Rational from its scientific mantissa and exponent.

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$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

All finite floats can be represented using Rationals, so no rounding is needed.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

See here.

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl SciMantissaAndExponent<f64, i64> for Rational

source§

fn sci_mantissa_and_exponent(self) -> (f64, i64)

Returns a Rational’s scientific mantissa and exponent, taking the Rational by 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 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 \log n \log\log n)$

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

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

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns a Rational’s scientific exponent, taking the Rational by 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 Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx \lfloor \log_2 x \rfloor. $$

§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 self.significant_bits().

§Examples

See here.

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: i64 ) -> Option<Rational>

Constructs a Rational from its scientific mantissa and exponent.

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$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

All finite floats can be represented using Rationals, so no rounding is needed.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl<'a> SciMantissaAndExponent<f64, i64, Rational> for &'a Rational

source§

fn sci_mantissa_and_exponent(self) -> (f64, i64)

Returns a Rational’s scientific mantissa and exponent, taking the Rational by reference.

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 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 \log n \log\log n)$

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

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

§Examples

See here.

source§

fn sci_exponent(self) -> i64

Returns a Rational’s scientific exponent, taking the Rational by reference.

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 Nearest rounding mode. To use other rounding modes, use sci_mantissa_and_exponent_round. $$ f(x) \approx \lfloor \log_2 x \rfloor. $$

§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 self.significant_bits().

source§

fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: i64 ) -> Option<Rational>

Constructs a Rational from its scientific mantissa and exponent.

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$. Here, the rational mantissa is provided as a float. If the mantissa is outside the range $[1, 2)$, None is returned.

All finite floats can be represented using Rationals, so no rounding is needed.

$$ f(x) \approx 2^{e_s}m_s. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

See here.

source§

fn sci_mantissa(self) -> M

Extracts the scientific mantissa from a number.
source§

impl<'a> Shl<i128> for &'a Rational

source§

fn shl(self, bits: i128) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<i128> for Rational

source§

fn shl(self, bits: i128) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<i16> for &'a Rational

source§

fn shl(self, bits: i16) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<i16> for Rational

source§

fn shl(self, bits: i16) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<i32> for &'a Rational

source§

fn shl(self, bits: i32) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<i32> for Rational

source§

fn shl(self, bits: i32) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<i64> for &'a Rational

source§

fn shl(self, bits: i64) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<i64> for Rational

source§

fn shl(self, bits: i64) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<i8> for &'a Rational

source§

fn shl(self, bits: i8) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<i8> for Rational

source§

fn shl(self, bits: i8) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<isize> for &'a Rational

source§

fn shl(self, bits: isize) -> Rational

Left-shifts a Rational (multiplies or divides it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<isize> for Rational

source§

fn shl(self, bits: isize) -> Rational

Left-shifts a Rational (multiplies it or divides it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<u128> for &'a Rational

source§

fn shl(self, bits: u128) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<u128> for Rational

source§

fn shl(self, bits: u128) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<u16> for &'a Rational

source§

fn shl(self, bits: u16) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<u16> for Rational

source§

fn shl(self, bits: u16) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<u32> for &'a Rational

source§

fn shl(self, bits: u32) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<u32> for Rational

source§

fn shl(self, bits: u32) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<u64> for &'a Rational

source§

fn shl(self, bits: u64) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<u64> for Rational

source§

fn shl(self, bits: u64) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<u8> for &'a Rational

source§

fn shl(self, bits: u8) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<u8> for Rational

source§

fn shl(self, bits: u8) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl<'a> Shl<usize> for &'a Rational

source§

fn shl(self, bits: usize) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl Shl<usize> for Rational

source§

fn shl(self, bits: usize) -> Rational

Left-shifts a Rational (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

§

type Output = Rational

The resulting type after applying the << operator.
source§

impl ShlAssign<i128> for Rational

source§

fn shl_assign(&mut self, bits: i128)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<i16> for Rational

source§

fn shl_assign(&mut self, bits: i16)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<i32> for Rational

source§

fn shl_assign(&mut self, bits: i32)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<i64> for Rational

source§

fn shl_assign(&mut self, bits: i64)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<i8> for Rational

source§

fn shl_assign(&mut self, bits: i8)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<isize> for Rational

source§

fn shl_assign(&mut self, bits: isize)

Left-shifts a Rational (multiplies or divides it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShlAssign<u128> for Rational

source§

fn shl_assign(&mut self, bits: u128)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl ShlAssign<u16> for Rational

source§

fn shl_assign(&mut self, bits: u16)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl ShlAssign<u32> for Rational

source§

fn shl_assign(&mut self, bits: u32)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl ShlAssign<u64> for Rational

source§

fn shl_assign(&mut self, bits: u64)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl ShlAssign<u8> for Rational

source§

fn shl_assign(&mut self, bits: u8)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl ShlAssign<usize> for Rational

source§

fn shl_assign(&mut self, bits: usize)

Left-shifts a Rational (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

§Examples

See here.

source§

impl<'a> Shr<i128> for &'a Rational

source§

fn shr(self, bits: i128) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<i128> for Rational

source§

fn shr(self, bits: i128) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<i16> for &'a Rational

source§

fn shr(self, bits: i16) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<i16> for Rational

source§

fn shr(self, bits: i16) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<i32> for &'a Rational

source§

fn shr(self, bits: i32) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<i32> for Rational

source§

fn shr(self, bits: i32) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<i64> for &'a Rational

source§

fn shr(self, bits: i64) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<i64> for Rational

source§

fn shr(self, bits: i64) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<i8> for &'a Rational

source§

fn shr(self, bits: i8) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<i8> for Rational

source§

fn shr(self, bits: i8) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<isize> for &'a Rational

source§

fn shr(self, bits: isize) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<isize> for Rational

source§

fn shr(self, bits: isize) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<u128> for &'a Rational

source§

fn shr(self, bits: u128) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<u128> for Rational

source§

fn shr(self, bits: u128) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<u16> for &'a Rational

source§

fn shr(self, bits: u16) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<u16> for Rational

source§

fn shr(self, bits: u16) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<u32> for &'a Rational

source§

fn shr(self, bits: u32) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<u32> for Rational

source§

fn shr(self, bits: u32) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<u64> for &'a Rational

source§

fn shr(self, bits: u64) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<u64> for Rational

source§

fn shr(self, bits: u64) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<u8> for &'a Rational

source§

fn shr(self, bits: u8) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<u8> for Rational

source§

fn shr(self, bits: u8) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl<'a> Shr<usize> for &'a Rational

source§

fn shr(self, bits: usize) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl Shr<usize> for Rational

source§

fn shr(self, bits: usize) -> Rational

Right-shifts a Rational (divides it by a power of 2), taking it by value.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

§

type Output = Rational

The resulting type after applying the >> operator.
source§

impl ShrAssign<i128> for Rational

source§

fn shr_assign(&mut self, bits: i128)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<i16> for Rational

source§

fn shr_assign(&mut self, bits: i16)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<i32> for Rational

source§

fn shr_assign(&mut self, bits: i32)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<i64> for Rational

source§

fn shr_assign(&mut self, bits: i64)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<i8> for Rational

source§

fn shr_assign(&mut self, bits: i8)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<isize> for Rational

source§

fn shr_assign(&mut self, bits: isize)

Right-shifts a Rational (divides it by a power of 2), in reference.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<u128> for Rational

source§

fn shr_assign(&mut self, bits: u128)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<u16> for Rational

source§

fn shr_assign(&mut self, bits: u16)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<u32> for Rational

source§

fn shr_assign(&mut self, bits: u32)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<u64> for Rational

source§

fn shr_assign(&mut self, bits: u64)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<u8> for Rational

source§

fn shr_assign(&mut self, bits: u8)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl ShrAssign<usize> for Rational

source§

fn shr_assign(&mut self, bits: usize)

Right-shifts a Rational (divides it by a power of 2), in place.

$$ f(x, k) = \frac{x}{2^k}. $$

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(n, m) = O(n + m)$

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

See here.

source§

impl Sign for Rational

source§

fn sign(&self) -> Ordering

Compares a Rational to zero.

Returns Greater, Equal, or Less, depending on whether the Rational is positive, zero, or negative, respectively.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::Sign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;
use std::cmp::Ordering;

assert_eq!(Rational::ZERO.sign(), Ordering::Equal);
assert_eq!(Rational::from_signeds(22, 7).sign(), Ordering::Greater);
assert_eq!(Rational::from_signeds(-22, 7).sign(), Ordering::Less);
source§

impl<'a> SignificantBits for &'a Rational

source§

fn significant_bits(self) -> u64

Returns the sum of the bits needed to represent the numerator and denominator.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;
use std::str::FromStr;

assert_eq!(Rational::ZERO.significant_bits(), 1);
assert_eq!(Rational::from_str("-100/101").unwrap().significant_bits(), 14);
source§

impl SimplestRationalInInterval for Rational

source§

fn simplest_rational_in_open_interval(x: &Rational, y: &Rational) -> Rational

Finds the simplest Rational contained in an open interval.

Let $f(x, y) = p/q$, with $p$ and $q$ relatively prime. Then the following properties hold:

  • $x < p/q < y$
  • If $x < m/n < y$, then $n \geq q$
  • If $x < m/q < y$, then $|p| \leq |m|$
§Worst-case complexity

$T(n) = O(n^2 \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(), y.significant_bits()).

§Panics

Panics if $x \geq y$.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::arithmetic::traits::SimplestRationalInInterval;
use malachite_q::Rational;

assert_eq!(
    Rational::simplest_rational_in_open_interval(
        &Rational::from_signeds(1, 3),
        &Rational::from_signeds(1, 2)
    ),
    Rational::from_signeds(2, 5)
);
assert_eq!(
    Rational::simplest_rational_in_open_interval(
        &Rational::from_signeds(-1, 3),
        &Rational::from_signeds(1, 3)
    ),
    Rational::ZERO
);
assert_eq!(
    Rational::simplest_rational_in_open_interval(
        &Rational::from_signeds(314, 100),
        &Rational::from_signeds(315, 100)
    ),
    Rational::from_signeds(22, 7)
);
source§

fn simplest_rational_in_closed_interval(x: &Rational, y: &Rational) -> Rational

Finds the simplest Rational contained in a closed interval.

Let $f(x, y) = p/q$, with $p$ and $q$ relatively prime. Then the following properties hold:

  • $x \leq p/q \leq y$
  • If $x \leq m/n \leq y$, then $n \geq q$
  • If $x \leq m/q \leq y$, then $|p| \leq |m|$
§Worst-case complexity

$T(n) = O(n^2 \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(), y.significant_bits()).

§Panics

Panics if $x > y$.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_q::arithmetic::traits::SimplestRationalInInterval;
use malachite_q::Rational;

assert_eq!(
    Rational::simplest_rational_in_closed_interval(
        &Rational::from_signeds(1, 3),
        &Rational::from_signeds(1, 2)
    ),
    Rational::from_signeds(1, 2)
);
assert_eq!(
    Rational::simplest_rational_in_closed_interval(
        &Rational::from_signeds(-1, 3),
        &Rational::from_signeds(1, 3)
    ),
    Rational::ZERO
);
assert_eq!(
    Rational::simplest_rational_in_closed_interval(
        &Rational::from_signeds(314, 100),
        &Rational::from_signeds(315, 100)
    ),
    Rational::from_signeds(22, 7)
);
source§

impl<'a> Square for &'a Rational

source§

fn square(self) -> Rational

Squares a Rational, taking it by reference.

$$ f(x) = x^2. $$

§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 self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!((&Rational::ZERO).square(), 0);
assert_eq!((&Rational::from_signeds(22, 7)).square().to_string(), "484/49");
assert_eq!((&Rational::from_signeds(-22, 7)).square().to_string(), "484/49");
§

type Output = Rational

source§

impl Square for Rational

source§

fn square(self) -> Rational

Squares a Rational, taking it by value.

$$ f(x) = x^2. $$

§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 self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

assert_eq!(Rational::ZERO.square(), 0);
assert_eq!(Rational::from_signeds(22, 7).square().to_string(), "484/49");
assert_eq!(Rational::from_signeds(-22, 7).square().to_string(), "484/49");
§

type Output = Rational

source§

impl SquareAssign for Rational

source§

fn square_assign(&mut self)

Squares a Rational in place.

$$ x \gets x^2. $$

§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 self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::SquareAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_q::Rational;

let mut x = Rational::ZERO;
x.square_assign();
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x.square_assign();
assert_eq!(x.to_string(), "484/49");

let mut x = Rational::from_signeds(-22, 7);
x.square_assign();
assert_eq!(x.to_string(), "484/49");
source§

impl<'a, 'b> Sub<&'a Rational> for &'b Rational

source§

fn sub(self, other: &'a Rational) -> Rational

Subtracts a Rational by another Rational, taking both by reference.

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

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF - &Rational::ONE_HALF, 0);
assert_eq!(
    (&Rational::from_signeds(22, 7) - &Rational::from_signeds(99, 100)).to_string(),
    "1507/700"
);
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl<'a> Sub<&'a Rational> for Rational

source§

fn sub(self, other: &'a Rational) -> Rational

Subtracts a Rational by another Rational, taking the first by value and the second by reference.

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

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF - &Rational::ONE_HALF, 0);
assert_eq!(
    (Rational::from_signeds(22, 7) - &Rational::from_signeds(99, 100)).to_string(),
    "1507/700"
);
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl<'a> Sub<Rational> for &'a Rational

source§

fn sub(self, other: Rational) -> Rational

Subtracts a Rational by another Rational, taking the first by reference and the second by value.

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

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(&Rational::ONE_HALF - Rational::ONE_HALF, 0);
assert_eq!(
    (&Rational::from_signeds(22, 7) - Rational::from_signeds(99, 100)).to_string(),
    "1507/700"
);
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl Sub for Rational

source§

fn sub(self, other: Rational) -> Rational

Subtracts a Rational by another Rational, taking both by value.

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

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

assert_eq!(Rational::ONE_HALF - Rational::ONE_HALF, 0);
assert_eq!(
    (Rational::from_signeds(22, 7) - Rational::from_signeds(99, 100)).to_string(),
    "1507/700"
);
§

type Output = Rational

The resulting type after applying the - operator.
source§

impl<'a> SubAssign<&'a Rational> for Rational

source§

fn sub_assign(&mut self, other: &'a Rational)

Subtracts a Rational by another Rational in place, taking the Rational on the right-hand side by reference.

$$ x \gets x - y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x -= &Rational::ONE_HALF;
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x -= &Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "1507/700");
source§

impl SubAssign for Rational

source§

fn sub_assign(&mut self, other: Rational)

Subtracts a Rational by another Rational in place, taking the Rational on the right-hand side by value.

$$ x \gets x - y. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \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::OneHalf;
use malachite_q::Rational;

let mut x = Rational::ONE_HALF;
x -= Rational::ONE_HALF;
assert_eq!(x, 0);

let mut x = Rational::from_signeds(22, 7);
x -= Rational::from_signeds(99, 100);
assert_eq!(x.to_string(), "1507/700");
source§

impl<'a> Sum<&'a Rational> for Rational

source§

fn sum<I>(xs: I) -> Rational
where I: Iterator<Item = &'a Rational>,

Adds up all the Rationals in an iterator of Rational references.

$$ f((x_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} x_i. $$

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, and $n$ is Rational::sum(xs.map(Rational::significant_bits)).

§Examples
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;
use std::iter::Sum;

assert_eq!(
    Rational::sum(
        vec_from_str::<Rational>("[0, 1, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10]")
                .unwrap().iter()
    ).to_string(),
    "19079/2520"
);
source§

impl Sum for Rational

source§

fn sum<I>(xs: I) -> Rational
where I: Iterator<Item = Rational>,

Adds up all the Rationals in an iterator.

$$ f((x_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} x_i. $$

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, and $n$ is Rational::sum(xs.map(Rational::significant_bits)).

§Examples
use malachite_base::vecs::vec_from_str;
use malachite_q::Rational;
use std::iter::Sum;

assert_eq!(
    Rational::sum(vec_from_str::<Rational>("[2, -3, 5, 7]").unwrap().into_iter()),
    11
);
source§

impl ToSci for Rational

source§

fn fmt_sci_valid(&self, options: ToSciOptions) -> bool

Determines whether a Rational can be converted to a string using to_sci and a particular set of options.

§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(), s), where s depends on the size type specified in options.

  • If options has scale specified, then s is options.scale.
  • If options has precision specified, then s is options.precision.
  • If options has size_complete specified, then s is self.denominator (not the log of the denominator!). This reflects the fact that setting size_complete might result in a very long string.
§Examples
use malachite_base::num::conversion::string::options::ToSciOptions;
use malachite_base::num::conversion::traits::ToSci;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;

let mut options = ToSciOptions::default();
assert!(Rational::from(123u8).fmt_sci_valid(options));
assert!(Rational::from(u128::MAX).fmt_sci_valid(options));
// u128::MAX has more than 16 significant digits
options.set_rounding_mode(RoundingMode::Exact);
assert!(!Rational::from(u128::MAX).fmt_sci_valid(options));
options.set_precision(50);
assert!(Rational::from(u128::MAX).fmt_sci_valid(options));

let mut options = ToSciOptions::default();
options.set_size_complete();
// 1/3 is non-terminating in base 10...
assert!(!Rational::from_signeds(1, 3).fmt_sci_valid(options));
options.set_size_complete();

// ...but is terminating in base 36
options.set_base(36);
assert!(Rational::from_signeds(1, 3).fmt_sci_valid(options));
source§

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

Converts a Rational to a string using a specified base, possibly formatting the number using scientific notation.

See ToSciOptions for details on the available options.

§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(), s), where s depends on the size type specified in options.

  • If options has scale specified, then s is options.scale.
  • If options has precision specified, then s is options.precision.
  • If options has size_complete specified, then s is self.denominator (not the log of the denominator!). This reflects the fact that setting size_complete might result in a very long string.
§Panics

Panics if options.rounding_mode is Exact, but the size options are such that the input must be rounded.

§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::conversion::string::options::ToSciOptions;
use malachite_base::num::conversion::traits::ToSci;
use malachite_base::rounding_modes::RoundingMode;
use malachite_q::Rational;

let q = Rational::from_signeds(22, 7);
let mut options = ToSciOptions::default();
assert_eq!(q.to_sci_with_options(options).to_string(), "3.142857142857143");

options.set_precision(3);
assert_eq!(q.to_sci_with_options(options).to_string(), "3.14");

options.set_rounding_mode(RoundingMode::Ceiling);
assert_eq!(q.to_sci_with_options(options).to_string(), "3.15");

options = ToSciOptions::default();
options.set_base(20);
assert_eq!(q.to_sci_with_options(options).to_string(), "3.2h2h2h2h2h2h2h3");

options.set_uppercase();
assert_eq!(q.to_sci_with_options(options).to_string(), "3.2H2H2H2H2H2H2H3");

options.set_base(2);
options.set_rounding_mode(RoundingMode::Floor);
options.set_precision(19);
assert_eq!(q.to_sci_with_options(options).to_string(), "11.001001001001001");

options.set_include_trailing_zeros(true);
assert_eq!(q.to_sci_with_options(options).to_string(), "11.00100100100100100");

let q = Rational::from_unsigneds(936851431250u64, 1397u64);
let mut options = ToSciOptions::default();
options.set_precision(6);
assert_eq!(q.to_sci_with_options(options).to_string(), "6.70617e8");

options.set_e_uppercase();
assert_eq!(q.to_sci_with_options(options).to_string(), "6.70617E8");

options.set_force_exponent_plus_sign(true);
assert_eq!(q.to_sci_with_options(options).to_string(), "6.70617E+8");

let q = Rational::from_signeds(123i64, 45678909876i64);
let mut options = ToSciOptions::default();
assert_eq!(q.to_sci_with_options(options).to_string(), "2.692708743135418e-9");

options.set_neg_exp_threshold(-10);
assert_eq!(q.to_sci_with_options(options).to_string(), "0.000000002692708743135418");

let q = Rational::power_of_2(-30i64);
let mut options = ToSciOptions::default();
assert_eq!(q.to_sci_with_options(options).to_string(), "9.313225746154785e-10");

options.set_size_complete();
assert_eq!(q.to_sci_with_options(options).to_string(), "9.31322574615478515625e-10");
source§

fn to_sci_with_options(&self, options: ToSciOptions) -> SciWrapper<'_, Self>

Converts a number to a string, possibly in scientific notation.
source§

fn to_sci(&self) -> SciWrapper<'_, Self>

Converts a number to a string, possibly in scientific notation, using the default ToSciOptions.
source§

impl<'a> TryFrom<&'a Rational> for Integer

source§

fn try_from(x: &Rational) -> Result<Integer, Self::Error>

Converts a Rational to an Integer, taking the Rational by reference. If the Rational is not 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 x.significant_bits().

§Examples
use malachite_nz::integer::Integer;
use malachite_q::conversion::integer_from_rational::IntegerFromRationalError;
use malachite_q::Rational;

assert_eq!(Integer::try_from(&Rational::from(123)).unwrap(), 123);
assert_eq!(Integer::try_from(&Rational::from(-123)).unwrap(), -123);
assert_eq!(
    Integer::try_from(&Rational::from_signeds(22, 7)),
    Err(IntegerFromRationalError)
);
§

type Error = IntegerFromRationalError

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

impl<'a> TryFrom<&'a Rational> for Natural

source§

fn try_from(x: &Rational) -> Result<Natural, Self::Error>

Converts a Rational to a Natural, taking the Rational by reference. If the Rational is negative or not 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 x.significant_bits().

§Examples
use malachite_nz::natural::Natural;
use malachite_q::conversion::natural_from_rational::NaturalFromRationalError;
use malachite_q::Rational;

assert_eq!(Natural::try_from(&Rational::from(123)).unwrap(), 123);
assert_eq!(Natural::try_from(&Rational::from(-123)), Err(NaturalFromRationalError));
assert_eq!(
    Natural::try_from(&Rational::from_signeds(22, 7)),
    Err(NaturalFromRationalError)
);
§

type Error = NaturalFromRationalError

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

impl<'a> TryFrom<&'a Rational> for f32

source§

fn try_from(value: &'a Rational) -> Result<f32, Self::Error>

Converts a Rational to a primitive float, taking the Rational by reference. If the input isn’t exactly equal to any float, 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 value.significant_bits().

§Examples

See here.

§

type Error = FloatFromRationalError

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

impl<'a> TryFrom<&'a Rational> for f64

source§

fn try_from(value: &'a Rational) -> Result<f64, Self::Error>

Converts a Rational to a primitive float, taking the Rational by reference. If the input isn’t exactly equal to any float, 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 value.significant_bits().

§Examples

See here.

§

type Error = FloatFromRationalError

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

impl<'a> TryFrom<&'a Rational> for i128

source§

fn try_from(value: &Rational) -> Result<i128, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for i16

source§

fn try_from(value: &Rational) -> Result<i16, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for i32

source§

fn try_from(value: &Rational) -> Result<i32, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for i64

source§

fn try_from(value: &Rational) -> Result<i64, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for i8

source§

fn try_from(value: &Rational) -> Result<i8, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for isize

source§

fn try_from(value: &Rational) -> Result<isize, SignedFromRationalError>

Converts a Rational to a signed primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = SignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for u128

source§

fn try_from(value: &Rational) -> Result<u128, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for u16

source§

fn try_from(value: &Rational) -> Result<u16, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for u32

source§

fn try_from(value: &Rational) -> Result<u32, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for u64

source§

fn try_from(value: &Rational) -> Result<u64, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for u8

source§

fn try_from(value: &Rational) -> Result<u8, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl<'a> TryFrom<&'a Rational> for usize

source§

fn try_from(value: &Rational) -> Result<usize, UnsignedFromRationalError>

Converts a Rational to an unsigned primitive integer, returning an error if the Rational cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromRationalError

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

impl TryFrom<Rational> for Integer

source§

fn try_from(x: Rational) -> Result<Integer, Self::Error>

Converts a Rational to an Integer, taking the Rational by value. If the Rational is not an integer, an error is returned.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;
use malachite_q::conversion::integer_from_rational::IntegerFromRationalError;
use malachite_q::Rational;

assert_eq!(Integer::try_from(Rational::from(123)).unwrap(), 123);
assert_eq!(Integer::try_from(Rational::from(-123)).unwrap(), -123);
assert_eq!(
    Integer::try_from(Rational::from_signeds(22, 7)),
    Err(IntegerFromRationalError)
);
§

type Error = IntegerFromRationalError

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

impl TryFrom<Rational> for Natural

source§

fn try_from(x: Rational) -> Result<Natural, Self::Error>

Converts a Rational to a Natural, taking the Rational by value. If the Rational is negative or not an integer, an error is returned.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::natural::Natural;
use malachite_q::conversion::natural_from_rational::NaturalFromRationalError;
use malachite_q::Rational;

assert_eq!(Natural::try_from(Rational::from(123)).unwrap(), 123);
assert_eq!(Natural::try_from(Rational::from(-123)), Err(NaturalFromRationalError));
assert_eq!(
    Natural::try_from(Rational::from_signeds(22, 7)),
    Err(NaturalFromRationalError)
);
§

type Error = NaturalFromRationalError

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

impl TryFrom<Rational> for f32

source§

fn try_from(value: Rational) -> Result<f32, Self::Error>

Converts a Rational to a primitive float, taking the Rational by value. If the input isn’t exactly equal to any float, an error is returned.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

§

type Error = FloatFromRationalError

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

impl TryFrom<Rational> for f64

source§

fn try_from(value: Rational) -> Result<f64, Self::Error>

Converts a Rational to a primitive float, taking the Rational by value. If the input isn’t exactly equal to any float, an error is returned.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

§

type Error = FloatFromRationalError

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

impl TryFrom<f32> for Rational

source§

fn try_from(value: f32) -> Result<Rational, Self::Error>

Converts a primitive float to the equivalent Rational. If the floating point value is NaN or infinite, and error is returned.

This conversion is literal. For example, Rational::try_from(0.1f32) evaluates to Some($13421773/134217728$). If you want $1/10$ instead, use try_from_float_simplest; that function returns the simplest Rational that rounds to the specified float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

§

type Error = RationalFromPrimitiveFloatError

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

impl TryFrom<f64> for Rational

source§

fn try_from(value: f64) -> Result<Rational, Self::Error>

Converts a primitive float to the equivalent Rational. If the floating point value is NaN or infinite, and error is returned.

This conversion is literal. For example, Rational::try_from(0.1f32) evaluates to Some($13421773/134217728$). If you want $1/10$ instead, use try_from_float_simplest; that function returns the simplest Rational that rounds to the specified float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples

See here.

§

type Error = RationalFromPrimitiveFloatError

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

impl Two for Rational

The constant 2.

source§

impl Zero for Rational

The constant 0.

source§

impl Eq for Rational

source§

impl StructuralPartialEq for Rational

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

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

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

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

source§

fn exact_from(value: T) -> U

source§

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

source§

fn exact_into(self) -> U

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

source§

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

source§

impl<T> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

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

source§

fn wrapping_into(self) -> U