Skip to main content

ComparableFloatRef

Struct ComparableFloatRef 

Source
pub struct ComparableFloatRef<'a>(pub &'a Float);
Expand description

ComparableFloatRef is a wrapper around a Float, taking the Float be reference.

See the ComparableFloat documentation for details.

Tuple Fields§

§0: &'a Float

Methods from Deref<Target = Float>§

Source

pub fn abs_negative_zero_ref(&self) -> Self

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

This function does not overflow or underflow.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

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

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

pub fn acos_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arccos x$, the arccosine of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_prec_round for the error bounds, the special cases, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(0.5)).acos_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "1.0469");
assert_eq!(o, Less);

let (c, o) = (&Float::from(0.5)).acos_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "1.0488");
assert_eq!(o, Greater);
Source

pub fn acos_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arccos x$, the arccosine of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_prec and Float::acos_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(0.5)).acos_prec_ref(10);
assert_eq!(c.to_string(), "1.0469");
assert_eq!(o, Less);

let (c, o) = (&Float::from(0.5)).acos_prec_ref(53);
assert_eq!(c.to_string(), "1.0471975511965979");
assert_eq!(o, Greater);
Source

pub fn acos_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arccos x$, the arccosine of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_round and Float::acos_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(1u32, 100).0 >> 1u32;
let (c, o) = (&x).acos_round_ref(Floor);
assert_eq!(c.to_string(), "1.0471975511965977461542144610921");
assert_eq!(o, Less);
Source

pub fn acos_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arccos(x)u/(2\pi)$, the arccosine of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_with_period_prec_round for the error bounds, the special and closed-form cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::NegativeOne;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// an input of -1 is a half turn
let (c, o) = (&Float::NEGATIVE_ONE).acos_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(c.to_string(), "180.00");
assert_eq!(o, Equal);

let (c, o) = (&Float::from(0.25)).acos_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(c.to_string(), "75.500");
assert_eq!(o, Less);
Source

pub fn acos_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\arccos(x)u/(2\pi)$, the arccosine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_with_period_prec and Float::acos_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(0.25)).acos_with_period_prec_ref(360, 10);
assert_eq!(c.to_string(), "75.500");
assert_eq!(o, Less);
Source

pub fn acos_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arccos(x)u/(2\pi)$, the arccosine of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acos_with_period_round and Float::acos_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
let (c, o) = (&x).acos_with_period_round_ref(360, Floor);
assert_eq!(c.to_string(), "75.500");
assert_eq!(o, Less);
Source

pub fn acos_with_period_ref(&self, u: u64) -> Self

Computes $\arccos(x)u/(2\pi)$, the arccosine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the input’s precision. The Float is taken by reference.

See Float::acos_with_period and Float::acos_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
assert_eq!((&x).acos_with_period_ref(360).to_string(), "75.500");
Source

pub fn acos_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arccos(x)/\pi$, the arccosine of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acos_with_period with a period of 2: see Float::acos_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. A zero input gives $1/2$, an input of 1 gives $0.0$, and an input of $-1$ gives $1$; all three are exact at every precision, since a half and a one need only one bit, and they are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $0 \leq \arccos(x)/\pi \leq 1$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(0.25)).acos_pi_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "0.41943");
assert_eq!(o, Less);
Source

pub fn acos_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arccos(x)/\pi$, the arccosine of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acos_with_period with a period of 2: see Float::acos_with_period_prec_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. A zero input gives $1/2$, an input of 1 gives $0.0$, and an input of $-1$ gives $1$; all three are exact at every precision, since a half and a one need only one bit, and they are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $0 \leq \arccos(x)/\pi \leq 1$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(0.25)).acos_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.41956937674483374");
assert_eq!(o, Less);
Source

pub fn acos_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arccos(x)/\pi$, the arccosine of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosine is less than, equal to, or greater than the exact arccosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acos_with_period with a period of 2: see Float::acos_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. A zero input gives $1/2$, an input of 1 gives $0.0$, and an input of $-1$ gives $1$; all three are exact at every precision, since a half and a one need only one bit, and they are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $0 \leq \arccos(x)/\pi \leq 1$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
let (c, o) = (&x).acos_pi_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.41992");
assert_eq!(o, Greater);
Source

pub fn acos_pi_ref(&self) -> Self

Computes $\arccos(x)/\pi$, the arccosine of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::acos_pi and Float::acos_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
assert_eq!((&x).acos_pi_ref().to_string(), "0.41943");
Source

pub fn acot_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acot} x$, the arccotangent of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_prec_round for the error bounds, the special cases, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{NegativeOne, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).acot_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "0.46338");
assert_eq!(o, Less);

let (c, o) = (&Float::NEGATIVE_ONE).acot_prec_round_ref(10, Nearest);
assert_eq!(c.to_string(), "-0.78516");
assert_eq!(o, Greater);
Source

pub fn acot_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acot} x$, the arccotangent of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_prec and Float::acot_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).acot_prec_ref(10);
assert_eq!(c.to_string(), "0.46387");
assert_eq!(o, Greater);
Source

pub fn acot_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{acot} x$, the arccotangent of a Float, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_round and Float::acot_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(2u32, 100).0;
let (c, o) = (&x).acot_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.46364760900080611621425623146131");
assert_eq!(o, Greater);
Source

pub fn acot_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acot}(x)u/(2\pi)$, the arccotangent of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_with_period_prec_round for the error bounds, the special and closed-form cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(2.5)).acot_with_period_prec_round_ref(360, 10, Ceiling);
assert_eq!(c.to_string(), "21.812");
assert_eq!(o, Greater);
Source

pub fn acot_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acot}(x)u/(2\pi)$, the arccotangent of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_with_period_prec and Float::acot_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(2.5)).acot_with_period_prec_ref(360, 53);
assert_eq!(c.to_string(), "21.801409486351812");
assert_eq!(o, Less);
Source

pub fn acot_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acot}(x)u/(2\pi)$, the arccotangent of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_with_period_round and Float::acot_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
let (c, o) = (&x).acot_with_period_round_ref(360, Ceiling);
assert_eq!(c.to_string(), "21.801409486351811770244866086963");
assert_eq!(o, Greater);
Source

pub fn acot_with_period_ref(&self, u: u64) -> Self

Computes $\operatorname{acot}(x)u/(2\pi)$, the arccotangent of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::acot_with_period and Float::acot_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
assert_eq!(
    (&x).acot_with_period_ref(360).to_string(),
    "21.801409486351811770244866086938"
);
Source

pub fn acot_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acot}(x)/\pi$, the arccotangent of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acot_with_period with a period of 2: see Float::acot_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, $\pm0.0$ give $\pm1/2$, and $\pm1$ give $\pm1/4$; all are exact at every precision, and they are the only exact cases. NaN gives NaN. Overflow is not possible, since $|\operatorname{acot}(x)/\pi| \leq 1/2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(2.5)).acot_pi_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "0.12122");
assert_eq!(o, Greater);
Source

pub fn acot_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acot}(x)/\pi$, the arccotangent of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acot_pi_prec and Float::acot_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(2.5)).acot_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.12111894159084340");
assert_eq!(o, Less);
Source

pub fn acot_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{acot}(x)/\pi$, the arccotangent of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccotangent is less than, equal to, or greater than the exact arccotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acot_with_period with a period of 2: see Float::acot_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, $\pm0.0$ give $\pm1/2$, and $\pm1$ give $\pm1/4$; all are exact at every precision, and they are the only exact cases. NaN gives NaN. Overflow is not possible, since $|\operatorname{acot}(x)/\pi| \leq 1/2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
let (c, o) = (&x).acot_pi_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.12122");
assert_eq!(o, Greater);
Source

pub fn acot_pi_ref(&self) -> Self

Computes $\operatorname{acot}(x)/\pi$, the arccotangent of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::acot_pi and Float::acot_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
assert_eq!((&x).acot_pi_ref().to_string(), "0.12109");
Source

pub fn acsc_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acsc} x$, the arccosecant of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_prec_round for the error bounds, the special cases, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{NegativeOne, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).acsc_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "0.52344");
assert_eq!(o, Less);

let (c, o) = (&Float::NEGATIVE_ONE).acsc_prec_round_ref(10, Nearest);
assert_eq!(c.to_string(), "-1.5703");
assert_eq!(o, Greater);
Source

pub fn acsc_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acsc} x$, the arccosecant of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_prec and Float::acsc_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).acsc_prec_ref(10);
assert_eq!(c.to_string(), "0.52344");
assert_eq!(o, Less);
Source

pub fn acsc_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{acsc} x$, the arccosecant of a Float, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_round and Float::acsc_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(2u32, 100).0;
let (c, o) = (&x).acsc_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.52359877559829887307710723054682");
assert_eq!(o, Greater);
Source

pub fn acsc_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_with_period_prec_round for the error bounds, the special and closed-form cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(2.5)).acsc_with_period_prec_round_ref(360, 10, Ceiling);
assert_eq!(c.to_string(), "23.594");
assert_eq!(o, Greater);
Source

pub fn acsc_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_with_period_prec and Float::acsc_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(2.5)).acsc_with_period_prec_ref(360, 53);
assert_eq!(c.to_string(), "23.578178478201831");
assert_eq!(o, Greater);
Source

pub fn acsc_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_with_period_round and Float::acsc_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
let (c, o) = (&x).acsc_with_period_round_ref(360, Ceiling);
assert_eq!(c.to_string(), "23.578178478201831104022499419849");
assert_eq!(o, Greater);
Source

pub fn acsc_with_period_ref(&self, u: u64) -> Self

Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::acsc_with_period and Float::acsc_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
assert_eq!(
    (&x).acsc_with_period_ref(360).to_string(),
    "23.578178478201831104022499419824"
);
Source

pub fn acsc_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acsc_with_period with a period of 2: see Float::acsc_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at every precision, and they are the only exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(2.5)).acsc_pi_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "0.13110");
assert_eq!(o, Greater);
Source

pub fn acsc_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::acsc_pi_prec and Float::acsc_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(2.5)).acsc_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.13098988043445461");
assert_eq!(o, Less);
Source

pub fn acsc_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is acsc_with_period with a period of 2: see Float::acsc_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at every precision, and they are the only exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
let (c, o) = (&x).acsc_pi_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.13110");
assert_eq!(o, Greater);
Source

pub fn acsc_pi_ref(&self) -> Self

Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::acsc_pi and Float::acsc_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
assert_eq!((&x).acsc_pi_ref().to_string(), "0.13110");
Source

pub fn add_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds two Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\infty,-\infty,p,m)=f(-\infty,\infty,p,m)= \text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,p,m)=0.0$
  • $f(-0.0,-0.0,p,m)=-0.0$
  • $f(0.0,-0.0,p,m)=f(-0.0,0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,-0.0,p,m)=f(-0.0,0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,-x,p,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,-x,p,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::add_round_ref_val instead. If both of these things are true, consider using + instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Panics

Panics if rm is Exact but prec is too small for an exact addition.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "6.00");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_prec_round_ref_val(Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_val(Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_val(Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "5.8598785");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);
Source

pub fn add_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds two Floats, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\infty,-\infty,p,m)=f(-\infty,\infty,p,m)= \text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,p,m)=0.0$
  • $f(-0.0,-0.0,p,m)=-0.0$
  • $f(0.0,-0.0,p,m)=f(-0.0,0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,-0.0,p,m)=f(-0.0,0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,-x,p,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,-x,p,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::add_round_ref_ref instead. If both of these things are true, consider using + instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Panics

Panics if rm is Exact but prec is too small for an exact addition.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "6.00");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "5.8598785");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);
Source

pub fn add_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Adds two Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\infty,-\infty,p)=f(-\infty,\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p)=f(x,-\infty,p)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,p)=0.0$
  • $f(-0.0,-0.0,p)=-0.0$
  • $f(0.0,-0.0,p)=f(-0.0,0.0,p)=0.0$
  • $f(x,-x,p)=0.0$ if $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using + instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = (&Float::from(PI)).add_prec_ref_val(Float::from(E), 5);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = (&Float::from(PI)).add_prec_ref_val(Float::from(E), 20);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);
Source

pub fn add_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Adds two Floats, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\infty,-\infty,p)=f(-\infty,\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p)=f(x,-\infty,p)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,p)=0.0$
  • $f(-0.0,-0.0,p)=-0.0$
  • $f(0.0,-0.0,p)=f(-0.0,0.0,p)=0.0$
  • $f(x,-x,p)=0.0$ if $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using + instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = (&Float::from(PI)).add_prec_ref_ref(&Float::from(E), 5);
assert_eq!(sum.to_string(), "5.75");
assert_eq!(o, Less);

let (sum, o) = (&Float::from(PI)).add_prec_ref_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "5.8598709");
assert_eq!(o, Less);
Source

pub fn add_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds two Floats, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\infty,-\infty,m)=f(-\infty,\infty,m)= \text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=f(x,-\infty,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,m)=0.0$
  • $f(-0.0,-0.0,m)=-0.0$
  • $f(0.0,-0.0,m)=f(-0.0,0.0,m)=0.0$ if $m$ is not Floor
  • $f(0.0,-0.0,m)=f(-0.0,0.0,m)=-0.0$ if $m$ is Floor
  • $f(0.0,x,m)=f(x,0.0,m)=f(-0.0,x,m)=f(x,-0.0,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,-x,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,-x,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using + instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(m)$

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = (&Float::from(PI)).add_round_ref_val(Float::from(E), Floor);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);

let (sum, o) = (&Float::from(PI)).add_round_ref_val(Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.8598744820488387");
assert_eq!(o, Greater);

let (sum, o) = (&Float::from(PI)).add_round_ref_val(Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);
Source

pub fn add_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds two Floats, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\infty,-\infty,m)=f(-\infty,\infty,m)= \text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=f(x,-\infty,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0.0,m)=0.0$
  • $f(-0.0,-0.0,m)=-0.0$
  • $f(0.0,-0.0,m)=f(-0.0,0.0,m)=0.0$ if $m$ is not Floor
  • $f(0.0,-0.0,m)=f(-0.0,0.0,m)=-0.0$ if $m$ is Floor
  • $f(0.0,x,m)=f(x,0.0,m)=f(-0.0,x,m)=f(x,-0.0,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,-x,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,-x,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using + instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_round_ref_ref(&Float::from(E), Floor);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.8598744820488387");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);
Source

pub fn add_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$
  • $f(-\infty,x,p,m)=-\infty$
  • $f(0.0,0,p,m)=0.0$
  • $f(-0.0,0,p,m)=-0.0$
  • $f(x,-x,p,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,-x,p,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_rational_prec_ref_val instead. If you know that your target precision is the precision of the Float input, consider using Float::add_rational_round_ref_val instead. If both of these things are true, consider using + instead.

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

§Panics

Panics if rm is Exact but prec is too small for an exact addition.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(sum.to_string(), "3.38");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(sum.to_string(), "3.50");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(sum.to_string(), "3.50");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(sum.to_string(), "3.4749222");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(sum.to_string(), "3.4749260");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(sum.to_string(), "3.4749260");
assert_eq!(o, Greater);
Source

pub fn add_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$
  • $f(-\infty,x,p,m)=-\infty$
  • $f(0.0,0,p,m)=0.0$
  • $f(-0.0,0,p,m)=-0.0$
  • $f(x,-x,p,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,-x,p,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_rational_prec_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using Float::add_rational_round_ref_ref instead. If both of these things are true, consider using + instead.

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

§Panics

Panics if rm is Exact but prec is too small for an exact addition.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(sum.to_string(), "3.38");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(sum.to_string(), "3.50");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(sum.to_string(), "3.50");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(sum.to_string(), "3.4749222");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(sum.to_string(), "3.4749260");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(sum.to_string(), "3.4749260");
assert_eq!(o, Greater);
Source

pub fn add_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$
  • $f(-\infty,x,p)=-\infty$
  • $f(0.0,0,p)=0.0$
  • $f(-0.0,0,p)=-0.0$
  • $f(x,-x,p)=0.0$ if $x$ is nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_rational_prec_round_ref_val instead. If you know that your target precision is the precision of the Float input, consider using + instead.

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

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_rational_prec_ref_val(Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "4.75");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_ref_val(Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "4.6415939");
assert_eq!(o, Greater);
Source

pub fn add_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$
  • $f(-\infty,x,p)=-\infty$
  • $f(0.0,0,p)=0.0$
  • $f(-0.0,0,p)=-0.0$
  • $f(x,-x,p)=0.0$ if $x$ is nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_rational_prec_round_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using + instead.

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

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).add_rational_prec_ref_ref(&Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "4.75");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).add_rational_prec_ref_ref(&Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "4.6415939");
assert_eq!(o, Greater);
Source

pub fn add_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result with the specified rounding mode. The Float is taken by reference and the Float by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0,m)=0.0$
  • $f(-0.0,0,m)=-0.0$
  • $f(0.0,x,m)=f(x,0,m)=f(-0.0,x,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,-x,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,-x,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_rational_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using + instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) =
    Float::from(PI).add_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "3.4749259869231253");
assert_eq!(o, Less);

let (sum, o) =
    Float::from(PI).add_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "3.4749259869231288");
assert_eq!(o, Greater);

let (sum, o) =
    Float::from(PI).add_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "3.4749259869231253");
assert_eq!(o, Less);
Source

pub fn add_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and a Rational, rounding the result with the specified rounding mode. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x+y+\varepsilon. $$

  • If $x+y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x+y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0,m)=0.0$
  • $f(-0.0,0,m)=-0.0$
  • $f(0.0,x,m)=f(x,0,m)=f(-0.0,x,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,-x,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,-x,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_rational_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using + instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) =
    Float::from(PI).add_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "3.4749259869231253");
assert_eq!(o, Less);

let (sum, o) =
    Float::from(PI).add_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "3.4749259869231288");
assert_eq!(o, Greater);

let (sum, o) =
    Float::from(PI).add_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "3.4749259869231253");
assert_eq!(o, Less);
Source

pub fn add_mul_prec_round_ref_val_val( &self, y: Self, z: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Floor);
assert_eq!(sum.to_string(), "6.75");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Ceiling);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Nearest);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Floor);
assert_eq!(sum.to_string(), "6.9858170");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Ceiling);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Nearest);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_round_ref_val_ref( &self, y: Self, z: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the specified precision and with the specified rounding mode. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Floor);
assert_eq!(sum.to_string(), "6.75");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Ceiling);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Nearest);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Floor);
assert_eq!(sum.to_string(), "6.9858170");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Ceiling);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Nearest);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_round_ref_ref_val( &self, y: &Self, z: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the specified precision and with the specified rounding mode. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Floor);
assert_eq!(sum.to_string(), "6.75");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Ceiling);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Nearest);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Floor);
assert_eq!(sum.to_string(), "6.9858170");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Ceiling);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Nearest);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_round_ref_ref_ref( &self, y: &Self, z: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the specified precision and with the specified rounding mode. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 5, Floor);
assert_eq!(sum.to_string(), "6.75");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 5, Ceiling);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 5, Nearest);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 20, Floor);
assert_eq!(sum.to_string(), "6.9858170");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 20, Ceiling);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_round_ref_ref_ref(&y, &z, 20, Nearest);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_ref_val_val( &self, y: Self, z: Self, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of different signs
  • $f(x,y,z,p)=0.0$ if $x=-yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_ref_val_val(y.clone(), z.clone(), 5);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_ref_val_val(y.clone(), z.clone(), 20);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_ref_val_ref( &self, y: Self, z: &Self, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the nearest value of the specified precision. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of different signs
  • $f(x,y,z,p)=0.0$ if $x=-yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_ref_val_ref(y.clone(), &z, 5);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_ref_val_ref(y.clone(), &z, 20);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_ref_ref_val( &self, y: &Self, z: Self, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the nearest value of the specified precision. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of different signs
  • $f(x,y,z,p)=0.0$ if $x=-yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_ref_ref_val(&y, z.clone(), 5);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_ref_ref_val(&y, z.clone(), 20);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_prec_ref_ref_ref( &self, y: &Self, z: &Self, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result to the nearest value of the specified precision. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of different signs
  • $f(x,y,z,p)=0.0$ if $x=-yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_prec_ref_ref_ref(&y, &z, 5);
assert_eq!(sum.to_string(), "7.00");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_prec_ref_ref_ref(&y, &z, 20);
assert_eq!(sum.to_string(), "6.9858246");
assert_eq!(o, Greater);
Source

pub fn add_mul_round_ref_val_val( &self, y: Self, z: Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result with the specified rounding mode. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_round_ref_val_val(y.clone(), z.clone(), Floor);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_round_ref_val_val(y.clone(), z.clone(), Ceiling);
assert_eq!(sum.to_string(), "6.9858236817489106");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_round_ref_val_val(y.clone(), z.clone(), Nearest);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);
Source

pub fn add_mul_round_ref_val_ref( &self, y: Self, z: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result with the specified rounding mode. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_round_ref_val_ref(y.clone(), &z, Floor);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_round_ref_val_ref(y.clone(), &z, Ceiling);
assert_eq!(sum.to_string(), "6.9858236817489106");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_round_ref_val_ref(y.clone(), &z, Nearest);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);
Source

pub fn add_mul_round_ref_ref_val( &self, y: &Self, z: Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result with the specified rounding mode. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_round_ref_ref_val(&y, z.clone(), Floor);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_round_ref_ref_val(&y, z.clone(), Ceiling);
assert_eq!(sum.to_string(), "6.9858236817489106");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_round_ref_ref_val(&y, z.clone(), Nearest);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);
Source

pub fn add_mul_round_ref_ref_ref( &self, y: &Self, z: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of two other Floats, rounding the result with the specified rounding mode. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=-0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of different signs and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (sum, o) = x.add_mul_round_ref_ref_ref(&y, &z, Floor);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_round_ref_ref_ref(&y, &z, Ceiling);
assert_eq!(sum.to_string(), "6.9858236817489106");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_round_ref_ref_ref(&y, &z, Nearest);
assert_eq!(sum.to_string(), "6.9858236817489097");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_round_ref_val_val( &self, y: Self, z: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_rational_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Floor);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Ceiling);
assert_eq!(sum.to_string(), "4.25");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Nearest);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Floor);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Ceiling);
assert_eq!(sum.to_string(), "4.0476913");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Nearest);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_round_ref_val_ref( &self, y: Self, z: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_rational_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Floor);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Ceiling);
assert_eq!(sum.to_string(), "4.25");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Nearest);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Floor);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Ceiling);
assert_eq!(sum.to_string(), "4.0476913");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Nearest);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_round_ref_ref_val( &self, y: &Self, z: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_rational_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Floor);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Ceiling);
assert_eq!(sum.to_string(), "4.25");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Nearest);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Floor);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Ceiling);
assert_eq!(sum.to_string(), "4.0476913");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Nearest);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_round_ref_ref_ref( &self, y: &Self, z: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::add_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::add_mul_rational_round instead. If both of these things are true, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-add is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Floor);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Ceiling);
assert_eq!(sum.to_string(), "4.25");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Nearest);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Floor);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Ceiling);
assert_eq!(sum.to_string(), "4.0476913");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Nearest);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_ref_val_val( &self, y: Self, z: Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=-yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_ref_val_val(y.clone(), z.clone(), 5);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_ref_val_val(y.clone(), z.clone(), 20);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_ref_val_ref( &self, y: Self, z: &Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the nearest value of the specified precision. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=-yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_ref_val_ref(y.clone(), &z, 5);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_ref_val_ref(y.clone(), &z, 20);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_ref_ref_val( &self, y: &Self, z: Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the nearest value of the specified precision. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=-yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_ref_ref_val(&y, z.clone(), 5);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_ref_ref_val(&y, z.clone(), 20);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_prec_ref_ref_ref( &self, y: &Self, z: &Rational, prec: u64, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result to the nearest value of the specified precision. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=-yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::add_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_prec_ref_ref_ref(&y, &z, 5);
assert_eq!(sum.to_string(), "4.00");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_prec_ref_ref_ref(&y, &z, 20);
assert_eq!(sum.to_string(), "4.0476837");
assert_eq!(o, Less);
Source

pub fn add_mul_rational_round_ref_val_val( &self, y: Self, z: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result with the specified rounding mode. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_round_ref_val_val(y.clone(), z.clone(), Floor);
assert_eq!(sum.to_string(), "4.0476865964094744");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_round_ref_val_val(y.clone(), z.clone(), Ceiling);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_round_ref_val_val(y.clone(), z.clone(), Nearest);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);
Source

pub fn add_mul_rational_round_ref_val_ref( &self, y: Self, z: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result with the specified rounding mode. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_round_ref_val_ref(y.clone(), &z, Floor);
assert_eq!(sum.to_string(), "4.0476865964094744");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_round_ref_val_ref(y.clone(), &z, Ceiling);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_round_ref_val_ref(y.clone(), &z, Nearest);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);
Source

pub fn add_mul_rational_round_ref_ref_val( &self, y: &Self, z: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result with the specified rounding mode. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_round_ref_ref_val(&y, z.clone(), Floor);
assert_eq!(sum.to_string(), "4.0476865964094744");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_round_ref_ref_val(&y, z.clone(), Ceiling);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_round_ref_ref_val(&y, z.clone(), Nearest);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);
Source

pub fn add_mul_rational_round_ref_ref_ref( &self, y: &Self, z: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds a Float and the product of another Float and a Rational, rounding the result with the specified rounding mode. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x+yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x+yz+\varepsilon. $$

  • If $x+yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x+yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x+yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x+yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x+yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=-yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::add_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using add_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(1, 3);

let (sum, o) = x.add_mul_rational_round_ref_ref_ref(&y, &z, Floor);
assert_eq!(sum.to_string(), "4.0476865964094744");
assert_eq!(o, Less);

let (sum, o) = x.add_mul_rational_round_ref_ref_ref(&y, &z, Ceiling);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);

let (sum, o) = x.add_mul_rational_round_ref_ref_ref(&y, &z, Nearest);
assert_eq!(sum.to_string(), "4.0476865964094753");
assert_eq!(o, Greater);
Source

pub fn agm_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p+1}$.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(-\infty,x,p,m)=f(x,-\infty,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,p,m)=\infty$
  • $f(\pm0.0,x,p,m)=f(x,\pm0.0,p,m)=0.0$
  • $f(x,y,p,m)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::agm_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::agm_round_ref_val instead. If both of these things are true, consider using Float::agm instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the two Float arguments are positive and distinct (and the exact result is therefore irrational).

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

let (agm, o) = Float::from(24).agm_prec_round_val_ref(&Float::from(6), 5, Floor);
assert_eq!(agm.to_string(), "13.0");
assert_eq!(o, Less);

let (agm, o) = Float::from(24).agm_prec_round_ref_val(Float::from(6), 5, Ceiling);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_val(Float::from(6), 5, Nearest);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_val(Float::from(6), 20, Floor);
assert_eq!(agm.to_string(), "13.458160");
assert_eq!(o, Less);

let (agm, o) = Float::from(24).agm_prec_round_ref_val(Float::from(6), 20, Ceiling);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_val(Float::from(6), 20, Nearest);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);
Source

pub fn agm_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p+1}$.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(-\infty,x,p,m)=f(x,-\infty,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,p,m)=\infty$
  • $f(\pm0.0,x,p,m)=f(x,\pm0.0,p,m)=0.0$
  • $f(x,y,p,m)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::agm_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::agm_round_ref_ref instead. If both of these things are true, consider using Float::agm instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the two Float arguments are positive and distinct (and the exact result is therefore irrational).

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

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 5, Floor);
assert_eq!(agm.to_string(), "13.0");
assert_eq!(o, Less);

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 5, Ceiling);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 5, Nearest);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 20, Floor);
assert_eq!(agm.to_string(), "13.458160");
assert_eq!(o, Less);

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 20, Ceiling);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);

let (agm, o) = Float::from(24).agm_prec_round_ref_ref(&Float::from(6), 20, Nearest);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);

This is mpfr_agm from agm.c, MPFR 4.3.0.

Source

pub fn agm_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the agm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(-\infty,x,p)=f(x,-\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,p)=\infty$
  • $f(\pm0.0,x,p)=f(x,\pm0.0,p)=0.0$
  • $f(x,y,p)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::agm_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::agm instead.

§Worst-case complexity

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

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (agm, o) = (&Float::from(24)).agm_prec_ref_val(Float::from(6), 5);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = (&Float::from(24)).agm_prec_ref_val(Float::from(6), 20);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);
Source

pub fn agm_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the agm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(-\infty,x,p)=f(x,-\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,p)=\infty$
  • $f(\pm0.0,x,p)=f(x,\pm0.0,p)=0.0$
  • $f(x,y,p)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::agm_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::agm instead.

§Worst-case complexity

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

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (agm, o) = (&Float::from(24)).agm_prec_ref_ref(&Float::from(6), 5);
assert_eq!(agm.to_string(), "13.5");
assert_eq!(o, Greater);

let (agm, o) = (&Float::from(24)).agm_prec_ref_ref(&Float::from(6), 20);
assert_eq!(agm.to_string(), "13.458176");
assert_eq!(o, Greater);
Source

pub fn agm_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(-\infty,x,m)=f(x,-\infty,m)=\text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,m)=\infty$
  • $f(\pm0.0,x,m)=f(x,\pm0.0,m)=0.0$
  • $f(x,y,m)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::agm_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using Float::agm instead.

§Worst-case complexity

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

$M(n) = O(m)$

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

§Panics

Panics if rm is Exact but the two Float arguments are positive and distinct (and the exact result is therefore irrational).

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

let (agm, o) =
    (&Float::from_unsigned_prec(24u8, 100).0).agm_round_ref_val(Float::from(6), Floor);
assert_eq!(agm.to_string(), "13.458171481725615420766813156964");
assert_eq!(o, Less);

let (agm, o) =
    (&Float::from_unsigned_prec(24u8, 100).0).agm_round_ref_val(Float::from(6), Ceiling);
assert_eq!(agm.to_string(), "13.458171481725615420766813156976");
assert_eq!(o, Greater);

let (agm, o) =
    (&Float::from_unsigned_prec(24u8, 100).0).agm_round_ref_val(Float::from(6), Nearest);
assert_eq!(agm.to_string(), "13.458171481725615420766813156976");
assert_eq!(o, Greater);
Source

pub fn agm_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the arithmetic-geometric mean (AGM) of two Floats, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded AGM is less than, equal to, or greater than the exact AGM. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = \text{AGM}(x,y)+\varepsilon =\frac{\pi}{2}\left(\int_0^{\frac{\pi}{2}}\frac{\mathrm{d}\theta} {\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\right)^{-1}+\varepsilon. $$

  • If $\text{AGM}(x,y)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $\text{AGM}(x,y)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \text{AGM}(x,y)\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(-\infty,x,m)=f(x,-\infty,m)=\text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\text{NaN}$ if $x\neq\infty$
  • $f(\infty,\infty,m)=\infty$
  • $f(\pm0.0,x,m)=f(x,\pm0.0,m)=0.0$
  • $f(x,y,m)=\text{NaN}$ if $x<0$ or $y<0$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::agm_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using Float::agm instead.

§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 rm is Exact but the two Float arguments are positive and distinct (and the exact result is therefore irrational).

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

let (agm, o) = Float::from_unsigned_prec(24u8, 100)
    .0
    .agm_round_ref_ref(&Float::from(6), Floor);
assert_eq!(agm.to_string(), "13.458171481725615420766813156964");
assert_eq!(o, Less);

let (agm, o) = Float::from_unsigned_prec(24u8, 100)
    .0
    .agm_round_ref_ref(&Float::from(6), Ceiling);
assert_eq!(agm.to_string(), "13.458171481725615420766813156976");
assert_eq!(o, Greater);

let (agm, o) = Float::from_unsigned_prec(24u8, 100)
    .0
    .agm_round_ref_ref(&Float::from(6), Nearest);
assert_eq!(agm.to_string(), "13.458171481725615420766813156976");
assert_eq!(o, Greater);
Source

pub fn asec_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{asec} x$, the arcsecant of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_prec_round for the error bounds, the special cases, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{NegativeOne, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).asec_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "1.0469");
assert_eq!(o, Less);

// an input of -1 gives pi
let (c, o) = (&Float::NEGATIVE_ONE).asec_prec_round_ref(10, Nearest);
assert_eq!(c.to_string(), "3.1406");
assert_eq!(o, Less);
Source

pub fn asec_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{asec} x$, the arcsecant of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_prec and Float::asec_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::TWO).asec_prec_ref(10);
assert_eq!(c.to_string(), "1.0469");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(2u32, 100).0).asec_prec_ref(100);
assert_eq!(c.to_string(), "1.0471975511965977461542144610936");
assert_eq!(o, Greater);
Source

pub fn asec_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{asec} x$, the arcsecant of a Float, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_round and Float::asec_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(2u32, 100).0;
let (c, o) = (&x).asec_round_ref(Ceiling);
assert_eq!(c.to_string(), "1.0471975511965977461542144610936");
assert_eq!(o, Greater);
Source

pub fn asec_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{asec}(x)u/(2\pi)$, the arcsecant of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_with_period_prec_round for the error bounds, the special and closed-form cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// an input of -2 is a third of a turn
let (c, o) = (&-Float::TWO).asec_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(c.to_string(), "120.00");
assert_eq!(o, Equal);

let (c, o) = (&Float::from(1.5)).asec_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(c.to_string(), "48.188");
assert_eq!(o, Less);
Source

pub fn asec_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\operatorname{asec}(x)u/(2\pi)$, the arcsecant of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_with_period_prec and Float::asec_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(1.5)).asec_with_period_prec_ref(360, 10);
assert_eq!(c.to_string(), "48.188");
assert_eq!(o, Less);
Source

pub fn asec_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{asec}(x)u/(2\pi)$, the arcsecant of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_with_period_round and Float::asec_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(3u32, 10).0 >> 1u32;
let (c, o) = (&x).asec_with_period_round_ref(360, Ceiling);
assert_eq!(c.to_string(), "48.250");
assert_eq!(o, Greater);
Source

pub fn asec_with_period_ref(&self, u: u64) -> Self

Computes $\operatorname{asec}(x)u/(2\pi)$, the arcsecant of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the input’s precision. The Float is taken by reference.

See Float::asec_with_period and Float::asec_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(3u32, 10).0 >> 1u32;
assert_eq!((&x).asec_with_period_ref(360).to_string(), "48.188");
Source

pub fn asec_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{asec}(x)/\pi$, the arcsecant of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is asec_with_period with a period of 2: see Float::asec_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives $1/2$, an input of 1 gives $0.0$, and an input of $-1$ gives $1$; all three are exact at every precision, and they are the only exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible, since $0 \leq \operatorname{asec}(x)/\pi \leq 1$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (c, o) = (&Float::from(2.5)).asec_pi_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "0.36914");
assert_eq!(o, Greater);
Source

pub fn asec_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{asec}(x)/\pi$, the arcsecant of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asec_pi_prec and Float::asec_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from(2.5)).asec_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.36901011956554536");
assert_eq!(o, Less);
Source

pub fn asec_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\operatorname{asec}(x)/\pi$, the arcsecant of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsecant is less than, equal to, or greater than the exact arcsecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is asec_with_period with a period of 2: see Float::asec_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity gives $1/2$, an input of 1 gives $0.0$, and an input of $-1$ gives $1$; all three are exact at every precision, and they are the only exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible, since $0 \leq \operatorname{asec}(x)/\pi \leq 1$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
let (c, o) = (&x).asec_pi_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.36914");
assert_eq!(o, Greater);
Source

pub fn asec_pi_ref(&self) -> Self

Computes $\operatorname{asec}(x)/\pi$, the arcsecant of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

See Float::asec_pi and Float::asec_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
assert_eq!((&x).asec_pi_ref().to_string(), "0.36914");
Source

pub fn asin_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arcsin x$, the arcsine of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \arcsin x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\arcsin x|\rfloor-p+1}$.
  • If $x$ is not NaN and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\arcsin x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=f(\pm\infty,p,m)=\text{NaN}$
  • $f(x,p,m)=\text{NaN}$ for $|x|>1$
  • $f(\pm0.0,p,m)=\pm0.0$
  • $f(\pm1,p,m)=\pm\pi/2$, rounded

Neither overflow nor underflow is possible: the result lies in $[-\pi/2, \pi/2]$, and $|\arcsin x| > |x|$ for nonzero $x$, so a representable input always has a representable result.

If you know you’ll be using Nearest, consider using Float::asin_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::asin_round_ref instead. If both of these things are true, consider using (&Float).asin() instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is prec, and $m$ is self.significant_bits(): the arcsine is taken as $\arctan(x/\sqrt{1-x^2})$ at a working precision of about $n$ plus the number of bits that cancel in $1-x^2$, which an input within $2^{-m}$ of $\pm1$ pushes to $m$; the arctangent at that width dominates. The magnitude of the input does not otherwise drive the cost.

§Panics

Panics if rm is Exact and self is nonzero and not NaN, since the arcsine of a finite nonzero Float is never exactly representable and neither is $\pm\pi/2$, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "1.62");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "1.5707951");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "1.5707970");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "1.5707970");
assert_eq!(o, Greater);
Source

pub fn asin_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arcsin x$, the arcsine of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the arcsine is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \arcsin x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN, then $|\varepsilon| < 2^{\lfloor\log_2 |\arcsin x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=f(\pm\infty,p,m)=\text{NaN}$
  • $f(x,p,m)=\text{NaN}$ for $|x|>1$
  • $f(\pm0.0,p,m)=\pm0.0$
  • $f(\pm1,p,m)=\pm\pi/2$, rounded

Neither overflow nor underflow is possible: the result lies in $[-\pi/2, \pi/2]$, and $|\arcsin x| > |x|$ for nonzero $x$, so a representable input always has a representable result.

If you want to use a rounding mode other than Nearest, consider using Float::asin_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).asin() instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is prec, and $m$ is self.significant_bits(): the arcsine is taken as $\arctan(x/\sqrt{1-x^2})$ at a working precision of about $n$ plus the number of bits that cancel in $1-x^2$, which an input within $2^{-m}$ of $\pm1$ pushes to $m$; the arctangent at that width dominates. The magnitude of the input does not otherwise drive the cost.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_ref(5);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_prec_ref(20);
assert_eq!(c.to_string(), "1.5707970");
assert_eq!(o, Greater);
Source

pub fn asin_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arcsin x$, the arcsine of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \arcsin x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\arcsin x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is not NaN and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\arcsin x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},p,m)=f(\pm\infty,p,m)=\text{NaN}$
  • $f(x,p,m)=\text{NaN}$ for $|x|>1$
  • $f(\pm0.0,p,m)=\pm0.0$
  • $f(\pm1,p,m)=\pm\pi/2$, rounded

Neither overflow nor underflow is possible: the result lies in $[-\pi/2, \pi/2]$, and $|\arcsin x| > |x|$ for nonzero $x$, so a representable input always has a representable result.

If you want to specify an output precision, consider using Float::asin_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).asin() instead.

§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 self.significant_bits(): the arcsine is taken as $\arctan(x/\sqrt{1-x^2})$ at a working precision of about $n$ plus the number of bits that cancel in $1-x^2$, which an input within $2^{-n}$ of $\pm1$ pushes to another $n$; the arctangent at that width dominates. The magnitude of the input does not otherwise drive the cost.

§Panics

Panics if rm is Exact and self is nonzero and not NaN, since the arcsine of a finite nonzero Float is never exactly representable and neither is $\pm\pi/2$.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_round_ref(Floor);
assert_eq!(c.to_string(), "1.5707963267948966192313216916397");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_round_ref(Ceiling);
assert_eq!(c.to_string(), "1.5707963267948966192313216916412");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).asin_round_ref(Nearest);
assert_eq!(c.to_string(), "1.5707963267948966192313216916397");
assert_eq!(o, Less);
Source

pub fn asin_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arcsin(x)u/(2\pi)$, the arcsine of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asin_with_period_prec_round for the error bounds, the special and closed-form cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).asin_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(t.to_string(), "90.000");
assert_eq!(o, Equal);

let (t, o) = (&(Float::ONE_HALF >> 1u32)).asin_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(t.to_string(), "14.469");
assert_eq!(o, Less);
Source

pub fn asin_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\arcsin(x)u/(2\pi)$, the arcsine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asin_with_period_prec and Float::asin_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::OneHalf;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&(Float::ONE_HALF >> 1u32)).asin_with_period_prec_ref(360, 10);
assert_eq!(t.to_string(), "14.484");
assert_eq!(o, Greater);
Source

pub fn asin_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arcsin(x)u/(2\pi)$, the arcsine of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::asin_with_period_round and Float::asin_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
let (t, o) = (&x).asin_with_period_round_ref(360, Floor);
assert_eq!(t.to_string(), "14.469");
assert_eq!(o, Less);
Source

pub fn asin_with_period_ref(&self, u: u64) -> Self

Computes $\arcsin(x)u/(2\pi)$, the arcsine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the input’s precision. The Float is taken by reference.

See Float::asin_with_period and Float::asin_with_period_prec_round; this function behaves the same way.

§Examples
use malachite_float::Float;

let x = Float::from_unsigned_prec(1u32, 10).0 >> 2u32;
assert_eq!((&x).asin_with_period_ref(360).to_string(), "14.484");
Source

pub fn asin_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arcsin(x)/\pi$, the arcsine of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is asin_with_period with a period of 2: see Float::asin_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$, exact at every precision, since a half needs only one bit, and a zero input gives $\pm0.0$; those are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $|\arcsin(x)/\pi| \leq 1/2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (t, o) = (&Float::from(0.1f64)).asin_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "0.031860");
assert_eq!(o, Less);

let (t, o) = (&Float::from(0.1f64)).asin_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "0.031921");
assert_eq!(o, Greater);
Source

pub fn asin_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arcsin(x)/\pi$, the arcsine of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is asin_with_period with a period of 2: see Float::asin_with_period_prec_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$, exact at every precision, since a half needs only one bit, and a zero input gives $\pm0.0$; those are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $|\arcsin(x)/\pi| \leq 1/2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::from(0.1f64)).asin_pi_prec_ref(10);
assert_eq!(t.to_string(), "0.031860");
assert_eq!(o, Less);

let (t, o) = (&Float::from(0.1f64)).asin_pi_prec_ref(53);
assert_eq!(t.to_string(), "0.031884280429259927");
assert_eq!(o, Greater);
Source

pub fn asin_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arcsin(x)/\pi$, the arcsine of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arcsine is less than, equal to, or greater than the exact arcsine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is asin_with_period with a period of 2: see Float::asin_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$, exact at every precision, since a half needs only one bit, and a zero input gives $\pm0.0$; those are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $|\arcsin(x)/\pi| \leq 1/2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (t, o) = (&Float::from(0.1f64)).asin_pi_round_ref(Floor);
assert_eq!(t.to_string(), "0.031884280429259920");
assert_eq!(o, Less);
Source

pub fn asin_pi_ref(&self) -> Self

Computes $\arcsin(x)/\pi$, the arcsine of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the arcsine is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is asin_with_period with a period of 2: see Float::asin_with_period_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$, exact at every precision, since a half needs only one bit, and a zero input gives $\pm0.0$; those are the only exact cases. NaN, either infinity, and any $|x|>1$ give NaN. Overflow is not possible, since $|\arcsin(x)/\pi| \leq 1/2$.

§Examples
use malachite_float::Float;

assert_eq!(
    (&Float::from(0.1f64)).asin_pi_ref().to_string(),
    "0.031884280429259920"
);
Source

pub fn atan_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arctan x$, the arctangent of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \arctan x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\arctan x|\rfloor-p+1}$.
  • If $x$ is not NaN and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\arctan x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\pm\pi/2$, rounded
  • $f(\pm0.0,p,m)=\pm0.0$

Overflow and underflow:

  • Since $|\arctan x| < \pi/2$, the result never overflows.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero: since $|\arctan x| < |x|$ for nonzero $x$, no other input can reach it.

If you know you’ll be using Nearest, consider using Float::atan_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::atan_round_ref instead. If both of these things are true, consider using (&Float).atan() instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is prec, and $m$ is self.significant_bits(): an input above 1 in magnitude is first inverted, and the argument is then halved a logarithmic number of times and split into chunks whose arctangents are summed by binary splitting, all at a working precision of about $n$; the summation is the first term, and the inversion of the $m$-bit input the second. The magnitude of the input does not drive the cost.

§Panics

Panics if rm is Exact and self is nonzero and not NaN, since the arctangent of a finite nonzero Float is never exactly representable and neither is $\pm\pi/2$, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "0.781");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "0.812");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "0.781");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "0.78539753");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "0.78539848");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "0.78539848");
assert_eq!(o, Greater);
Source

pub fn atan_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arctan x$, the arctangent of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the arctangent is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \arctan x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN, then $|\varepsilon| < 2^{\lfloor\log_2 |\arctan x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\pm\pi/2$, rounded
  • $f(\pm0.0,p)=1.0$

Overflow and underflow:

  • Since $|\arctan x| < \pi/2$, the result never overflows.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero: since $|\arctan x| < |x|$ for nonzero $x$, no other input can reach it.

If you want to use a rounding mode other than Nearest, consider using Float::atan_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).atan() instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is prec, and $m$ is self.significant_bits(): an input above 1 in magnitude is first inverted, and the argument is then halved a logarithmic number of times and split into chunks whose arctangents are summed by binary splitting, all at a working precision of about $n$; the summation is the first term, and the inversion of the $m$-bit input the second. The magnitude of the input does not drive the cost.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_ref(5);
assert_eq!(c.to_string(), "0.781");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_prec_ref(20);
assert_eq!(c.to_string(), "0.78539848");
assert_eq!(o, Greater);
Source

pub fn atan_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arctan x$, the arctangent of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \arctan x+\varepsilon. $$

  • If $x$ is NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is not NaN and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\arctan x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is not NaN and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\arctan x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\pm\pi/2$, rounded
  • $f(\pm0.0,m)=1.0$

Overflow and underflow:

  • Since $|\arctan x| < \pi/2$, the result never overflows.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero: since $|\arctan x| < |x|$ for nonzero $x$, no other input can reach it.

If you want to specify an output precision, consider using Float::atan_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).atan() instead.

§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 self.significant_bits(): an input above 1 in magnitude is first inverted, and the argument is then halved a logarithmic number of times and split into chunks whose arctangents are summed by binary splitting, all at a working precision of about $n$. The magnitude of the input does not drive the cost.

§Panics

Panics if rm is Exact and self is nonzero and not NaN, since the arctangent of a finite nonzero Float is never exactly representable and neither is $\pm\pi/2$.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_round_ref(Floor);
assert_eq!(c.to_string(), "0.78539816339744830961566084581983");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.78539816339744830961566084582062");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).atan_round_ref(Nearest);
assert_eq!(c.to_string(), "0.78539816339744830961566084581983");
assert_eq!(o, Less);
Source

pub fn atan_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arctan(x)u/(2\pi)$, the arctangent of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(t.to_string(), "45.000");
assert_eq!(o, Equal);

let (t, o) = (&Float::TWO).atan_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(t.to_string(), "63.375");
assert_eq!(o, Less);
Source

pub fn atan_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\arctan(x)u/(2\pi)$, the arctangent of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan_with_period_prec and Float::atan_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::TWO).atan_with_period_prec_ref(360, 10);
assert_eq!(t.to_string(), "63.438");
assert_eq!(o, Greater);
Source

pub fn atan_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arctan(x)u/(2\pi)$, the arctangent of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan_with_period_round and Float::atan_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

// the output takes the input's precision, here 10 bits
let x = Float::from_unsigned_prec(2u32, 10).0;
let (t, o) = (&x).atan_with_period_round_ref(360, Floor);
assert_eq!(t.to_string(), "63.375");
assert_eq!(o, Less);
Source

pub fn atan_with_period_ref(&self, u: u64) -> Self

Computes $\arctan(x)u/(2\pi)$, the arctangent of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the arctangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::atan_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::atan_with_period_round_ref instead. If you want to specify an output precision, consider using Float::atan_with_period_prec_ref. If you want both of these things, consider using Float::atan_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from_unsigned_prec(2u32, 10).0).atan_with_period_ref(360);
assert_eq!(t.to_string(), "63.438");
Source

pub fn atan_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\arctan(x)/\pi$, the arctangent of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan_with_period with a period of 2: see Float::atan_with_period_prec_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite input gives $\pm1/2$ and an input of $\pm1$ gives $\pm1/4$, both exact at every precision, since a half and a quarter need only one bit; a zero input gives $\pm0.0$. Those are the only exact cases. Overflow is not possible, since $|\arctan(x)/\pi| < 1/2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).atan_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "0.031677");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).atan_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "0.031738");
assert_eq!(o, Greater);

// an input of 1 gives an eighth of a turn, which is a quarter of a half-turn, exactly
let (t, o) = (&Float::ONE).atan_pi_prec_round_ref(10, Exact);
assert_eq!(t.to_string(), "0.25000");
assert_eq!(o, Equal);
Source

pub fn atan_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\arctan(x)/\pi$, the arctangent of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan_with_period with a period of 2: see Float::atan_with_period_prec_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite input gives $\pm1/2$ and an input of $\pm1$ gives $\pm1/4$, both exact at every precision, since a half and a quarter need only one bit; a zero input gives $\pm0.0$. Those are the only exact cases. Overflow is not possible, since $|\arctan(x)/\pi| < 1/2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).atan_pi_prec_ref(10);
assert_eq!(t.to_string(), "0.031738");
assert_eq!(o, Greater);

let (t, o) = (Float::from(0.1f64)).atan_pi_prec_ref(53);
assert_eq!(t.to_string(), "0.031725517430553574");
assert_eq!(o, Greater);
Source

pub fn atan_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\arctan(x)/\pi$, the arctangent of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded arctangent is less than, equal to, or greater than the exact arctangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan_with_period with a period of 2: see Float::atan_with_period_round_ref for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite input gives $\pm1/2$ and an input of $\pm1$ gives $\pm1/4$, both exact at every precision, since a half and a quarter need only one bit; a zero input gives $\pm0.0$. Those are the only exact cases. Overflow is not possible, since $|\arctan(x)/\pi| < 1/2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (t, o) = (Float::from(0.1f64)).atan_pi_round_ref(Floor);
assert_eq!(t.to_string(), "0.031725517430553560");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).atan_pi_round_ref(Nearest);
assert_eq!(t.to_string(), "0.031725517430553574");
assert_eq!(o, Greater);
Source

pub fn atan_pi_ref(&self) -> Self

Computes $\arctan(x)/\pi$, the arctangent of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the arctangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is atan_with_period with a period of 2: see Float::atan_with_period for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite input gives $\pm1/2$ and an input of $\pm1$ gives $\pm1/4$, both exact at every precision, since a half and a quarter need only one bit; a zero input gives $\pm0.0$. Those are the only exact cases. Overflow is not possible, since $|\arctan(x)/\pi| < 1/2$.

If you want to use a rounding mode other than Nearest, consider using Float::atan_pi_round_ref instead. If you want to specify an output precision, consider using Float::atan_pi_prec_ref. If you want both of these things, consider using Float::atan_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from(0.1f64)).atan_pi_ref();
assert_eq!(t.to_string(), "0.031725517430553574");
Source

pub fn atan2_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result to the specified precision and with the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision (which is the case unless the result is a zero).

§Examples
use malachite_base::num::basic::traits::{NegativeOne, One, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_prec_round_ref_ref(&Float::ONE, 10, Floor);
assert_eq!(t.to_string(), "0.78516");
assert_eq!(o, Less);

// a negative x with a zero y is half a turn
let (t, o) = (&Float::ZERO).atan2_prec_round_ref_ref(&Float::NEGATIVE_ONE, 10, Floor);
assert_eq!(t.to_string(), "3.1406");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_prec_round_ref_ref( &self, other: &Self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// an eighth of a turn
let (t, o) =
    (&Float::ONE).atan2_with_period_prec_round_ref_ref(&Float::ONE, 360, 10, Exact);
assert_eq!(t.to_string(), "45.000");
assert_eq!(o, Equal);

let (t, o) =
    (&Float::ONE).atan2_with_period_prec_round_ref_ref(&Float::TWO, 360, 10, Floor);
assert_eq!(t.to_string(), "26.562");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_prec_round_ref_val( &self, other: Self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// an eighth of a turn
let (t, o) = (&Float::ONE).atan2_with_period_prec_round_ref_val(Float::ONE, 360, 10, Exact);
assert_eq!(t.to_string(), "45.000");
assert_eq!(o, Equal);

let (t, o) = (&Float::ONE).atan2_with_period_prec_round_ref_val(Float::TWO, 360, 10, Floor);
assert_eq!(t.to_string(), "26.562");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_prec_ref_val( &self, other: Self, u: u64, prec: u64, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the angle is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::atan2_with_period_prec_round instead.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_with_period_prec_ref_val(Float::TWO, 360, 10);
assert_eq!(t.to_string(), "26.562");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_prec_ref_ref( &self, other: &Self, u: u64, prec: u64, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the angle is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::atan2_with_period_prec_round instead.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_with_period_prec_ref_ref(&Float::TWO, 360, 10);
assert_eq!(t.to_string(), "26.562");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_round_ref_val( &self, other: Self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with prec the maximum input precision.

If you want to specify the output precision, consider using Float::atan2_with_period_prec_round instead.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let (t, o) =
    (&Float::from(0.3f64)).atan2_with_period_round_ref_val(Float::from(0.4f64), 360, Floor);
assert_eq!(t.to_string(), "36.869897645844013");
assert_eq!(o, Less);
Source

pub fn atan2_with_period_round_ref_ref( &self, other: &Self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the positive $x$-axis in $u$ths of a turn, rounding the result to the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

See Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with prec the maximum input precision.

If you want to specify the output precision, consider using Float::atan2_with_period_prec_round instead.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let y = Float::from(0.3f64);
let x = Float::from(0.4f64);
let (t, o) = (&y).atan2_with_period_round_ref_ref(&x, 360, Floor);
assert_eq!(t.to_string(), "36.869897645844013");
assert_eq!(o, Less);
Source

pub fn atan2_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision (which is the case unless the result is a zero).

§Examples
use malachite_base::num::basic::traits::{NegativeOne, One, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_prec_round_ref_val(Float::ONE, 10, Floor);
assert_eq!(t.to_string(), "0.78516");
assert_eq!(o, Less);

// a negative x with a zero y is half a turn
let (t, o) = (&Float::ZERO).atan2_prec_round_ref_val(Float::NEGATIVE_ONE, 10, Floor);
assert_eq!(t.to_string(), "3.1406");
assert_eq!(o, Less);
Source

pub fn atan2_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the angle is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::atan2_prec_round instead.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_prec_ref_val(Float::ONE, 10);
assert_eq!(t.to_string(), "0.78516");
assert_eq!(o, Less);
Source

pub fn atan2_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result to the nearest value of the specified precision. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the angle is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::atan2_prec_round instead.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_prec_ref_ref(&Float::ONE, 10);
assert_eq!(t.to_string(), "0.78516");
assert_eq!(o, Less);
Source

pub fn atan2_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with prec the maximum input precision.

If you want to specify the output precision, consider using Float::atan2_prec_round instead.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let (t, o) = (&Float::from(0.3f64)).atan2_round_ref_val(Float::from(0.4f64), Floor);
assert_eq!(t.to_string(), "0.64350110879328426");
assert_eq!(o, Less);
Source

pub fn atan2_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive $x$-axis, rounding the result with the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

See Float::atan2_prec_round for the error bounds, the special cases, underflow, and the complexity; this function is that one with prec the maximum input precision.

If you want to specify the output precision, consider using Float::atan2_prec_round instead.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let (t, o) = (&Float::from(0.3f64)).atan2_round_ref_ref(&Float::from(0.4f64), Floor);
assert_eq!(t.to_string(), "0.64350110879328426");
assert_eq!(o, Less);
Source

pub fn atan2_pi_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// the first quadrant's diagonal is a quarter turn
let (t, o) = (&Float::ONE).atan2_pi_prec_round_ref_val(Float::ONE, 10, Exact);
assert_eq!(t.to_string(), "0.25000");
assert_eq!(o, Equal);

let (t, o) = (&Float::ONE).atan2_pi_prec_round_ref_val(Float::TWO, 10, Floor);
assert_eq!(t.to_string(), "0.14746");
assert_eq!(o, Less);
Source

pub fn atan2_pi_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

// the first quadrant's diagonal is a quarter turn
let (t, o) = (&Float::ONE).atan2_pi_prec_round_ref_ref(&Float::ONE, 10, Exact);
assert_eq!(t.to_string(), "0.25000");
assert_eq!(o, Equal);

let (t, o) = (&Float::ONE).atan2_pi_prec_round_ref_ref(&Float::TWO, 10, Floor);
assert_eq!(t.to_string(), "0.14746");
assert_eq!(o, Less);
Source

pub fn atan2_pi_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_pi_prec_ref_val(Float::TWO, 10);
assert_eq!(t.to_string(), "0.14771");
assert_eq!(o, Greater);
Source

pub fn atan2_pi_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the nearest value of the specified precision. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (&Float::ONE).atan2_pi_prec_ref_ref(&Float::TWO, 10);
assert_eq!(t.to_string(), "0.14771");
assert_eq!(o, Greater);
Source

pub fn atan2_pi_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let (t, o) = (&Float::from(0.3f64)).atan2_pi_round_ref_val(Float::from(0.4f64), Floor);
assert_eq!(t.to_string(), "0.20483276469913342");
assert_eq!(o, Less);
Source

pub fn atan2_pi_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\operatorname{atan2}(y,x)/\pi$, the angle of the point $(x,y)$ measured from the positive $x$-axis in half-turns, rounding the result to the specified rounding mode. The Floats are both taken by reference. An Ordering is also returned, indicating whether the rounded angle is less than, equal to, or greater than the exact angle. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is atan2_with_period with a period of 2: see Float::atan2_with_period_prec_round for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. An infinite $y$ gives $\pm1/4$ against $+\infty$ and $\pm3/4$ against $-\infty$, and $\pm1/2$ against a finite $x$; a zero $y$ gives $\pm0.0$ for a positive-signed $x$ and $\pm1$ for a negative-signed one; a zero $x$ gives $\pm1/2$; and the quadrant diagonals give $\pm1/4$ and $\pm3/4$. All of those are exact at every precision except $\pm3/4$, which needs two bits.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the inputs.

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

let (t, o) = (&Float::from(0.3f64)).atan2_pi_round_ref_ref(&Float::from(0.4f64), Floor);
assert_eq!(t.to_string(), "0.20483276469913342");
assert_eq!(o, Less);
Source

pub fn average_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result to the specified precision and with the specified rounding mode, and taking the first Float 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 exact average.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you know you’ll be using Nearest, consider using Float::average_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::average_round_ref_val instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the average is not exactly representable with the specified precision.

§Examples

See here.

Source

pub fn average_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result to the specified precision and with the specified rounding mode, and taking both Floats by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact average.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you know you’ll be using Nearest, consider using Float::average_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::average_round_ref_ref instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the average is not exactly representable with the specified precision.

§Examples

See here.

Source

pub fn average_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result to the nearest value of the specified precision, and taking the first Float 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 exact average. If a rounding is a tie, the value with fewer 1s in its binary expansion is chosen.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you want to specify the rounding mode, consider using Float::average_prec_round_ref_val instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples

See here.

Source

pub fn average_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result to the nearest value of the specified precision, and taking both Floats by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact average. If a rounding is a tie, the value with fewer 1s in its binary expansion is chosen.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you want to specify the rounding mode, consider using Float::average_prec_round_ref_ref instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples

See here.

Source

pub fn average_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result with the specified rounding mode, and taking the first Float 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 exact average.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you want to specify the output precision, consider using Float::average_prec_round_ref_val instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact but the average is not exactly representable with the maximum of the inputs’ precisions.

§Examples

See here.

Source

pub fn average_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the average (arithmetic mean) of two Floats, rounding the result with the specified rounding mode, and taking both Floats by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact average.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

The average is computed as though with unbounded exponent range and rounded exactly once, so a sum that would overflow, or a halving that would underflow, does not spoil a result that is itself in range.

If either input is NaN, the result is NaN; the average of an infinity and any value other than the opposite infinity is that infinity, and the average of the two opposite infinities is NaN.

$$ f(x,y,p,m) = \frac{x+y}{2}, $$

rounded to $p$ bits in the direction specified by $m$.

If you want to specify the output precision, consider using Float::average_prec_round_ref_ref instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact but the average is not exactly representable with the maximum of the inputs’ precisions.

§Examples

See here.

Source

pub fn cbrt_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Takes the cube root of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cube root is less than, equal to, or greater than the exact cube root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See the Float::cbrt_prec_round documentation for information on special cases, overflow, and underflow.

If you know you’ll be using Nearest, consider using Float::cbrt_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::cbrt_round_ref instead. If both of these things are true, consider using the Cbrt implementation instead.

§Worst-case complexity

$T(n) = O(n^{3/2} \log n \log\log n)$

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the cube root is not exact.

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

let (cbrt, o) = Float::from(2.0).cbrt_prec_round_ref(10, Floor);
assert_eq!(cbrt.to_string(), "1.2598");
assert_eq!(o, Less);

let (cbrt, o) = Float::from(2.0).cbrt_prec_round_ref(10, Ceiling);
assert_eq!(cbrt.to_string(), "1.2617");
assert_eq!(o, Greater);
Source

pub fn cbrt_prec_ref(&self, prec: u64) -> (Self, Ordering)

Takes the cube root of a Float, rounding the result to the specified precision and to the nearest value. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cube root is less than, equal to, or greater than the exact cube root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See the Float::cbrt_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::cbrt_prec_round_ref instead.

§Worst-case complexity

$T(n) = O(n^{3/2} \log n \log\log n)$

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (cbrt, o) = Float::from(2.0).cbrt_prec_ref(10);
assert_eq!(cbrt.to_string(), "1.2598");
assert_eq!(o, Less);
Source

pub fn cbrt_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Takes the cube root of a Float, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cube root is less than, equal to, or greater than the exact cube root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See the Float::cbrt_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::cbrt_prec_round_ref instead.

§Worst-case complexity

$T(n) = O(n^{3/2} \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 rm is Exact but the cube root is not exact.

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

let (cbrt, o) = (&Float::from(-8.0)).cbrt_round_ref(Floor);
assert_eq!(cbrt.to_string(), "-2.0");
assert_eq!(o, Equal);
Source

pub fn compound_prec_round_ref( &self, n: i64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the compound function $(1+x)^n$ of a Float $x$ and an i64 $n$, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = (1+x)^n+\varepsilon. $$

  • If $(1+x)^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $(1+x)^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 (1+x)^n\rfloor-p+1}$.
  • If $(1+x)^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 (1+x)^n\rfloor-p}$.

See the Float::compound_prec_round documentation for information on special cases, overflow, and underflow.

If you know you’ll be using Nearest, consider using Float::compound_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::compound_round_ref instead. If both of these things are true, consider using the Compound trait instead.

§Worst-case complexity

$T(n, m) = O(mn^{3/2} \log n \log\log n)$

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = Float::from(3).compound_prec_round_ref(2, 10, Nearest);
assert_eq!(c.to_string(), "16.000");
assert_eq!(o, Equal);

let (c, o) = Float::TWO.compound_prec_round_ref(-2, 10, Ceiling);
assert_eq!(c.to_string(), "0.11121");
assert_eq!(o, Greater);
Source

pub fn compound_prec_ref(&self, n: i64, prec: u64) -> (Self, Ordering)

Computes the compound function $(1+x)^n$ of a Float $x$ and an i64 $n$, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the compound value is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See the Float::compound_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::compound_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using the Compound trait instead.

§Worst-case complexity

$T(n, m) = O(mn^{3/2} \log n \log\log n)$

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = Float::from(3).compound_prec_ref(2, 10);
assert_eq!(c.to_string(), "16.000");
assert_eq!(o, Equal);

let (c, o) = Float::TWO.compound_prec_ref(-2, 10);
assert_eq!(c.to_string(), "0.11108");
assert_eq!(o, Less);
Source

pub fn compound_round_ref(&self, n: i64, rm: RoundingMode) -> (Self, Ordering)

Computes the compound function $(1+x)^n$ of a Float $x$ and an i64 $n$, rounding the result to the precision of the input with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::compound_prec_round documentation for information on special cases, overflow, and underflow.

If you know you’ll be using Nearest, consider using the Compound trait instead. If you want to specify an output precision, consider using Float::compound_prec_round_ref instead.

§Worst-case complexity

$T(n, m) = O(mn^{3/2} \log n \log\log n)$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $m$ is the number of significant bits of the exponent n.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (c, o) = Float::from(1.5).compound_round_ref(2, Floor);
assert_eq!(c.to_string(), "6.0");
assert_eq!(o, Less);

let (c, o) = Float::from(1.5).compound_round_ref(2, Ceiling);
assert_eq!(c.to_string(), "8.0");
assert_eq!(o, Greater);
Source

pub fn cos_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cos x$, the cosine of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \cos x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cos x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=1.0$

Overflow and underflow:

  • Since $|\cos x|\leq 1$, the result never overflows.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you know you’ll be using Nearest, consider using Float::cos_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::cos_round_ref instead. If both of these things are true, consider using (&Float).cos() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, cos therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cosine of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "0.531");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "0.562");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "0.531");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "0.54030228");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "0.54030323");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "0.54030228");
assert_eq!(o, Less);
Source

pub fn cos_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\cos x$, the cosine of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the cosine is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \cos x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=1.0$

Overflow and underflow:

  • Since $|\cos x|\leq 1$, the result never overflows.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you want to use a rounding mode other than Nearest, consider using Float::cos_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).cos() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, cos therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_ref(5);
assert_eq!(c.to_string(), "0.531");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_prec_ref(20);
assert_eq!(c.to_string(), "0.54030228");
assert_eq!(o, Less);
Source

pub fn cos_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\cos x$, the cosine of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \cos x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cos x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=1.0$

Overflow and underflow:

  • Since $|\cos x|\leq 1$, the result never overflows.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you want to specify an output precision, consider using Float::cos_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).cos() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, cos therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cosine of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_round_ref(Floor);
assert_eq!(c.to_string(), "0.54030230586813971740093660744256");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.54030230586813971740093660744335");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cos_round_ref(Nearest);
assert_eq!(c.to_string(), "0.54030230586813971740093660744335");
assert_eq!(o, Greater);
Source

pub fn cos_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cos(2\pi x/u)$, the cosine of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,u,p,m) = \cos(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, $u\neq 0$, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos(2\pi x/u)|\rfloor-p+1}$.
  • If $x$ is finite, $u\neq 0$, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cos(2\pi x/u)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},u,p,m)=\text{NaN}$
  • $f(\pm\infty,u,p,m)=\text{NaN}$
  • $f(x,0,p,m)=\text{NaN}$
  • $f(\pm0.0,u,p,m)=1.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $1$ or $-1$; if it is an odd multiple of $1/4$, the result is exactly $0.0$ (always positive, following IEEE 754-2019’s cosPi); and if it is an odd multiple of $1/6$ or $1/3$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 5, 8, 10, or 12, the result is $\pm\varphi/2$, $\pm(\varphi-1)/2$, $\pm\sqrt2/2$, or $\pm\sqrt3/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a cosine, which is far faster.

Overflow and underflow:

  • Since $|\cos(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,u,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of an odd multiple of $1/4$ without being one, which takes more than $2^{30}$ bits of precision.

If you know you’ll be using Nearest, consider using Float::cos_with_period_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::cos_with_period_round_ref instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the cosine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision (which is the case unless $x/u$ is a multiple of $1/4$ or $1/6$, or $x$ is zero or not finite, or $u$ is zero).

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::ONE).cos_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o, Less);

let (c, o) = (&Float::ONE).cos_with_period_prec_round_ref(7, 10, Ceiling);
assert_eq!(c.to_string(), "0.62402");
assert_eq!(o, Greater);

let (c, o) = (&Float::ONE).cos_with_period_prec_round_ref(7, 10, Nearest);
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o, Less);

// a sixth of a turn is exact
let (c, o) = (&Float::from(60u32)).cos_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(c.to_string(), "0.50000");
assert_eq!(o, Equal);

// a quarter turn is exactly zero
let (c, o) = (&Float::from(90u32)).cos_with_period_prec_round_ref(360, 10, Nearest);
assert_eq!(c.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn cos_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\cos(2\pi x/u)$, the cosine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the cosine is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,u,p) = \cos(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $u\neq 0$, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos(2\pi x/u)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},u,p)=\text{NaN}$
  • $f(\pm\infty,u,p)=\text{NaN}$
  • $f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,u,p)=1.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $1$ or $-1$; if it is an odd multiple of $1/4$, the result is exactly $0.0$ (always positive, following IEEE 754-2019’s cosPi); and if it is an odd multiple of $1/6$ or $1/3$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 5, 8, 10, or 12, the result is $\pm\varphi/2$, $\pm(\varphi-1)/2$, $\pm\sqrt2/2$, or $\pm\sqrt3/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a cosine, which is far faster.

Overflow and underflow:

  • Since $|\cos(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of an odd multiple of $1/4$ without being one, which takes more than $2^{30}$ bits of precision.

If you want to use a rounding mode other than Nearest, consider using Float::cos_with_period_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using Float::cos_with_period_round_ref with Nearest instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the cosine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::ONE).cos_with_period_prec_ref(7, 10);
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o, Less);

let (c, o) = (&Float::ONE).cos_with_period_prec_ref(360, 53);
assert_eq!(c.to_string(), "0.99984769515639127");
assert_eq!(o, Greater);

// an eighth of a turn: sqrt(2)/2
let (c, o) = (&Float::ONE).cos_with_period_prec_ref(8, 10);
assert_eq!(c.to_string(), "0.70703");
assert_eq!(o, Less);
Source

pub fn cos_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cos(2\pi x/u)$, the cosine of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,u,m) = \cos(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, $u\neq 0$, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cos(2\pi x/u)|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite, $u\neq 0$, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cos(2\pi x/u)|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},u,m)=\text{NaN}$
  • $f(\pm\infty,u,m)=\text{NaN}$
  • $f(x,0,m)=\text{NaN}$
  • $f(\pm0.0,u,m)=1.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $1$ or $-1$; if it is an odd multiple of $1/4$, the result is exactly $0.0$ (always positive, following IEEE 754-2019’s cosPi); and if it is an odd multiple of $1/6$ or $1/3$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 5, 8, 10, or 12, the result is $\pm\varphi/2$, $\pm(\varphi-1)/2$, $\pm\sqrt2/2$, or $\pm\sqrt3/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a cosine, which is far faster.

Overflow and underflow:

  • Since $|\cos(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,u,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,u,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of an odd multiple of $1/4$ without being one, which takes more than $2^{30}$ bits of precision.

If you want to specify an output precision, consider using Float::cos_with_period_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using Float::cos_with_period_prec_ref with the input’s precision instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the cosine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision (which is the case unless $x/u$ is a multiple of $1/4$ or $1/6$, or $x$ is zero or not finite, or $u$ is zero).

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).cos_with_period_round_ref(7, Floor);
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).cos_with_period_round_ref(7, Ceiling);
assert_eq!(c.to_string(), "0.62402");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).cos_with_period_round_ref(7, Nearest);
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o, Less);
Source

pub fn cos_with_period_ref(&self, u: u64) -> Self

Computes $\cos(2\pi x/u)$, the cosine of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cosine is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::cos_with_period_prec_round for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::cos_with_period_round_ref instead. If you want to specify an output precision, consider using Float::cos_with_period_prec_ref. If you want both of these things, consider using Float::cos_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let c = (&Float::from_unsigned_prec(1u32, 10).0).cos_with_period_ref(7);
assert_eq!(c.to_string(), "0.62305");
Source

pub fn cos_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cos(\pi x)$, the cosine of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cos_with_period with a period of 2: see Float::cos_with_period_prec_round_ref for the error bounds, the special and closed-form cases (integers give $\pm1$, half-integers give $+0.0$, and multiples of $1/3$, $1/4$, $1/5$, $1/6$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (Float::from(0.1f64)).cos_pi_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "0.95020");
assert_eq!(o, Less);

let (c, o) = (Float::from(0.1f64)).cos_pi_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "0.95117");
assert_eq!(o, Greater);

// a half-turn is exactly -1
let (c, o) = (&Float::ONE).cos_pi_prec_round_ref(10, Exact);
assert_eq!(c.to_string(), "-1.0000");
assert_eq!(o, Equal);
Source

pub fn cos_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\cos(\pi x)$, the cosine of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cos_with_period with a period of 2: see Float::cos_with_period_prec_ref for the error bounds, the special and closed-form cases (integers give $\pm1$, half-integers give $+0.0$, and multiples of $1/3$, $1/4$, $1/5$, $1/6$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (Float::from(0.1f64)).cos_pi_prec_ref(10);
assert_eq!(c.to_string(), "0.95117");
assert_eq!(o, Greater);

let (c, o) = (Float::from(0.1f64)).cos_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.95105651629515353");
assert_eq!(o, Less);
Source

pub fn cos_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\cos(\pi x)$, the cosine of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosine is less than, equal to, or greater than the exact cosine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cos_with_period with a period of 2: see Float::cos_with_period_round_ref for the error bounds, the special and closed-form cases (integers give $\pm1$, half-integers give $+0.0$, and multiples of $1/3$, $1/4$, $1/5$, $1/6$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (c, o) = (Float::from(0.1f64)).cos_pi_round_ref(Floor);
assert_eq!(c.to_string(), "0.95105651629515342");
assert_eq!(o, Less);

let (c, o) = (Float::from(0.1f64)).cos_pi_round_ref(Nearest);
assert_eq!(c.to_string(), "0.95105651629515364");
assert_eq!(o, Greater);
Source

pub fn cos_pi_ref(&self) -> Self

Computes $\cos(\pi x)$, the cosine of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cosine is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is cos_with_period with a period of 2: see Float::cos_with_period for the error bounds, the special and closed-form cases (integers give $\pm1$, half-integers give $+0.0$, and multiples of $1/3$, $1/4$, $1/5$, $1/6$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::cos_pi_round_ref instead. If you want to specify an output precision, consider using Float::cos_pi_prec_ref. If you want both of these things, consider using Float::cos_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let c = (&Float::from(0.1f64)).cos_pi_ref();
assert_eq!(c.to_string(), "0.95105651629515364");
Source

pub fn cot_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cot x$, the cotangent of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \cot x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cot x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cot x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm\infty$

Overflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, and underflow an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, either of which takes more than $2^{30}$ bits of precision; overflow also occurs for an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you know you’ll be using Nearest, consider using Float::cot_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::cot_round_ref instead. If both of these things are true, consider using (&Float).cot() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived), and their quotient, cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, cot therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cotangent of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "0.625");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "0.656");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "0.656");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "0.64209175");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "0.64209270");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "0.64209270");
assert_eq!(o, Greater);
Source

pub fn cot_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\cot x$, the cotangent of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the cotangent is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \cot x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\cot x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=\pm\infty$

Overflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, and underflow an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, either of which takes more than $2^{30}$ bits of precision; overflow also occurs for an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you want to use a rounding mode other than Nearest, consider using Float::cot_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).cot() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived), and their quotient, cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, cot therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_ref(5);
assert_eq!(c.to_string(), "0.656");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_prec_ref(20);
assert_eq!(c.to_string(), "0.64209270");
assert_eq!(o, Greater);
Source

pub fn cot_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\cot x$, the cotangent of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \cot x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\cot x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\cot x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=\pm\infty$

Overflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, and underflow an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, either of which takes more than $2^{30}$ bits of precision; overflow also occurs for an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you want to specify an output precision, consider using Float::cot_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).cot() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, cot therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cotangent of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_round_ref(Floor);
assert_eq!(c.to_string(), "0.64209261593433070300641998659417");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.64209261593433070300641998659496");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).cot_round_ref(Nearest);
assert_eq!(c.to_string(), "0.64209261593433070300641998659417");
assert_eq!(o, Less);
Source

pub fn cot_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cot(2\pi x/u)$, the cotangent of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::cot_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.cot_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(t.to_string(), "0.79688");
assert_eq!(o, Less);
Source

pub fn cot_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\cot(2\pi x/u)$, the cotangent of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::cot_with_period_prec and Float::cot_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.cot_with_period_prec_ref(7, 10);
assert_eq!(t.to_string(), "0.79785");
assert_eq!(o, Greater);
Source

pub fn cot_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cot(2\pi x/u)$, the cotangent of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::cot_with_period_round and Float::cot_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (t, o) = Float::from_unsigned_prec(1u32, 10)
    .0
    .cot_with_period_round_ref(7, Floor);
assert_eq!(t.to_string(), "0.79688");
assert_eq!(o, Less);
Source

pub fn cot_with_period_ref(&self, u: u64) -> Self

Computes $\cot(2\pi x/u)$, the cotangent of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cotangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::cot_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::cot_with_period_round_ref instead. If you want to specify an output precision, consider using Float::cot_with_period_prec_ref. If you want both of these things, consider using Float::cot_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from_unsigned_prec(1u32, 10).0).cot_with_period_ref(7);
assert_eq!(t.to_string(), "0.79785");
Source

pub fn cot_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\cot(\pi x)$, the cotangent of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cot_with_period with a period of 2: see Float::cot_with_period_prec_round_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$, with the sign of $x$ at an even integer and the opposite at an odd one; half-integers give $\pm0.0$; odd multiples of $1/4$ give $\pm1$; odd multiples of $1/6$ give $\pm\sqrt3$; and multiples of $1/3$ that are not integers give $\pm\sqrt3/3$), overflow, underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).cot_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "3.0742");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).cot_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "3.0781");
assert_eq!(o, Greater);

// an integer is a pole
let (t, o) = (&Float::ONE).cot_pi_prec_round_ref(10, Exact);
assert_eq!(t.to_string(), "-Infinity");
assert_eq!(o, Equal);
Source

pub fn cot_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\cot(\pi x)$, the cotangent of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cot_with_period with a period of 2: see Float::cot_with_period_prec_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$, with the sign of $x$ at an even integer and the opposite at an odd one; half-integers give $\pm0.0$; odd multiples of $1/4$ give $\pm1$; odd multiples of $1/6$ give $\pm\sqrt3$; and multiples of $1/3$ that are not integers give $\pm\sqrt3/3$), overflow, underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).cot_pi_prec_ref(10);
assert_eq!(t.to_string(), "3.0781");
assert_eq!(o, Greater);

let (t, o) = (Float::from(0.1f64)).cot_pi_prec_ref(53);
assert_eq!(t.to_string(), "3.0776835371752531");
assert_eq!(o, Less);
Source

pub fn cot_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\cot(\pi x)$, the cotangent of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cotangent is less than, equal to, or greater than the exact cotangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is cot_with_period with a period of 2: see Float::cot_with_period_round_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$, with the sign of $x$ at an even integer and the opposite at an odd one; half-integers give $\pm0.0$; odd multiples of $1/4$ give $\pm1$; odd multiples of $1/6$ give $\pm\sqrt3$; and multiples of $1/3$ that are not integers give $\pm\sqrt3/3$), overflow, underflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (t, o) = (Float::from(0.1f64)).cot_pi_round_ref(Floor);
assert_eq!(t.to_string(), "3.0776835371752531");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).cot_pi_round_ref(Nearest);
assert_eq!(t.to_string(), "3.0776835371752531");
assert_eq!(o, Less);
Source

pub fn cot_pi_ref(&self) -> Self

Computes $\cot(\pi x)$, the cotangent of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cotangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is cot_with_period with a period of 2: see Float::cot_with_period for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$, with the sign of $x$ at an even integer and the opposite at an odd one; half-integers give $\pm0.0$; odd multiples of $1/4$ give $\pm1$; odd multiples of $1/6$ give $\pm\sqrt3$; and multiples of $1/3$ that are not integers give $\pm\sqrt3/3$), overflow, underflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::cot_pi_round_ref instead. If you want to specify an output precision, consider using Float::cot_pi_prec_ref. If you want both of these things, consider using Float::cot_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from(0.1f64)).cot_pi_ref();
assert_eq!(t.to_string(), "3.0776835371752531");
Source

pub fn csc_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\csc x$, the cosecant of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \csc x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm\infty$

Overflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you know you’ll be using Nearest, consider using Float::csc_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::csc_round_ref instead. If both of these things are true, consider using (&Float).csc() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the cosine at working precision $n$, summed by binary splitting of the Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, csc therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cosecant of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "1.19");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "1.25");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "1.19");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "1.1883945");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "1.1883965");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "1.1883945");
assert_eq!(o, Less);
Source

pub fn csc_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\csc x$, the cosecant of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the cosecant is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \csc x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=\pm\infty$

Overflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.

Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you want to use a rounding mode other than Nearest, consider using Float::csc_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).csc() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the cosine at working precision $n$, summed by binary splitting of the Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, csc therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_ref(5);
assert_eq!(c.to_string(), "1.19");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_ref(20);
assert_eq!(c.to_string(), "1.1883945");
assert_eq!(o, Less);
Source

pub fn csc_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\csc x$, the cosecant of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \csc x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=\pm\infty$

Overflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond the largest finite Float.

If you want to specify an output precision, consider using Float::csc_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).csc() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, csc therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the cosecant of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Floor);
assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Ceiling);
assert_eq!(c.to_string(), "1.1883951057781212162615994523760");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Nearest);
assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
assert_eq!(o, Less);
Source

pub fn csc_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\csc(2\pi x/u)$, the cosecant of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::csc_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.csc_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(t.to_string(), "1.2773");
assert_eq!(o, Less);
Source

pub fn csc_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\csc(2\pi x/u)$, the cosecant of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::csc_with_period_prec and Float::csc_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.csc_with_period_prec_ref(7, 10);
assert_eq!(t.to_string(), "1.2793");
assert_eq!(o, Greater);
Source

pub fn csc_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\csc(2\pi x/u)$, the cosecant of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::csc_with_period_round and Float::csc_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (t, o) = Float::from_unsigned_prec(1u32, 10)
    .0
    .csc_with_period_round_ref(7, Floor);
assert_eq!(t.to_string(), "1.2773");
assert_eq!(o, Less);
Source

pub fn csc_with_period_ref(&self, u: u64) -> Self

Computes $\csc(2\pi x/u)$, the cosecant of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cosecant is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::csc_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::csc_with_period_round_ref instead. If you want to specify an output precision, consider using Float::csc_with_period_prec_ref. If you want both of these things, consider using Float::csc_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from_unsigned_prec(1u32, 10).0).csc_with_period_ref(7);
assert_eq!(t.to_string(), "1.2793");
Source

pub fn csc_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\csc(\pi x)$, the cosecant of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is csc_with_period with a period of 2: see Float::csc_with_period_prec_round_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).csc_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "3.2344");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).csc_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "3.2383");
assert_eq!(o, Greater);

// an integer is a pole
let (t, o) = (&Float::ONE).csc_pi_prec_round_ref(10, Exact);
assert_eq!(t.to_string(), "Infinity");
assert_eq!(o, Equal);
Source

pub fn csc_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\csc(\pi x)$, the cosecant of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is csc_with_period with a period of 2: see Float::csc_with_period_prec_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).csc_pi_prec_ref(10);
assert_eq!(t.to_string(), "3.2344");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).csc_pi_prec_ref(53);
assert_eq!(t.to_string(), "3.2360679774997894");
assert_eq!(o, Less);
Source

pub fn csc_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\csc(\pi x)$, the cosecant of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is csc_with_period with a period of 2: see Float::csc_with_period_round_ref for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (t, o) = (Float::from(0.1f64)).csc_pi_round_ref(Floor);
assert_eq!(t.to_string(), "3.2360679774997889");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).csc_pi_round_ref(Nearest);
assert_eq!(t.to_string(), "3.2360679774997898");
assert_eq!(o, Greater);
Source

pub fn csc_pi_ref(&self) -> Self

Computes $\csc(\pi x)$, the cosecant of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the cosecant is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is csc_with_period with a period of 2: see Float::csc_with_period for the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::csc_pi_round_ref instead. If you want to specify an output precision, consider using Float::csc_pi_prec_ref. If you want both of these things, consider using Float::csc_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from(0.1f64)).csc_pi_ref();
assert_eq!(t.to_string(), "3.2360679774997898");
Source

pub fn div_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Divides two Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,p,m)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,p,m)=\infty$ if $x>0.0$
  • $f(x,0.0,p,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p,m)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,p,m)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,p,m)=-\infty$ if $x>0.0$
  • $f(x,-0.0,p,m)=\infty$ if $x<0.0$
  • $f(0.0,x,p,m)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,p,m)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p,m)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,p,m)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::div_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::div_round_ref_val instead. If both of these things are true, consider using / instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact division.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 5, Floor);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(quotient.to_string(), "1.19");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 5, Nearest);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 20, Floor);
assert_eq!(quotient.to_string(), "1.1557255");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 20, Ceiling);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);
Source

pub fn div_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Divides two Floats, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,p,m)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,p,m)=\infty$ if $x>0.0$
  • $f(x,0.0,p,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p,m)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,p,m)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,p,m)=-\infty$ if $x>0.0$
  • $f(x,-0.0,p,m)=\infty$ if $x<0.0$
  • $f(0.0,x,p,m)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,p,m)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p,m)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,p,m)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::div_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::div_round_ref_ref instead. If both of these things are true, consider using / instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact division.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(quotient.to_string(), "1.19");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 5, Nearest);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 20, Floor);
assert_eq!(quotient.to_string(), "1.1557255");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 20, Ceiling);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);
Source

pub fn div_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Divides two Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the quotient is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,p)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,p)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,p)=\infty$ if $x>0.0$
  • $f(x,0.0,p)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,p)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,p)=-\infty$ if $x>0.0$
  • $f(x,-0.0,p)=\infty$ if $x<0.0$
  • $f(0.0,x,p)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,p)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,p)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::div_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using / instead.

§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(), prec).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_prec_ref_val(Float::from(E), 5);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_ref_val(Float::from(E), 20);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);
Source

pub fn div_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Divides two Floats, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the quotient is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,p)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,p)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,p)=\infty$ if $x>0.0$
  • $f(x,0.0,p)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,p)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,p)=-\infty$ if $x>0.0$
  • $f(x,-0.0,p)=\infty$ if $x<0.0$
  • $f(0.0,x,p)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,p)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,p)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::div_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using / instead.

§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(), prec).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_prec_ref_ref(&Float::from(E), 5);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_prec_ref_ref(&Float::from(E), 20);
assert_eq!(quotient.to_string(), "1.1557274");
assert_eq!(o, Greater);
Source

pub fn div_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Divides two Floats, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,m)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,m)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,m)=\infty$ if $x>0.0$
  • $f(x,0.0,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,m)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,m)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,m)=-\infty$ if $x>0.0$
  • $f(x,-0.0,m)=\infty$ if $x<0.0$
  • $f(0.0,x,m)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,m)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,m)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,m)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::div_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using / instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_round_ref_val(Float::from(E), Floor);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_round_ref_val(Float::from(E), Ceiling);
assert_eq!(quotient.to_string(), "1.1557273497909220");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_round_ref_val(Float::from(E), Nearest);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
Source

pub fn div_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Divides two Floats, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm\infty,p,m)=f(\pm0.0,\pm0.0,p,m) = \text{NaN}$
  • $f(\infty,x,m)=\infty$ if $0.0<x<\infty$
  • $f(\infty,x,m)=-\infty$ if $-\infty<x<0.0$
  • $f(x,0.0,m)=\infty$ if $x>0.0$
  • $f(x,0.0,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,m)=-\infty$ if $0.0<x<\infty$
  • $f(-\infty,x,m)=\infty$ if $-\infty<x<0.0$
  • $f(x,-0.0,m)=-\infty$ if $x>0.0$
  • $f(x,-0.0,m)=\infty$ if $x<0.0$
  • $f(0.0,x,m)=0.0$ if $x$ is not NaN and $x>0.0$
  • $f(0.0,x,m)=-0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,\infty,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,\infty,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,m)=-0.0$ if $x$ is not NaN and $x>0.0$
  • $f(-0.0,x,m)=0.0$ if $x$ is not NaN and $x<0.0$
  • $f(x,-\infty,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(x,-\infty,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::div_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using / instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_round_ref_ref(&Float::from(E), Floor);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(quotient.to_string(), "1.1557273497909220");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
Source

pub fn div_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(\pm\infty,0,p,m)=f(\pm0.0,0,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x\geq 0$
  • $f(\infty,x,p,m)=-\infty$ if $x<0$
  • $f(-\infty,x,p,m)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,p,m)=\infty$ if $x<0$
  • $f(0.0,x,p,m)=0.0$ if $x>0$
  • $f(0.0,x,p,m)=-0.0$ if $x<0$
  • $f(-0.0,x,p,m)=-0.0$ if $x>0$
  • $f(-0.0,x,p,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::div_rational_prec_ref_val instead. If you know that your target precision is the precision of the Float input, consider using Float::div_rational_round_ref_val instead. If both of these things are true, consider using / instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact division.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(quotient.to_string(), "9.00");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(quotient.to_string(), "9.50");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(quotient.to_string(), "9.50");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(quotient.to_string(), "9.4247742");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(quotient.to_string(), "9.4247894");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(quotient.to_string(), "9.4247742");
assert_eq!(o, Less);
Source

pub fn div_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(\pm\infty,0,p,m)=f(\pm0.0,0,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x\geq 0$
  • $f(\infty,x,p,m)=-\infty$ if $x<0$
  • $f(-\infty,x,p,m)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,p,m)=\infty$ if $x<0$
  • $f(0.0,x,p,m)=0.0$ if $x>0$
  • $f(0.0,x,p,m)=-0.0$ if $x<0$
  • $f(-0.0,x,p,m)=-0.0$ if $x>0$
  • $f(-0.0,x,p,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::div_rational_prec_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using Float::div_rational_round_ref_ref instead. If both of these things are true, consider using / instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact division.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(quotient.to_string(), "9.00");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(quotient.to_string(), "9.50");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(quotient.to_string(), "9.50");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(quotient.to_string(), "9.4247742");
assert_eq!(o, Less);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(quotient.to_string(), "9.4247894");
assert_eq!(o, Greater);

let (quotient, o) = Float::from(PI).div_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(quotient.to_string(), "9.4247742");
assert_eq!(o, Less);
Source

pub fn div_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the quotient is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(\pm\infty,0,p)=f(\pm0.0,0,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x\geq 0$
  • $f(\infty,x,p)=-\infty$ if $x<0$
  • $f(-\infty,x,p)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,p)=\infty$ if $x<0$
  • $f(0.0,x,p)=0.0$ if $x>0$
  • $f(0.0,x,p)=-0.0$ if $x<0$
  • $f(-0.0,x,p)=-0.0$ if $x>0$
  • $f(-0.0,x,p)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::div_rational_prec_round_ref_val instead. If you know that your target precision is the precision of the Float input, consider using / instead.

§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(), prec).

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) = Float::from(PI).div_rational_prec_ref_val(Rational::exact_from(1.5), 5);
assert_eq!(quotient.to_string(), "2.12");
assert_eq!(o, Greater);

let (quotient, o) =
    Float::from(PI).div_rational_prec_ref_val(Rational::exact_from(1.5), 20);
assert_eq!(quotient.to_string(), "2.0943947");
assert_eq!(o, Less);
Source

pub fn div_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the quotient is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(\pm\infty,0,p)=f(\pm0.0,0,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x\geq 0$
  • $f(\infty,x,p)=-\infty$ if $x<0$
  • $f(-\infty,x,p)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,p)=\infty$ if $x<0$
  • $f(0.0,x,p)=0.0$ if $x>0$
  • $f(0.0,x,p)=-0.0$ if $x<0$
  • $f(-0.0,x,p)=-0.0$ if $x>0$
  • $f(-0.0,x,p)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::div_rational_prec_round_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using / instead.

§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(), prec).

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) =
    Float::from(PI).div_rational_prec_ref_ref(&Rational::exact_from(1.5), 5);
assert_eq!(quotient.to_string(), "2.12");
assert_eq!(o, Greater);

let (quotient, o) =
    Float::from(PI).div_rational_prec_ref_ref(&Rational::exact_from(1.5), 20);
assert_eq!(quotient.to_string(), "2.0943947");
assert_eq!(o, Less);
Source

pub fn div_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=f(\pm\infty,0,m)=f(\pm0.0,0,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x\geq 0$
  • $f(\infty,x,m)=-\infty$ if $x<0$
  • $f(-\infty,x,m)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,m)=\infty$ if $x<0$
  • $f(0.0,x,m)=0.0$ if $x>0$
  • $f(0.0,x,m)=-0.0$ if $x<0$
  • $f(-0.0,x,m)=-0.0$ if $x>0$
  • $f(-0.0,x,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::div_rational_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using / instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(quotient.to_string(), "9.4247779607693758");
assert_eq!(o, Less);

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(quotient.to_string(), "9.4247779607693900");
assert_eq!(o, Greater);

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(quotient.to_string(), "9.4247779607693758");
assert_eq!(o, Less);
Source

pub fn div_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Divides a Float by a Rational, rounding the result with the specified rounding mode. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded quotient is less than, equal to, or greater than the exact quotient. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x/y+\varepsilon. $$

  • If $x/y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x/y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x/y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=f(\pm\infty,0,m)=f(\pm0.0,0,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x\geq 0$
  • $f(\infty,x,m)=-\infty$ if $x<0$
  • $f(-\infty,x,m)=-\infty$ if $x\geq 0$
  • $f(-\infty,x,m)=\infty$ if $x<0$
  • $f(0.0,x,m)=0.0$ if $x>0$
  • $f(0.0,x,m)=-0.0$ if $x<0$
  • $f(-0.0,x,m)=-0.0$ if $x>0$
  • $f(-0.0,x,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::div_rational_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using / instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(quotient.to_string(), "9.4247779607693758");
assert_eq!(o, Less);

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(quotient.to_string(), "9.4247779607693900");
assert_eq!(o, Greater);

let (quotient, o) =
    Float::from(PI).div_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(quotient.to_string(), "9.4247779607693758");
assert_eq!(o, Less);
Source

pub fn exp_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $e^x$, the exponential of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded exponential is less than, equal to, or greater than the exact exponential. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = e^x+\varepsilon. $$

  • If $e^x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 e^x\rfloor-p+1}$.
  • If $e^x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 e^x\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=0.0$
  • $f(\pm0.0,p,m)=1.0$

Overflow and underflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,p,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $f(x,p,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $f(x,p,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::exp_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::exp_round_ref instead. If both of these things are true, consider using (&Float).exp() instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(5, Floor);
assert_eq!(e.to_string(), "2.62");
assert_eq!(o, Less);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(5, Ceiling);
assert_eq!(e.to_string(), "2.75");
assert_eq!(o, Greater);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(5, Nearest);
assert_eq!(e.to_string(), "2.75");
assert_eq!(o, Greater);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(20, Floor);
assert_eq!(e.to_string(), "2.7182808");
assert_eq!(o, Less);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(20, Ceiling);
assert_eq!(e.to_string(), "2.7182846");
assert_eq!(o, Greater);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_prec_round_ref(20, Nearest);
assert_eq!(e.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn exp_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $e^x$, the exponential of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded exponential is less than, equal to, or greater than the exact exponential. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the exponential is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = e^x+\varepsilon. $$

  • If $e^x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 e^x\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=0.0$
  • $f(\pm0.0,p)=1.0$

Overflow and underflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::exp_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).exp() instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (e, o) = Float::from_unsigned_prec(1u32, 100).0.exp_prec_ref(5);
assert_eq!(e.to_string(), "2.75");
assert_eq!(o, Greater);

let (e, o) = Float::from_unsigned_prec(1u32, 100).0.exp_prec_ref(20);
assert_eq!(e.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn exp_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $e^x$, the exponential of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded exponential is less than, equal to, or greater than the exact exponential. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = e^x+\varepsilon. $$

  • If $e^x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 e^x\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $e^x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 e^x\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=0.0$
  • $f(\pm0.0,m)=1.0$

See the Float::exp_prec_round documentation for information on overflow and underflow.

If you want to specify an output precision, consider using Float::exp_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).exp() instead.

§Worst-case complexity

$T(n) = O(n^{3/2} \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 rm is Exact but the result cannot be represented exactly with the input precision.

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

let (e, o) = Float::from_unsigned_prec(1u32, 100).0.exp_round_ref(Floor);
assert_eq!(e.to_string(), "2.7182818284590452353602874713512");
assert_eq!(o, Less);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_round_ref(Ceiling);
assert_eq!(e.to_string(), "2.7182818284590452353602874713544");
assert_eq!(o, Greater);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_round_ref(Nearest);
assert_eq!(e.to_string(), "2.7182818284590452353602874713512");
assert_eq!(o, Less);
Source

pub fn exp_x_minus_1_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $e^x-1$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = e^x-1+\varepsilon. $$

  • If $e^x-1$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x-1$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |e^x-1|\rfloor-p+1}$.
  • If $e^x-1$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |e^x-1|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=-1$
  • $f(\pm0.0,p,m)=\pm0.0$

Overflow and underflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$ and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$ and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$ and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<-2^{-2^{30}-1}$ and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

(A positive result never underflows: $e^x-1>x$ for positive $x$.)

If you know you’ll be using Nearest, consider using Float::exp_x_minus_1_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::exp_x_minus_1_round_ref instead. If both of these things are true, consider using (&Float).exp_x_minus_1() instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision. (The result cannot be represented exactly whenever the input is finite and nonzero.)

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

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_x_minus_1_prec_round_ref(20, Floor);
assert_eq!(e.to_string(), "1.7182808");
assert_eq!(o, Less);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_x_minus_1_prec_round_ref(20, Ceiling);
assert_eq!(e.to_string(), "1.7182827");
assert_eq!(o, Greater);
Source

pub fn exp_x_minus_1_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $e^x-1$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the result is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = e^x-1+\varepsilon. $$

  • If $e^x-1$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x-1$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |e^x-1|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=-1$
  • $f(\pm0.0,p)=\pm0.0$

Overflow and underflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

(A positive result never underflows: $e^x-1>x$ for positive $x$.)

If you want to use a rounding mode other than Nearest, consider using Float::exp_x_minus_1_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).exp_x_minus_1() instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_x_minus_1_prec_ref(20);
assert_eq!(e.to_string(), "1.7182827");
assert_eq!(o, Greater);
Source

pub fn exp_x_minus_1_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $e^x-1$, where $x$ is a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = e^x-1+\varepsilon. $$

  • If $e^x-1$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $e^x-1$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |e^x-1|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $e^x-1$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |e^x-1|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=-1$
  • $f(\pm0.0,m)=\pm0.0$

Overflow and underflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$ and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$ and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$ and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<-2^{-2^{30}-1}$ and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

(A positive result never underflows: $e^x-1>x$ for positive $x$.)

If you want to specify an output precision, consider using Float::exp_x_minus_1_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).exp_x_minus_1() instead.

§Worst-case complexity

$T(n) = O(n^{3/2} \log n \log\log n)$

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision. (The result cannot be represented exactly whenever the input is finite and nonzero.)

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

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_x_minus_1_round_ref(Floor);
assert_eq!(e.to_string(), "1.7182818284590452353602874713512");
assert_eq!(o, Less);

let (e, o) = Float::from_unsigned_prec(1u32, 100)
    .0
    .exp_x_minus_1_round_ref(Ceiling);
assert_eq!(e.to_string(), "1.7182818284590452353602874713528");
assert_eq!(o, Greater);
Source

pub fn fractional_part_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Returns the fractional part of a Float, rounded to the specified precision with the specified rounding mode, along with an Ordering comparing the result to the exact fraction. The Float is taken by reference.

The fractional part has the same sign as the input, and the rounding mode rounds the exact fraction rather than shaping it: for a negative input, Floor rounds the (negative) fraction downward. The fractional part of an integer or an infinity is a zero with the input’s sign, and NaN propagates. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the fraction is not exactly representable at the target precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
assert_eq!(
    x.fractional_part_prec_round_ref(10, Floor),
    (Float::from(0.25f64), Equal)
);
// the fraction of a negative value is negative, and Floor rounds it downward
let y = Float::from(-3.375f64);
assert_eq!(
    y.fractional_part_prec_round(1, Floor),
    (Float::from(-0.5f64), Less)
);
Source

pub fn fractional_part_prec_ref(&self, prec: u64) -> (Self, Ordering)

Returns the fractional part of a Float, rounded to the specified precision with the Nearest rounding mode, along with an Ordering comparing the result to the exact fraction. The Float is taken by reference.

The fractional part has the same sign as the input, and the rounding mode rounds the exact fraction rather than shaping it: for a negative input, Floor rounds the (negative) fraction downward. The fractional part of an integer or an infinity is a zero with the input’s sign, and NaN propagates. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
assert_eq!(
    x.fractional_part_prec_ref(10),
    (Float::from(0.25f64), Equal)
);
Source

pub fn fractional_part_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Returns the fractional part of a Float, rounded to the input’s precision with the specified rounding mode, along with an Ordering comparing the result to the exact fraction. The Float is taken by reference.

The fractional part has the same sign as the input, and the rounding mode rounds the exact fraction rather than shaping it: for a negative input, Floor rounds the (negative) fraction downward. The fractional part of an integer or an infinity is a zero with the input’s sign, and NaN propagates. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§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 rm is Exact and the fraction is not exactly representable at the input’s precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
assert_eq!(
    x.fractional_part_round_ref(Ceiling),
    (Float::from(0.25f64), Equal)
);
Source

pub fn fractional_part_ref(&self) -> (Self, Ordering)

Returns the fractional part of a Float, rounded to the input’s precision with the Nearest rounding mode, along with an Ordering comparing the result to the exact fraction. The Float is taken by reference.

The fractional part has the same sign as the input, and the rounding mode rounds the exact fraction rather than shaping it: for a negative input, Floor rounds the (negative) fraction downward. The fractional part of an integer or an infinity is a zero with the input’s sign, and NaN propagates. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§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

Never panics.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
assert_eq!(x.fractional_part_ref(), (Float::from(0.25f64), Equal));
Source

pub fn integer_and_fractional_parts_prec_round_ref( &self, iprec: u64, fprec: u64, rm: RoundingMode, ) -> ((Self, Ordering), (Self, Ordering))

Returns the integral and fractional parts of a Float, rounded to the specified precisions with the specified rounding mode. The Float is taken by reference.

The integral part is the input truncated toward zero and then correctly rounded to its target precision, as by Float::round_to_integer_then_prec_round with Down; the fractional part is as by Float::fractional_part_prec_round. Both parts have the input’s sign; for an infinity, the integral part is the infinity and the fractional part a signed zero, and NaN propagates to both parts. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if iprec or fprec is zero, or if rm is Exact and either part is not exactly representable at its target precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(-3.25f64);
let ((i, io), (f, fo)) = x.integer_and_fractional_parts_prec_round_ref(10, 10, Nearest);
assert_eq!(i, Float::from(-3i32));
assert_eq!(f, Float::from(-0.25f64));
assert_eq!((io, fo), (Equal, Equal));
Source

pub fn integer_and_fractional_parts_prec_ref( &self, iprec: u64, fprec: u64, ) -> ((Self, Ordering), (Self, Ordering))

Returns the integral and fractional parts of a Float, rounded to the specified precisions with the Nearest rounding mode. The Float is taken by reference.

The integral part is the input truncated toward zero and then correctly rounded to its target precision, as by Float::round_to_integer_then_prec_round with Down; the fractional part is as by Float::fractional_part_prec_round. Both parts have the input’s sign; for an infinity, the integral part is the infinity and the fractional part a signed zero, and NaN propagates to both parts. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if iprec or fprec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
let ((i, io), (f, fo)) = x.integer_and_fractional_parts_prec_ref(10, 10);
assert_eq!(i, Float::from(3u32));
assert_eq!(f, Float::from(0.25f64));
assert_eq!((io, fo), (Equal, Equal));
Source

pub fn integer_and_fractional_parts_round_ref( &self, rm: RoundingMode, ) -> ((Self, Ordering), (Self, Ordering))

Returns the integral and fractional parts of a Float, rounded to the input’s precision with the specified rounding mode. The Float is taken by reference.

The integral part is the input truncated toward zero and then correctly rounded to its target precision, as by Float::round_to_integer_then_prec_round with Down; the fractional part is as by Float::fractional_part_prec_round. Both parts have the input’s sign; for an infinity, the integral part is the infinity and the fractional part a signed zero, and NaN propagates to both parts. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§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 rm is Exact and the fraction is not exactly representable at the input’s precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
let ((i, io), (f, fo)) = x.integer_and_fractional_parts_round_ref(Floor);
assert_eq!(i, Float::from(3u32));
assert_eq!(f, Float::from(0.25f64));
assert_eq!((io, fo), (Equal, Equal));
Source

pub fn integer_and_fractional_parts_ref( &self, ) -> ((Self, Ordering), (Self, Ordering))

Returns the integral and fractional parts of a Float, rounded to the input’s precision with the Nearest rounding mode. The Float is taken by reference.

The integral part is the input truncated toward zero and then correctly rounded to its target precision, as by Float::round_to_integer_then_prec_round with Down; the fractional part is as by Float::fractional_part_prec_round. Both parts have the input’s sign; for an infinity, the integral part is the infinity and the fractional part a signed zero, and NaN propagates to both parts. The Orderings compare each result to its exact value; whenever a result equals its exact value, its Ordering is Equal.

§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

Never panics.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let x = Float::from(3.25f64);
let ((i, io), (f, fo)) = x.integer_and_fractional_parts_ref();
assert_eq!(i, Float::from(3u32));
assert_eq!(f, Float::from(0.25f64));
assert_eq!((io, fo), (Equal, Equal));
Source

pub fn hypot_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p+1}$.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$.

If the output has a precision, it is prec.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you know you’ll be using Nearest, consider using Float::hypot_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::hypot_round_ref_val instead. If both of these things are true, consider using Float::hypot instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact and the hypotenuse is not exactly representable with prec bits.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 5, Floor);
assert_eq!(hypot.to_string(), "2.12");
assert_eq!(o, Less);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 5, Ceiling);
assert_eq!(hypot.to_string(), "2.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 5, Nearest);
assert_eq!(hypot.to_string(), "2.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 20, Floor);
assert_eq!(hypot.to_string(), "2.2360649");
assert_eq!(o, Less);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 20, Ceiling);
assert_eq!(hypot.to_string(), "2.2360687");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_val(Float::TWO, 20, Nearest);
assert_eq!(hypot.to_string(), "2.2360687");
assert_eq!(o, Greater);
Source

pub fn hypot_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p+1}$.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$.

If the output has a precision, it is prec.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you know you’ll be using Nearest, consider using Float::hypot_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::hypot_round_ref_ref instead. If both of these things are true, consider using Float::hypot instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact and the hypotenuse is not exactly representable with prec bits.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 5, Floor);
assert_eq!(hypot.to_string(), "2.12");
assert_eq!(o, Less);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 5, Ceiling);
assert_eq!(hypot.to_string(), "2.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 5, Nearest);
assert_eq!(hypot.to_string(), "2.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 20, Floor);
assert_eq!(hypot.to_string(), "2.2360649");
assert_eq!(o, Less);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 20, Ceiling);
assert_eq!(hypot.to_string(), "2.2360687");
assert_eq!(o, Greater);

let (hypot, o) = Float::ONE.hypot_prec_round_ref_ref(&Float::TWO, 20, Nearest);
assert_eq!(hypot.to_string(), "2.2360687");
assert_eq!(o, Greater);
Source

pub fn hypot_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the hypotenuse is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$.

If the output has a precision, it is prec.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::hypot_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::hypot instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::from(PI).hypot_prec_ref_val(Float::from(E), 5);
assert_eq!(hypot.to_string(), "4.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::from(PI).hypot_prec_ref_val(Float::from(E), 20);
assert_eq!(hypot.to_string(), "4.1543579");
assert_eq!(o, Greater);
Source

pub fn hypot_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the hypotenuse is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$.

If the output has a precision, it is prec.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::hypot_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::hypot instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::from(PI).hypot_prec_ref_ref(&Float::from(E), 5);
assert_eq!(hypot.to_string(), "4.25");
assert_eq!(o, Greater);

let (hypot, o) = Float::from(PI).hypot_prec_ref_ref(&Float::from(E), 20);
assert_eq!(hypot.to_string(), "4.1543579");
assert_eq!(o, Greater);
Source

pub fn hypot_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$, where $p$ is the maximum precision of the inputs.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::hypot_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using Float::hypot instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the hypotenuse is not exactly representable with the maximum of the precisions of the inputs.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::from(PI).hypot_round_ref_val(Float::from(E), Floor);
assert_eq!(hypot.to_string(), "4.1543544023133130");
assert_eq!(o, Less);

let (hypot, o) = Float::from(PI).hypot_round_ref_val(Float::from(E), Ceiling);
assert_eq!(hypot.to_string(), "4.1543544023133139");
assert_eq!(o, Greater);

let (hypot, o) = Float::from(PI).hypot_round_ref_val(Float::from(E), Nearest);
assert_eq!(hypot.to_string(), "4.1543544023133130");
assert_eq!(o, Less);
Source

pub fn hypot_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the hypotenuse of two Floats, $\sqrt{x^2+y^2}$, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded hypotenuse is less than, equal to, or greater than the exact hypotenuse. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = \sqrt{x^2+y^2}+\varepsilon. $$

  • If $\sqrt{x^2+y^2}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $\sqrt{x^2+y^2}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x^2+y^2}\rfloor-p}$, where $p$ is the maximum precision of the inputs.

See the Float::hypot_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::hypot_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using Float::hypot instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the hypotenuse is not exactly representable with the maximum of the precisions of the inputs.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (hypot, o) = Float::from(PI).hypot_round_ref_ref(&Float::from(E), Floor);
assert_eq!(hypot.to_string(), "4.1543544023133130");
assert_eq!(o, Less);

let (hypot, o) = Float::from(PI).hypot_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(hypot.to_string(), "4.1543544023133139");
assert_eq!(o, Greater);

let (hypot, o) = Float::from(PI).hypot_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(hypot.to_string(), "4.1543544023133130");
assert_eq!(o, Less);
Source

pub fn ln_prec_round_ref(&self, prec: u64, rm: RoundingMode) -> (Self, Ordering)

Computes the natural logarithm of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded logarithm is less than, equal to, or greater than the exact logarithm. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The logarithm of any nonzero negative number is NaN.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \ln{x}+\varepsilon. $$

  • If $\ln{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |ln{x}|\rfloor-p+1}$.
  • If $\ln{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |ln{x}|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=-\infty$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::ln_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::ln_round_ref instead. If both of these things are true, consider using (&Float).ln()instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(5, Floor);
assert_eq!(ln.to_string(), "2.25");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(5, Ceiling);
assert_eq!(ln.to_string(), "2.38");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(5, Nearest);
assert_eq!(ln.to_string(), "2.25");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(20, Floor);
assert_eq!(ln.to_string(), "2.3025818");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(20, Ceiling);
assert_eq!(ln.to_string(), "2.3025856");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_prec_round_ref(20, Nearest);
assert_eq!(ln.to_string(), "2.3025856");
assert_eq!(o, Greater);
Source

pub fn ln_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes the natural logarithm of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded logarithm is less than, equal to, or greater than the exact logarithm. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The logarithm of any nonzero negative number is NaN.

If the logarithm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \ln{x}+\varepsilon. $$

  • If $\ln{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln{x}$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \ln{x}\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=-\infty$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::ln_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).ln() instead.

§Worst-case complexity

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

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (ln, o) = Float::from_unsigned_prec(10u32, 100).0.ln_prec_ref(5);
assert_eq!(ln.to_string(), "2.25");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100).0.ln_prec_ref(20);
assert_eq!(ln.to_string(), "2.3025856");
assert_eq!(o, Greater);
Source

pub fn ln_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes the natural logarithm of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded logarithm is less than, equal to, or greater than the exact logarithm. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The logarithm of any nonzero negative number is NaN.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \ln{x}+\varepsilon. $$

  • If $\ln{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |ln{x}|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\ln{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |ln{x}|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=-\infty$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::ln_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).ln() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (ln, o) = Float::from_unsigned_prec(10u32, 100).0.ln_round_ref(Floor);
assert_eq!(ln.to_string(), "2.3025850929940456840179914546838");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_round_ref(Ceiling);
assert_eq!(ln.to_string(), "2.3025850929940456840179914546870");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_round_ref(Nearest);
assert_eq!(ln.to_string(), "2.3025850929940456840179914546838");
assert_eq!(o, Less);
Source

pub fn ln_1_plus_x_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\ln(1+x)$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\ln(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \ln(1+x)+\varepsilon. $$

  • If $\ln(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\ln(1+x)|\rfloor-p+1}$.
  • If $\ln(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\ln(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm0.0$
  • $f(-1,p,m)=-\infty$
  • $f(x,p,m)=\text{NaN}$ for $x<-1$

This function cannot overflow, but it can underflow:

  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling, Up, or Nearest, $2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::ln_1_plus_x_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::ln_1_plus_x_round_ref instead. If both of these things are true, consider using (&Float).ln_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision. (The result cannot be represented exactly whenever the input is finite, nonzero, and greater than $-1$.)

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

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(5, Floor);
assert_eq!(ln.to_string(), "2.38");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(5, Ceiling);
assert_eq!(ln.to_string(), "2.50");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(5, Nearest);
assert_eq!(ln.to_string(), "2.38");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(20, Floor);
assert_eq!(ln.to_string(), "2.3978920");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(20, Ceiling);
assert_eq!(ln.to_string(), "2.3978958");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_round_ref(20, Nearest);
assert_eq!(ln.to_string(), "2.3978958");
assert_eq!(o, Greater);
Source

pub fn ln_1_plus_x_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\ln(1+x)$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\ln(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

If the result is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \ln(1+x)+\varepsilon. $$

  • If $\ln(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln(1+x)$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\ln(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=\pm0.0$
  • $f(-1,p)=-\infty$
  • $f(x,p)=\text{NaN}$ for $x<-1$

This function cannot overflow, but it can underflow: if $0<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::ln_1_plus_x_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).ln_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_ref(5);
assert_eq!(ln.to_string(), "2.38");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_prec_ref(20);
assert_eq!(ln.to_string(), "2.3978958");
assert_eq!(o, Greater);

let (ln, o) = Float::ONE.ln_1_plus_x_prec_ref(20);
assert_eq!(ln.to_string(), "0.69314671");
assert_eq!(o, Less);
Source

pub fn ln_1_plus_x_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\ln(1+x)$, where $x$ is a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\ln(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \ln(1+x)+\varepsilon. $$

  • If $\ln(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\ln(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\ln(1+x)|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\ln(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\ln(1+x)|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=\pm0.0$
  • $f(-1,m)=-\infty$
  • $f(x,m)=\text{NaN}$ for $x<-1$

This function cannot overflow, but it can underflow:

  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling, Up, or Nearest, $2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ln_1_plus_x_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).ln_1_plus_x() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision. (The result cannot be represented exactly whenever the input is finite, nonzero, and greater than $-1$.)

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

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_round_ref(Floor);
assert_eq!(ln.to_string(), "2.3978952727983705440619435779621");
assert_eq!(o, Less);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_round_ref(Ceiling);
assert_eq!(ln.to_string(), "2.3978952727983705440619435779652");
assert_eq!(o, Greater);

let (ln, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .ln_1_plus_x_round_ref(Nearest);
assert_eq!(ln.to_string(), "2.3978952727983705440619435779652");
assert_eq!(o, Greater);
Source

pub fn log_base_prec_round_ref( &self, base: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::log_base_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if base is less than 2, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (log, o) = Float::from(1000).log_base_prec_round_ref(10, 10, Nearest);
assert_eq!(log.to_string(), "3.0000");
assert_eq!(o, Equal);
Source

pub fn log_base_prec_ref(&self, base: u64, prec: u64) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero or if base is less than 2.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from(50).log_base_prec_ref(10, 10);
assert_eq!(log.to_string(), "1.6992");
assert_eq!(o, Greater);
Source

pub fn log_base_round_ref( &self, base: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_prec_round for details and special 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 the precision of the input.

§Panics

Panics if base is less than 2, or if rm is Exact but the result cannot be represented exactly with the input’s precision.

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

let (log, o) = Float::from(81).log_base_round_ref(3, Ceiling);
assert_eq!(log.to_string(), "4.000");
assert_eq!(o, Equal);
Source

pub fn log_base_10_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{10} x$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::log_base_10_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (log, o) = Float::from(1000).log_base_10_prec_round_ref(10, Nearest);
assert_eq!(log.to_string(), "3.0000");
assert_eq!(o, Equal);
Source

pub fn log_base_10_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\log_{10} x$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_10_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from(50).log_base_10_prec_ref(10);
assert_eq!(log.to_string(), "1.6992");
assert_eq!(o, Greater);
Source

pub fn log_base_10_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\log_{10} x$, where $x$ is a Float, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_10_prec_round for details and special 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 the precision of the input.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input’s precision.

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

let (log, o) = Float::from(100).log_base_10_round_ref(Ceiling);
assert_eq!(log.to_string(), "2.00");
assert_eq!(o, Equal);
Source

pub fn log_base_10_1_plus_x_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{10}(1+x)$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::log_base_10_1_plus_x_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(99)).log_base_10_1_plus_x_prec_round_ref(10, Exact);
assert_eq!(log.to_string(), "2.0000"); // log_10(100) = 2
assert_eq!(o, Equal);

let (log, o) = (&Float::ONE).log_base_10_1_plus_x_prec_round_ref(20, Floor);
assert_eq!(log.to_string(), "0.30102968"); // log_10(2), rounded down
assert_eq!(o, Less);
Source

pub fn log_base_10_1_plus_x_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\log_{10}(1+x)$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_10_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(99)).log_base_10_1_plus_x_prec_ref(10);
assert_eq!(log.to_string(), "2.0000"); // log_10(100) = 2
assert_eq!(o, Equal);

let (log, o) = (&Float::from(7)).log_base_10_1_plus_x_prec_ref(30);
assert_eq!(log.to_string(), "0.90308998711"); // log_10(8)
assert_eq!(o, Greater);
Source

pub fn log_base_10_1_plus_x_round_ref( &self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{10}(1+x)$, where $x$ is a Float, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_10_1_plus_x_prec_round for details and special 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 the precision of the input.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input’s precision.

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

let (log, o) = (&Float::from(99)).log_base_10_1_plus_x_round_ref(Exact);
assert_eq!(log.to_string(), "2.000"); // log_10(100) = 2
assert_eq!(o, Equal);

let (log, o) = (&Float::from(9)).log_base_10_1_plus_x_round_ref(Exact);
assert_eq!(log.to_string(), "1.00"); // log_10(10) = 1
assert_eq!(o, Equal);
Source

pub fn log_base_1_plus_x_prec_round_ref( &self, base: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::log_base_1_plus_x_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if base is less than 2, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from(8).log_base_1_plus_x_prec_round_ref(3, 10, Exact);
assert_eq!(log.to_string(), "2.0000"); // log_3(9) = 2
assert_eq!(o, Equal);

let (log, o) = Float::ONE.log_base_1_plus_x_prec_round_ref(3, 20, Floor);
assert_eq!(log.to_string(), "0.63092899"); // log_3(2), rounded down
assert_eq!(o, Less);
Source

pub fn log_base_1_plus_x_prec_ref( &self, base: u64, prec: u64, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero or if base is less than 2.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::TWO).log_base_1_plus_x_prec_ref(9, 10);
assert_eq!(log.to_string(), "0.50000"); // log_9(3) = 1/2
assert_eq!(o, Equal);

let (log, o) = (&Float::from(7)).log_base_1_plus_x_prec_ref(5, 30);
assert_eq!(log.to_string(), "1.2920296751"); // log_5(8)
assert_eq!(o, Greater);
Source

pub fn log_base_1_plus_x_round_ref( &self, base: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a u64 greater than 1, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_1_plus_x_prec_round for details and special 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 the precision of the input.

§Panics

Panics if base is less than 2, or if rm is Exact but the result cannot be represented exactly with the input’s precision.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(8)).log_base_1_plus_x_round_ref(3, Exact);
assert_eq!(log.to_string(), "2.0"); // log_3(9) = 2
assert_eq!(o, Equal);

let (log, o) = (&Float::TWO).log_base_1_plus_x_round_ref(9, Exact);
assert_eq!(log.to_string(), "0.50"); // log_9(3) = 1/2
assert_eq!(o, Equal);
Source

pub fn log_base_2_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_2 x$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-2 logarithm of any nonzero negative number is NaN.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \log_2 x+\varepsilon. $$

  • If $\log_2 x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2 x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_2 x|\rfloor-p+1}$.
  • If $\log_2 x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2 x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=-\infty$
  • $f(1.0,p,m)=0.0$, and the result is exact
  • $f(2^k,p,m)=k$, rounded to precision $p$; the result is exact if and only if $k$ is representable with precision $p$
  • $f(x,p,m)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::log_base_2_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::log_base_2_round_ref instead. If both of these things are true, consider using (&Float).log_base_2() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision. (The result is exactly representable if and only if the input is NaN, infinite, zero, equal to 1, or a power of 2 whose base-2 logarithm is representable with the given precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(5, Floor);
assert_eq!(log.to_string(), "3.25");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(5, Ceiling);
assert_eq!(log.to_string(), "3.38");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(5, Nearest);
assert_eq!(log.to_string(), "3.38");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(20, Floor);
assert_eq!(log.to_string(), "3.3219261");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(20, Ceiling);
assert_eq!(log.to_string(), "3.3219299");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_round_ref(20, Nearest);
assert_eq!(log.to_string(), "3.3219299");
assert_eq!(o, Greater);
Source

pub fn log_base_2_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\log_2 x$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-2 logarithm of any nonzero negative number is NaN.

If the logarithm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \log_2 x+\varepsilon. $$

  • If $\log_2 x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2 x$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2 x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=-\infty$
  • $f(1.0,p)=0.0$, and the result is exact
  • $f(2^k,p)=k$, rounded to precision $p$; the result is exact if and only if $k$ is representable with precision $p$
  • $f(x,p)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::log_base_2_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).log_base_2() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_ref(5);
assert_eq!(log.to_string(), "3.38");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_prec_ref(20);
assert_eq!(log.to_string(), "3.3219299");
assert_eq!(o, Greater);
Source

pub fn log_base_2_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\log_2 x$, where $x$ is a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-2 logarithm of any nonzero negative number is NaN.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \log_2 x+\varepsilon. $$

  • If $\log_2 x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2 x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_2 x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\log_2 x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2 x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=-\infty$
  • $f(1.0,m)=0.0$, and the result is exact
  • $f(2^k,m)=k$, rounded to the precision of the input; the result is exact if and only if $k$ is representable with that precision
  • $f(x,m)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::log_base_2_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).log_base_2() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision. (The result is exactly representable if and only if the input is NaN, infinite, zero, equal to 1, or a power of 2 whose base-2 logarithm is representable with the input precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_round_ref(Floor);
assert_eq!(log.to_string(), "3.3219280948873623478703194294867");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_round_ref(Ceiling);
assert_eq!(log.to_string(), "3.3219280948873623478703194294898");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_round_ref(Nearest);
assert_eq!(log.to_string(), "3.3219280948873623478703194294898");
assert_eq!(o, Greater);
Source

pub fn log_base_2_1_plus_x_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_2(1+x)$, where $x$ is a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_2(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \log_2(1+x)+\varepsilon. $$

  • If $\log_2(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_2(1+x)|\rfloor-p+1}$.
  • If $\log_2(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm0.0$
  • $f(-1,p,m)=-\infty$
  • $f(x,p,m)=\text{NaN}$ for $x<-1$
  • $f(x,p,m)=k$ when $1+x=2^k$. The result is the integer $k$ (subject to rounding at precision $p$, and exact iff $k$ is representable with precision $p$). This covers $x$ a power of 2 minus 1 (e.g. $x=1\to1$, $x=3\to2$) and negative $x$ such as $x=-1/2\to-1$ and $x=-3/4\to-2$.

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::log_base_2_1_plus_x_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::log_base_2_1_plus_x_round_ref instead. If both of these things are true, consider using (&Float).log_base_2_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision. (The result is exactly representable only when the input is NaN, infinite, zero, $-1$, less than $-1$, or a value for which $1+x$ is a power of 2 whose base-2 logarithm is representable with the given precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(5, Floor);
assert_eq!(log.to_string(), "3.38");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(5, Ceiling);
assert_eq!(log.to_string(), "3.50");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(5, Nearest);
assert_eq!(log.to_string(), "3.50");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(20, Floor);
assert_eq!(log.to_string(), "3.4594307");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(20, Ceiling);
assert_eq!(log.to_string(), "3.4594345");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_round_ref(20, Nearest);
assert_eq!(log.to_string(), "3.4594307");
assert_eq!(o, Less);
Source

pub fn log_base_2_1_plus_x_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\log_2(1+x)$, where $x$ is a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_2(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

If the result is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \log_2(1+x)+\varepsilon. $$

  • If $\log_2(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2(1+x)$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=\pm0.0$
  • $f(-1,p)=-\infty$
  • $f(x,p)=\text{NaN}$ for $x<-1$
  • $f(x,p)=k$ when $1+x=2^k$. The result is the integer $k$ (subject to rounding at precision $p$, and exact iff $k$ is representable with precision $p$). This covers $x$ a power of 2 minus 1 (e.g. $x=1\to1$, $x=3\to2$) and negative $x$ such as $x=-1/2\to-1$ and $x=-3/4\to-2$.

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::log_base_2_1_plus_x_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).log_base_2_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_ref(5);
assert_eq!(log.to_string(), "3.50");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_prec_ref(20);
assert_eq!(log.to_string(), "3.4594307");
assert_eq!(o, Less);

let (log, o) = Float::ONE.log_base_2_1_plus_x_prec_ref(20);
assert_eq!(log.to_string(), "1.0000000");
assert_eq!(o, Equal);
Source

pub fn log_base_2_1_plus_x_round_ref( &self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_2(1+x)$, where $x$ is a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_2(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \log_2(1+x)+\varepsilon. $$

  • If $\log_2(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_2(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_2(1+x)|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\log_2(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_2(1+x)|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=\pm0.0$
  • $f(-1,m)=-\infty$
  • $f(x,m)=\text{NaN}$ for $x<-1$
  • $f(x,m)=k$ when $1+x=2^k$. The result is the integer $k$ (subject to rounding at the input precision $p$, and exact iff $k$ is representable with precision $p$). This covers $x$ a power of 2 minus 1 (e.g. $x=1\to1$, $x=3\to2$) and negative $x$ such as $x=-1/2\to-1$ and $x=-3/4\to-2$.

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::log_base_2_1_plus_x_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).log_base_2_1_plus_x() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision. (The result is exactly representable only when the input is NaN, infinite, zero, $-1$, less than $-1$, or a value for which $1+x$ is a power of 2 whose base-2 logarithm is representable with the given precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_round_ref(Floor);
assert_eq!(log.to_string(), "3.4594316186372972561993630467247");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_round_ref(Ceiling);
assert_eq!(log.to_string(), "3.4594316186372972561993630467279");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_2_1_plus_x_round_ref(Nearest);
assert_eq!(log.to_string(), "3.4594316186372972561993630467247");
assert_eq!(o, Less);
Source

pub fn log_base_float_base_prec_round_ref( &self, base: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ and the base $b$ are both Floats, rounding the result to the specified precision and with the specified rounding mode. Both are taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_float_base_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(8)).log_base_float_base_prec_round_ref(&Float::TWO, 10, Exact);
assert_eq!(log.to_string(), "3.0000"); // log_2(8) = 3
assert_eq!(o, Equal);

let (log, o) = (&Float::TWO).log_base_float_base_prec_round_ref(&Float::from(4), 10, Exact);
assert_eq!(log.to_string(), "0.50000"); // log_4(2) = 1/2
assert_eq!(o, Equal);
Source

pub fn log_base_float_base_prec_ref( &self, base: &Self, prec: u64, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ and the base $b$ are both Floats, rounding the result to the nearest value of the specified precision. Both are taken by reference. An Ordering is also returned.

See Float::log_base_float_base_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(8)).log_base_float_base_prec_ref(&Float::from(4), 10);
assert_eq!(log.to_string(), "1.5000"); // log_4(8) = 3/2
assert_eq!(o, Equal);
Source

pub fn log_base_float_base_round_ref( &self, base: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ and the base $b$ are both Floats, rounding the result to the precision of the input and with the specified rounding mode. Both are taken by reference. An Ordering is also returned.

See Float::log_base_float_base_prec_round for details and special cases.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is base.significant_bits().

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input’s precision.

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

let (log, o) = (&Float::from(81)).log_base_float_base_round_ref(&Float::from(3), Exact);
assert_eq!(log.to_string(), "4.000"); // log_3(81) = 4
assert_eq!(o, Equal);
Source

pub fn log_base_float_base_1_plus_x_prec_round_ref( &self, base: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ and the base $b$ are both Floats, rounding the result to the specified precision and with the specified rounding mode. Both are taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_float_base_1_plus_x_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(7);
let (log, o) = x.log_base_float_base_1_plus_x_prec_round_ref(&Float::TWO, 10, Exact);
assert_eq!(log.to_string(), "3.0000"); // log_2(1 + 7) = log_2(8) = 3
assert_eq!(o, Equal);

let x = Float::ONE;
let (log, o) = x.log_base_float_base_1_plus_x_prec_round_ref(&Float::from(3), 20, Floor);
assert_eq!(log.to_string(), "0.63092899"); // log_3(2), rounded down
assert_eq!(o, Less);
Source

pub fn log_base_float_base_1_plus_x_prec_ref( &self, base: &Self, prec: u64, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ and the base $b$ are both Floats, rounding the result to the nearest value of the specified precision. Both are taken by reference. An Ordering is also returned.

See Float::log_base_float_base_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(8)).log_base_float_base_1_plus_x_prec_ref(&Float::from(3), 10);
assert_eq!(log.to_string(), "2.0000"); // log_3(1 + 8) = log_3(9) = 2
assert_eq!(o, Equal);
Source

pub fn log_base_float_base_1_plus_x_round_ref( &self, base: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ and the base $b$ are both Floats, rounding the result to the precision of the input and with the specified rounding mode. Both are taken by reference. An Ordering is also returned.

See Float::log_base_float_base_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is base.significant_bits().

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input’s precision.

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

let (log, o) =
    (&Float::from(8)).log_base_float_base_1_plus_x_round_ref(&Float::from(3), Exact);
assert_eq!(log.to_string(), "2.0"); // log_3(1 + 8) = log_3(9) = 2
assert_eq!(o, Equal);
Source

pub fn log_base_power_of_2_prec_round_ref( &self, pow: i64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{2^k} x$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result to the specified precision and with the specified rounding mode. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-$2^k$ logarithm of any nonzero negative number is NaN.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \log_{2^k} x+\varepsilon. $$

  • If $\log_{2^k} x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k} x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_{2^k} x|\rfloor-p+1}$.
  • If $\log_{2^k} x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k} x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=\infty$ if $k>0$, and $-\infty$ if $k<0$
  • $f(-\infty,k,p,m)=\text{NaN}$
  • $f(\pm0.0,k,p,m)=-\infty$ if $k>0$, and $\infty$ if $k<0$
  • $f(1.0,k,p,m)=0.0$, and the result is exact
  • $f(2^m,k,p,m’)=m/k$, rounded to precision $p$; the result is exact if and only if $m/k$ is representable with precision $p$ (for example $\log_4 8=3/2$ is exact, but $\log_8 4=2/3$ is not)
  • $f(x,k,p,m)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::log_base_power_of_2_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::log_base_power_of_2_round_ref instead. If both of these things are true, consider using (&Float).log_base_power_of_2() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if pow is zero (the base $2^0=1$ has no logarithm), or if rm is Exact but the result cannot be represented exactly with the given precision. (The result is exactly representable if and only if the input is NaN, infinite, zero, equal to 1, or a power of 2 whose base-$2^k$ logarithm is representable with the given precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(2, 5, Floor);
assert_eq!(log.to_string(), "1.62");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(2, 5, Ceiling);
assert_eq!(log.to_string(), "1.69");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(2, 5, Nearest);
assert_eq!(log.to_string(), "1.69");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(3, 20, Floor);
assert_eq!(log.to_string(), "1.1073093");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(3, 20, Ceiling);
assert_eq!(log.to_string(), "1.1073112");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_round_ref(3, 20, Nearest);
assert_eq!(log.to_string(), "1.1073093");
assert_eq!(o, Less);

// log_4(8) = 3/2, exactly representable
let (log, o) = Float::from(8u32).log_base_power_of_2_prec_round_ref(2, 10, Nearest);
assert_eq!(log.to_string(), "1.5000");
assert_eq!(o, Equal);
Source

pub fn log_base_power_of_2_prec_ref( &self, pow: i64, prec: u64, ) -> (Self, Ordering)

Computes $\log_{2^k} x$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result to the nearest value of the specified precision. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-$2^k$ logarithm of any nonzero negative number is NaN.

If the logarithm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,k,p) = \log_{2^k} x+\varepsilon. $$

  • If $\log_{2^k} x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k} x$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k} x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p)=\text{NaN}$
  • $f(\infty,k,p)=\infty$ if $k>0$, and $-\infty$ if $k<0$
  • $f(-\infty,k,p)=\text{NaN}$
  • $f(\pm0.0,k,p)=-\infty$ if $k>0$, and $\infty$ if $k<0$
  • $f(1.0,k,p)=0.0$, and the result is exact
  • $f(2^m,k,p)=m/k$, rounded to precision $p$; the result is exact if and only if $m/k$ is representable with precision $p$ (for example $\log_4 8=3/2$ is exact, but $\log_8 4=2/3$ is not)
  • $f(x,k,p)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::log_base_power_of_2_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).log_base_power_of_2() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero or if pow is zero (the base $2^0=1$ has no logarithm).

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_ref(2, 5);
assert_eq!(log.to_string(), "1.69");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_prec_ref(3, 20);
assert_eq!(log.to_string(), "1.1073093");
assert_eq!(o, Less);
Source

pub fn log_base_power_of_2_round_ref( &self, pow: i64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{2^k} x$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result with the specified rounding mode. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The base-$2^k$ logarithm of any nonzero negative number is NaN.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,m) = \log_{2^k} x+\varepsilon. $$

  • If $\log_{2^k} x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k} x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_{2^k} x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\log_{2^k} x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k} x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},k,m)=\text{NaN}$
  • $f(\infty,k,m)=\infty$ if $k>0$, and $-\infty$ if $k<0$
  • $f(-\infty,k,m)=\text{NaN}$
  • $f(\pm0.0,k,m)=-\infty$ if $k>0$, and $\infty$ if $k<0$
  • $f(1.0,k,m)=0.0$, and the result is exact
  • $f(2^m,k,m’)=m/k$, rounded to the precision of the input; the result is exact if and only if $m/k$ is representable with that precision (for example $\log_4 8=3/2$ is exact, but $\log_8 4=2/3$ is not)
  • $f(x,k,m)=\text{NaN}$ for $x<0$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::log_base_power_of_2_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).log_base_power_of_2() instead.

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

§Panics

Panics if pow is zero (the base $2^0=1$ has no logarithm), or if rm is Exact but the result cannot be represented exactly with the input precision. (The result is exactly representable if and only if the input is NaN, infinite, zero, equal to 1, or a power of 2 whose base-$2^k$ logarithm is representable with the input precision.)

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_round_ref(2, Floor);
assert_eq!(log.to_string(), "1.6609640474436811739351597147433");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_round_ref(2, Ceiling);
assert_eq!(log.to_string(), "1.6609640474436811739351597147449");
assert_eq!(o, Greater);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_round_ref(2, Nearest);
assert_eq!(log.to_string(), "1.6609640474436811739351597147449");
assert_eq!(o, Greater);
Source

pub fn log_base_power_of_2_1_plus_x_prec_round_ref( &self, pow: i64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{2^k}(1+x)$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result to the specified precision and with the specified rounding mode. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_{2^k}(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \log_{2^k}(1+x)+\varepsilon. $$

  • If $\log_{2^k}(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k}(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_{2^k}(1+x)|\rfloor-p+1}$.
  • If $\log_{2^k}(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k}(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=\infty$ if $k>0$, and $-\infty$ if $k<0$
  • $f(-\infty,k,p,m)=\text{NaN}$
  • $f(0.0,k,p,m)=0.0$ if $k>0$, and $-0.0$ if $k<0$
  • $f(-0.0,k,p,m)=-0.0$ if $k>0$, and $0.0$ if $k<0$
  • $f(-1.0,k,p,m)=-\infty$ if $k>0$, and $\infty$ if $k<0$
  • $f(x,k,p,m)=\text{NaN}$ for $x<-1$
  • $f(x,k,p,m)=m/k$ when $1+x=2^m$, rounded to precision $p$; the result is exact if and only if $m/k$ is representable with precision $p$ (for example $\log_4 8=3/2$ when $x=7$ is exact, but $\log_8 4=2/3$ when $x=3$ is not)

This function cannot overflow, but it can underflow:

  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,k,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::log_base_power_of_2_1_plus_x_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::log_base_power_of_2_1_plus_x_round_ref instead. If both of these things are true, consider using (&Float).log_base_power_of_2_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if pow is zero (the base $2^0=1$ has no logarithm), or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_1_plus_x_prec_round_ref(2, 20, Floor);
assert_eq!(log.to_string(), "1.7297153");
assert_eq!(o, Less);

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_1_plus_x_prec_round_ref(2, 20, Ceiling);
assert_eq!(log.to_string(), "1.7297173");
assert_eq!(o, Greater);
Source

pub fn log_base_power_of_2_1_plus_x_prec_ref( &self, pow: i64, prec: u64, ) -> (Self, Ordering)

Computes $\log_{2^k}(1+x)$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result to the nearest value of the specified precision. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_{2^k}(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

If the logarithm is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,k,p) = \log_{2^k}(1+x)+\varepsilon. $$

  • If $\log_{2^k}(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k}(1+x)$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k}(1+x)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p)=\text{NaN}$
  • $f(\infty,k,p)=\infty$ if $k>0$, and $-\infty$ if $k<0$
  • $f(-\infty,k,p)=\text{NaN}$
  • $f(0.0,k,p)=0.0$ if $k>0$, and $-0.0$ if $k<0$
  • $f(-0.0,k,p)=-0.0$ if $k>0$, and $0.0$ if $k<0$
  • $f(-1.0,k,p)=-\infty$ if $k>0$, and $\infty$ if $k<0$
  • $f(x,k,p)=\text{NaN}$ for $x<-1$
  • $f(x,k,p)=m/k$ when $1+x=2^m$, rounded to precision $p$; the result is exact if and only if $m/k$ is representable with precision $p$

This function cannot overflow, but it can underflow:

  • If $0<f(x,k,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::log_base_power_of_2_1_plus_x_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).log_base_power_of_2_1_plus_x() instead.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero or if pow is zero (the base $2^0=1$ has no logarithm).

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_1_plus_x_prec_ref(2, 20);
assert_eq!(log.to_string(), "1.7297153");
assert_eq!(o, Less);
Source

pub fn log_base_power_of_2_1_plus_x_round_ref( &self, pow: i64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_{2^k}(1+x)$, where $x$ is a Float and the base is $2^k$ for some nonzero integer $k$, rounding the result with the specified rounding mode. The base’s exponent $k$ is pow, which may be negative. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$\log_{2^k}(1+x)$ is undefined for $x<-1$, so whenever $x<-1$, NaN is returned.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,m) = \log_{2^k}(1+x)+\varepsilon. $$

  • If $\log_{2^k}(1+x)$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\log_{2^k}(1+x)$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\log_{2^k}(1+x)|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\log_{2^k}(1+x)$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\log_{2^k}(1+x)|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

See the Float::log_base_power_of_2_1_plus_x_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::log_base_power_of_2_1_plus_x_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).log_base_power_of_2_1_plus_x() instead.

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

§Panics

Panics if pow is zero (the base $2^0=1$ has no logarithm), or if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (log, o) = Float::from_unsigned_prec(10u32, 100)
    .0
    .log_base_power_of_2_1_plus_x_round_ref(2, Floor);
assert_eq!(log.to_string(), "1.7297158093186486280996815233624");
assert_eq!(o, Less);
Source

pub fn log_base_rational_base_prec_round_ref( &self, base: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the specified precision and with the specified rounding mode. The Float and the base are both taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_rational_base_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if base is less than or equal to 1, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (log, o) =
    (&Float::from(8)).log_base_rational_base_prec_round_ref(&Rational::TWO, 10, Exact);
assert_eq!(log.to_string(), "3.0000"); // log_2(8) = 3
assert_eq!(o, Equal);

let (log, o) =
    (&Float::TWO).log_base_rational_base_prec_round_ref(&Rational::from(4), 10, Exact);
assert_eq!(log.to_string(), "0.50000"); // log_4(2) = 1/2
assert_eq!(o, Equal);
Source

pub fn log_base_rational_base_prec_ref( &self, base: &Rational, prec: u64, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the nearest value of the specified precision. The Float and the base are both taken by reference. An Ordering is also returned.

See Float::log_base_rational_base_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

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

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (log, o) = (&Float::from(8)).log_base_rational_base_prec_ref(&Rational::TWO, 10);
assert_eq!(log.to_string(), "3.0000"); // log_2(8) = 3
assert_eq!(o, Equal);

let (log, o) = (&Float::TWO).log_base_rational_base_prec_ref(&Rational::from(4), 10);
assert_eq!(log.to_string(), "0.50000"); // log_4(2) = 1/2
assert_eq!(o, Equal);
Source

pub fn log_base_rational_base_round_ref( &self, base: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b x$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the precision of the input and with the specified rounding mode. The Float and the base are both taken by reference. An Ordering is also returned.

See Float::log_base_rational_base_prec_round for details and special cases.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is base.significant_bits().

§Panics

Panics if base is less than or equal to 1, or if rm is Exact but the result cannot be represented exactly with the input’s precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (log, o) =
    (&Float::from(81)).log_base_rational_base_round_ref(&Rational::from(3), Exact);
assert_eq!(log.to_string(), "4.000"); // log_3(81) = 4
assert_eq!(o, Equal);

let (log, o) =
    (&Float::from(9)).log_base_rational_base_round_ref(&Rational::from(3), Exact);
assert_eq!(log.to_string(), "2.00"); // log_3(9) = 2
assert_eq!(o, Equal);
Source

pub fn log_base_rational_base_1_plus_x_prec_round_ref( &self, base: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the specified precision and with the specified rounding mode. The Float and the base are both taken by reference. An Ordering is also returned, indicating whether the rounded value is less than, equal to, or greater than the exact value.

See Float::log_base_rational_base_1_plus_x_prec_round for details, special cases, and a description of the rounding behavior.

§Worst-case complexity

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

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

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

§Panics

Panics if prec is zero, if base is less than or equal to 1, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (log, o) = (&Float::from(8)).log_base_rational_base_1_plus_x_prec_round_ref(
    &Rational::from(3),
    10,
    Exact,
);
assert_eq!(log.to_string(), "2.0000"); // log_3(1 + 8) = log_3(9) = 2
assert_eq!(o, Equal);

let (log, o) = (&Float::ONE).log_base_rational_base_1_plus_x_prec_round_ref(
    &Rational::from(3),
    20,
    Floor,
);
assert_eq!(log.to_string(), "0.63092899"); // log_3(2), rounded down
assert_eq!(o, Less);
Source

pub fn log_base_rational_base_1_plus_x_prec_ref( &self, base: &Rational, prec: u64, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the nearest value of the specified precision. The Float and the base are both taken by reference. An Ordering is also returned.

See Float::log_base_rational_base_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

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

§Panics

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

§Examples
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (log, o) =
    (&Float::from(8)).log_base_rational_base_1_plus_x_prec_ref(&Rational::from(3), 10);
assert_eq!(log.to_string(), "2.0000"); // log_3(1 + 8) = log_3(9) = 2
assert_eq!(o, Equal);
Source

pub fn log_base_rational_base_1_plus_x_round_ref( &self, base: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\log_b(1+x)$, where $x$ is a Float and $b$ is a Rational greater than 1, rounding the result to the precision of the input and with the specified rounding mode. The Float and the base are both taken by reference. An Ordering is also returned.

See Float::log_base_rational_base_1_plus_x_prec_round for details and special cases.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is base.significant_bits().

§Panics

Panics if base is less than or equal to 1, or if rm is Exact but the result cannot be represented exactly with the input’s precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (log, o) =
    (&Float::from(8)).log_base_rational_base_1_plus_x_round_ref(&Rational::from(3), Exact);
assert_eq!(log.to_string(), "2.0"); // log_3(1 + 8) = log_3(9) = 2
assert_eq!(o, Equal);
Source

pub fn mul_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies two Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm0.0,p,m)=f(\pm0.0,\pm\infty,p,m) = \text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\infty$ if $x>0.0$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=-\infty$ if $x>0.0$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=\infty$ if $x<0.0$
  • $f(0.0,x,p,m)=f(x,0.0,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,p,m)=f(x,0.0,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p,m)=f(x,-0.0,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,p,m)=f(x,-0.0,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::mul_round_ref_val instead. If both of these things are true, consider using * instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but prec is too small for an exact multiplication.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 5, Floor);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(product.to_string(), "9.00");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 5, Nearest);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 20, Floor);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 20, Ceiling);
assert_eq!(product.to_string(), "8.5397491");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);
Source

pub fn mul_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies two Floats, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\pm\infty,\pm0.0,p,m)=f(\pm0.0,\pm\infty,p,m) = \text{NaN}$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=\infty$ if $x>0.0$
  • $f(\infty,x,p,m)=f(x,\infty,p,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=-\infty$ if $x>0.0$
  • $f(-\infty,x,p,m)=f(x,-\infty,p,m)=\infty$ if $x<0.0$
  • $f(0.0,x,p,m)=f(x,0.0,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,p,m)=f(x,0.0,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p,m)=f(x,-0.0,p,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,p,m)=f(x,-0.0,p,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::mul_round_ref_ref instead. If both of these things are true, consider using * instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but prec is too small for an exact multiplication.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(product.to_string(), "9.00");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 5, Nearest);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 20, Floor);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 20, Ceiling);
assert_eq!(product.to_string(), "8.5397491");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);
Source

pub fn mul_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Multiplies two Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the product is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\pm\infty,\pm0.0,p)=f(\pm0.0,\pm\infty,p) = \text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\infty$ if $x>0.0$
  • $f(\infty,x,p)=f(x,\infty,p)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p)=f(x,-\infty,p)=-\infty$ if $x>0.0$
  • $f(-\infty,x,p)=f(x,-\infty,p)=\infty$ if $x<0.0$
  • $f(0.0,x,p)=f(x,0.0,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,p)=f(x,0.0,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p)=f(x,-0.0,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,p)=f(x,-0.0,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using * instead.

§Worst-case complexity

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

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

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

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_prec_ref_val(Float::from(E), 5);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_ref_val(Float::from(E), 20);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);
Source

pub fn mul_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Multiplies two Floats, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the product is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\pm\infty,\pm0.0,p)=f(\pm0.0,\pm\infty,p) = \text{NaN}$
  • $f(\infty,x,p)=f(x,\infty,p)=\infty$ if $x>0.0$
  • $f(\infty,x,p)=f(x,\infty,p)=-\infty$ if $x<0.0$
  • $f(-\infty,x,p)=f(x,-\infty,p)=-\infty$ if $x>0.0$
  • $f(-\infty,x,p)=f(x,-\infty,p)=\infty$ if $x<0.0$
  • $f(0.0,x,p)=f(x,0.0,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,p)=f(x,0.0,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,p)=f(x,-0.0,p)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,p)=f(x,-0.0,p)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using * instead.

§Worst-case complexity

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

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

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

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_prec_ref_ref(&Float::from(E), 5);
assert_eq!(product.to_string(), "8.50");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_prec_ref_ref(&Float::from(E), 20);
assert_eq!(product.to_string(), "8.5397339");
assert_eq!(o, Less);
Source

pub fn mul_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies two Floats, rounding the result with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\pm\infty,\pm0.0,m)=f(\pm0.0,\pm\infty,m) = \text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\infty$ if $x>0.0$
  • $f(\infty,x,m)=f(x,\infty,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,m)=f(x,-\infty,m)=-\infty$ if $x>0.0$
  • $f(-\infty,x,m)=f(x,-\infty,m)=\infty$ if $x<0.0$
  • $f(0.0,x,m)=f(x,0.0,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,m)=f(x,0.0,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,m)=f(x,-0.0,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,m)=f(x,-0.0,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using * instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_round_ref_val(Float::from(E), Floor);
assert_eq!(product.to_string(), "8.5397342226735660");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_round_ref_val(Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.5397342226735677");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_round_ref_val(Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.5397342226735660");
assert_eq!(o, Less);
Source

pub fn mul_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies two Floats, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\pm\infty,\pm0.0,m)=f(\pm0.0,\pm\infty,m) = \text{NaN}$
  • $f(\infty,x,m)=f(x,\infty,m)=\infty$ if $x>0.0$
  • $f(\infty,x,m)=f(x,\infty,m)=-\infty$ if $x<0.0$
  • $f(-\infty,x,m)=f(x,-\infty,m)=-\infty$ if $x>0.0$
  • $f(-\infty,x,m)=f(x,-\infty,m)=\infty$ if $x<0.0$
  • $f(0.0,x,m)=f(x,0.0,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(0.0,x,m)=f(x,0.0,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
  • $f(-0.0,x,m)=f(x,-0.0,m)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
  • $f(-0.0,x,m)=f(x,-0.0,m)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using * instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_round_ref_ref(&Float::from(E), Floor);
assert_eq!(product.to_string(), "8.5397342226735660");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.5397342226735677");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.5397342226735660");
assert_eq!(o, Less);
Source

pub fn mul_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x>0$
  • $f(\infty,x,p,m)=-\infty$ if $x<0$
  • $f(-\infty,x,p,m)=-\infty$ if $x>0$
  • $f(-\infty,x,p,m)=\infty$ if $x<0$
  • $f(0.0,x,p,m)=0.0$ if $x\geq0$
  • $f(0.0,x,p,m)=-0.0$ if $x<0$
  • $f(-0.0,x,p,m)=-0.0$ if $x\geq0$
  • $f(-0.0,x,p,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_rational_prec_ref_val instead. If you know that your target precision is the precision of the Float input, consider using Float::mul_rational_round_ref_val instead. If both of these things are true, consider using * instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact multiplication.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(product.to_string(), "1.00");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(product.to_string(), "1.06");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(product.to_string(), "1.06");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(product.to_string(), "1.0471973");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(product.to_string(), "1.0471992");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(product.to_string(), "1.0471973");
assert_eq!(o, Less);
Source

pub fn mul_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x>0$
  • $f(\infty,x,p,m)=-\infty$ if $x<0$
  • $f(-\infty,x,p,m)=-\infty$ if $x>0$
  • $f(-\infty,x,p,m)=\infty$ if $x<0$
  • $f(0.0,x,p,m)=0.0$ if $x\geq0$
  • $f(0.0,x,p,m)=-0.0$ if $x<0$
  • $f(-0.0,x,p,m)=-0.0$ if $x\geq0$
  • $f(-0.0,x,p,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_rational_prec_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using Float::mul_rational_round_ref_ref instead. If both of these things are true, consider using * instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact multiplication.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(product.to_string(), "1.00");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(product.to_string(), "1.06");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(product.to_string(), "1.06");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(product.to_string(), "1.0471973");
assert_eq!(o, Less);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(product.to_string(), "1.0471992");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(product.to_string(), "1.0471973");
assert_eq!(o, Less);
Source

pub fn mul_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the product is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x>0$
  • $f(\infty,x,p)=-\infty$ if $x<0$
  • $f(-\infty,x,p)=-\infty$ if $x>0$
  • $f(-\infty,x,p)=\infty$ if $x<0$
  • $f(0.0,x,p)=0.0$ if $x\geq0$
  • $f(0.0,x,p)=-0.0$ if $x<0$
  • $f(-0.0,x,p)=-0.0$ if $x\geq0$
  • $f(-0.0,x,p)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_rational_prec_round_ref_val instead. If you know that your target precision is the precision of the Float input, consider using * instead.

§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(), prec).

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_rational_prec_ref_val(Rational::exact_from(1.5), 5);
assert_eq!(product.to_string(), "4.75");
assert_eq!(o, Greater);

let (product, o) = Float::from(PI).mul_rational_prec_ref_val(Rational::exact_from(1.5), 20);
assert_eq!(product.to_string(), "4.7123871");
assert_eq!(o, Less);
Source

pub fn mul_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the product is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x>0$
  • $f(\infty,x,p)=-\infty$ if $x<0$
  • $f(-\infty,x,p)=-\infty$ if $x>0$
  • $f(-\infty,x,p)=\infty$ if $x<0$
  • $f(0.0,x,p)=0.0$ if $x\geq0$
  • $f(0.0,x,p)=-0.0$ if $x<0$
  • $f(-0.0,x,p)=-0.0$ if $x\geq0$
  • $f(-0.0,x,p)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_rational_prec_round_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using * instead.

§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(), prec).

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) = Float::from(PI).mul_rational_prec_ref_ref(&Rational::exact_from(1.5), 5);
assert_eq!(product.to_string(), "4.75");
assert_eq!(o, Greater);

let (product, o) =
    Float::from(PI).mul_rational_prec_ref_ref(&Rational::exact_from(1.5), 20);
assert_eq!(product.to_string(), "4.7123871");
assert_eq!(o, Less);
Source

pub fn mul_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=f(\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x>0$
  • $f(\infty,x,m)=-\infty$ if $x<0$
  • $f(-\infty,x,m)=-\infty$ if $x>0$
  • $f(-\infty,x,m)=\infty$ if $x<0$
  • $f(0.0,x,m)=0.0$ if $x\geq0$
  • $f(0.0,x,m)=-0.0$ if $x<0$
  • $f(-0.0,x,m)=-0.0$ if $x\geq0$
  • $f(-0.0,x,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_rational_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using * instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) =
    Float::from(PI).mul_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(product.to_string(), "1.0471975511965965");
assert_eq!(o, Less);

let (product, o) =
    Float::from(PI).mul_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(product.to_string(), "1.0471975511965983");
assert_eq!(o, Greater);

let (product, o) =
    Float::from(PI).mul_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(product.to_string(), "1.0471975511965983");
assert_eq!(o, Greater);
Source

pub fn mul_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Multiplies a Float by a Rational, rounding the result with the specified rounding mode. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded product is less than, equal to, or greater than the exact product. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = xy+\varepsilon. $$

  • If $xy$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $xy$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=f(\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x>0$
  • $f(\infty,x,m)=-\infty$ if $x<0$
  • $f(-\infty,x,m)=-\infty$ if $x>0$
  • $f(-\infty,x,m)=\infty$ if $x<0$
  • $f(0.0,x,m)=0.0$ if $x\geq0$
  • $f(0.0,x,m)=-0.0$ if $x<0$
  • $f(-0.0,x,m)=-0.0$ if $x\geq0$
  • $f(-0.0,x,m)=0.0$ if $x<0$

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_rational_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using * instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (product, o) =
    Float::from(PI).mul_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(product.to_string(), "1.0471975511965965");
assert_eq!(o, Less);

let (product, o) =
    Float::from(PI).mul_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(product.to_string(), "1.0471975511965983");
assert_eq!(o, Greater);

let (product, o) =
    Float::from(PI).mul_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(product.to_string(), "1.0471975511965983");
assert_eq!(o, Greater);
Source

pub fn mul_add_mul_prec_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds the products of two pairs of Floats, rounding the result to the specified precision and with the specified rounding mode; the products are not rounded before the final addition, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,p,m) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy+zw|\rfloor-p+1}$.
  • If $xy+zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,p,m)=0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,p,m)=-0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_add_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::mul_add_mul_round instead. If both of these things are true, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused operation is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Floor);
assert_eq!(sum.to_string(), "9.50");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Ceiling);
assert_eq!(sum.to_string(), "10.0");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Nearest);
assert_eq!(sum.to_string(), "9.50");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Floor);
assert_eq!(sum.to_string(), "9.5199890");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Ceiling);
assert_eq!(sum.to_string(), "9.5200043");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Nearest);
assert_eq!(sum.to_string(), "9.5199890");
assert_eq!(o, Less);
Source

pub fn mul_add_mul_prec_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, prec: u64, ) -> (Self, Ordering)

Adds the products of two pairs of Floats, rounding the result to the nearest value of the specified precision; the products are not rounded before the final addition, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,w,p) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,p)=0.0$ if $xy=-zw$, the products are
  • $f(x,y,z,w,p)=0.0$ if $xy=-zw$ and the products are finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,w,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,w,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,w,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_add_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (sum, o) = x.mul_add_mul_prec_ref_ref_ref_ref(&y, &z, &w, 5);
assert_eq!(sum.to_string(), "9.50");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_prec_ref_ref_ref_ref(&y, &z, &w, 20);
assert_eq!(sum.to_string(), "9.5199890");
assert_eq!(o, Less);
Source

pub fn mul_add_mul_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Adds the products of two pairs of Floats, rounding the result with the specified rounding mode; the products are not rounded before the final addition, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,m) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy+zw|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy+zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,m)=0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,m)=-0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_add_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is self.significant_bits().

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (sum, o) = x.mul_add_mul_round_ref_ref_ref_ref(&y, &z, &w, Floor);
assert_eq!(sum.to_string(), "9.5199923661421124");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_round_ref_ref_ref_ref(&y, &z, &w, Ceiling);
assert_eq!(sum.to_string(), "9.5199923661421142");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_round_ref_ref_ref_ref(&y, &z, &w, Nearest);
assert_eq!(sum.to_string(), "9.5199923661421142");
assert_eq!(o, Greater);
Source

pub fn mul_add_mul_rational_prec_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Adds the product of two Floats and the product of a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode; the Rational enters its product exactly and the products are not rounded before the final addition, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,p,m) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy+zw|\rfloor-p+1}$.
  • If $xy+zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,p,m)=0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,p,m)=-0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_add_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::mul_add_mul_rational_round instead. If both of these things are true, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused operation is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(1, 3);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Floor);
assert_eq!(sum.to_string(), "9.00");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Ceiling);
assert_eq!(sum.to_string(), "9.50");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Nearest);
assert_eq!(sum.to_string(), "9.00");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Floor);
assert_eq!(sum.to_string(), "9.0111237");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Ceiling);
assert_eq!(sum.to_string(), "9.0111389");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Nearest);
assert_eq!(sum.to_string(), "9.0111389");
assert_eq!(o, Greater);
Source

pub fn mul_add_mul_rational_prec_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, prec: u64, ) -> (Self, Ordering)

Adds the product of two Floats and the product of a Float and a Rational, rounding the result to the nearest value of the specified precision; the Rational enters its product exactly and the products are not rounded before the final addition, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sum is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,w,p) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,p)=0.0$ if $xy=-zw$, the products are
  • $f(x,y,z,w,p)=0.0$ if $xy=-zw$ and the products are finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,w,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,w,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,w,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_add_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(1, 3);

let (sum, o) = x.mul_add_mul_rational_prec_ref_ref_ref_ref(&y, &z, &w, 5);
assert_eq!(sum.to_string(), "9.00");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_rational_prec_ref_ref_ref_ref(&y, &z, &w, 20);
assert_eq!(sum.to_string(), "9.0111389");
assert_eq!(o, Greater);
Source

pub fn mul_add_mul_rational_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Adds the product of two Floats and the product of a Float and a Rational, rounding the result with the specified rounding mode; the Rational enters its product exactly and the products are not rounded before the final addition, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded sum is less than, equal to, or greater than the exact sum. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,m) = xy+zw+\varepsilon. $$

  • If $xy+zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy+zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy+zw|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy+zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy+zw|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity.
  • If both products are infinite, the result is their common infinity if their signs agree, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply.
  • $f(x,y,z,w,m)=0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,m)=-0.0$ if $xy=-zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_add_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using mul_add_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is self.significant_bits().

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(1, 3);

let (sum, o) = x.mul_add_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Floor);
assert_eq!(sum.to_string(), "9.0111387434645973");
assert_eq!(o, Less);

let (sum, o) = x.mul_add_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Ceiling);
assert_eq!(sum.to_string(), "9.0111387434645991");
assert_eq!(o, Greater);

let (sum, o) = x.mul_add_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Nearest);
assert_eq!(sum.to_string(), "9.0111387434645973");
assert_eq!(o, Less);
Source

pub fn mul_sub_mul_prec_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of one pair of Floats from the product of another pair, rounding the result to the specified precision and with the specified rounding mode; the products are not rounded before the final subtraction, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,p,m) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy-zw|\rfloor-p+1}$.
  • If $xy-zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,p,m)=0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,p,m)=-0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_sub_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::mul_sub_mul_round instead. If both of these things are true, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused operation is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Floor);
assert_eq!(diff.to_string(), "7.50");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Ceiling);
assert_eq!(diff.to_string(), "7.75");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Nearest);
assert_eq!(diff.to_string(), "7.50");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Floor);
assert_eq!(diff.to_string(), "7.5594711");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Ceiling);
assert_eq!(diff.to_string(), "7.5594788");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Nearest);
assert_eq!(diff.to_string(), "7.5594788");
assert_eq!(o, Greater);
Source

pub fn mul_sub_mul_prec_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, prec: u64, ) -> (Self, Ordering)

Subtracts the product of one pair of Floats from the product of another pair, rounding the result to the nearest value of the specified precision; the products are not rounded before the final subtraction, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,w,p) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,p)=0.0$ if $xy=zw$, the products are
  • $f(x,y,z,w,p)=0.0$ if $xy=zw$ and the products are finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,w,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,w,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,w,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_sub_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (diff, o) = x.mul_sub_mul_prec_ref_ref_ref_ref(&y, &z, &w, 5);
assert_eq!(diff.to_string(), "7.50");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_prec_ref_ref_ref_ref(&y, &z, &w, 20);
assert_eq!(diff.to_string(), "7.5594788");
assert_eq!(o, Greater);
Source

pub fn mul_sub_mul_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of one pair of Floats from the product of another pair, rounding the result with the specified rounding mode; the products are not rounded before the final subtraction, so there is a single rounding. All four Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,m) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy-zw|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy-zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,m)=0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,m)=-0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_sub_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is self.significant_bits().

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, LN_2, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Float::from(LN_2);

let (diff, o) = x.mul_sub_mul_round_ref_ref_ref_ref(&y, &z, &w, Floor);
assert_eq!(diff.to_string(), "7.5594760792050186");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_round_ref_ref_ref_ref(&y, &z, &w, Ceiling);
assert_eq!(diff.to_string(), "7.5594760792050195");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_round_ref_ref_ref_ref(&y, &z, &w, Nearest);
assert_eq!(diff.to_string(), "7.5594760792050186");
assert_eq!(o, Less);
Source

pub fn mul_sub_mul_rational_prec_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from the product of two Floats, rounding the result to the specified precision and with the specified rounding mode; the Rational enters its product exactly and the products are not rounded before the final subtraction, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,p,m) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy-zw|\rfloor-p+1}$.
  • If $xy-zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$ $f(\text{NaN},y,z,w,p,m)=f(x,\text{NaN},z,w,p,m)=f(x,y,\text{NaN},w,p,m)= f(x,y,z,\text{NaN},p,m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,p,m)=0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,p,m)=-0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::mul_sub_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::mul_sub_mul_rational_round instead. If both of these things are true, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused operation is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(22, 7);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Floor);
assert_eq!(diff.to_string(), "4.00");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Ceiling);
assert_eq!(diff.to_string(), "4.25");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 5, Nearest);
assert_eq!(diff.to_string(), "4.00");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Floor);
assert_eq!(diff.to_string(), "4.0950623");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Ceiling);
assert_eq!(diff.to_string(), "4.0950699");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_rational_prec_round_ref_ref_ref_ref(&y, &z, &w, 20, Nearest);
assert_eq!(diff.to_string(), "4.0950623");
assert_eq!(o, Less);
Source

pub fn mul_sub_mul_rational_prec_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, prec: u64, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from the product of two Floats, rounding the result to the nearest value of the specified precision; the Rational enters its product exactly and the products are not rounded before the final subtraction, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,w,p) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$ $f(\text{NaN},y,z,w,p)=f(x,\text{NaN},z,w,p)=f(x,y,\text{NaN},w,p)= f(x,y,z,\text{NaN},p)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,p)=0.0$ if $xy=zw$, the products are
  • $f(x,y,z,w,p)=0.0$ if $xy=zw$ and the products are finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,w,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,w,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,w,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::mul_sub_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(22, 7);

let (diff, o) = x.mul_sub_mul_rational_prec_ref_ref_ref_ref(&y, &z, &w, 5);
assert_eq!(diff.to_string(), "4.00");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_rational_prec_ref_ref_ref_ref(&y, &z, &w, 20);
assert_eq!(diff.to_string(), "4.0950623");
assert_eq!(o, Less);
Source

pub fn mul_sub_mul_rational_round_ref_ref_ref_ref( &self, y: &Self, z: &Self, w: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from the product of two Floats, rounding the result with the specified rounding mode; the Rational enters its product exactly and the products are not rounded before the final subtraction, so there is a single rounding. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,w,m) = xy-zw+\varepsilon. $$

  • If $xy-zw$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $xy-zw$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |xy-zw|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $xy-zw$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |xy-zw|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$ $f(\text{NaN},y,z,w,m)=f(x,\text{NaN},z,w,m)=f(x,y,\text{NaN},w,m)= f(x,y,z,\text{NaN},m)=\text{NaN}$
  • If either product multiplies an infinity by a zero, the result is NaN; a zero Rational counts as an unsigned zero and a positive sign.
  • If exactly one product is infinite, the result is that product’s infinity, the second product’s sign counting as flipped.
  • If both products are infinite, the result is their common infinity if their signs differ, and NaN otherwise.
  • If both products are zeros, the sign rules of Float addition apply to $xy$ and $-zw$.
  • $f(x,y,z,w,m)=0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,w,m)=-0.0$ if $xy=zw$, the products are finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,w,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,w,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,w,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,w,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,w,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,w,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::mul_sub_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using mul_sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits() + w.significant_bits(), and $m$ is self.significant_bits().

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);
let w = Rational::from_signeds(22, 7);

let (diff, o) = x.mul_sub_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Floor);
assert_eq!(diff.to_string(), "4.0950630266438379");
assert_eq!(o, Less);

let (diff, o) = x.mul_sub_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Ceiling);
assert_eq!(diff.to_string(), "4.0950630266438388");
assert_eq!(o, Greater);

let (diff, o) = x.mul_sub_mul_rational_round_ref_ref_ref_ref(&y, &z, &w, Nearest);
assert_eq!(diff.to_string(), "4.0950630266438388");
assert_eq!(o, Greater);
Source

pub fn positive_difference_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you know you’ll be using Nearest, consider using Float::positive_difference_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::positive_difference_round instead. If both of these things are true, consider using Float::positive_difference instead.

§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(), other.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the positive difference is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (d, o) =
    Float::from(3u32).positive_difference_prec_round_ref_val(Float::ONE, 10, Floor);
assert_eq!(d.to_string(), "2.0000");
assert_eq!(o, Equal);

let (d, o) =
    Float::from(10u32).positive_difference_prec_round_ref_val(Float::from(7u32), 1, Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Less);

let (d, o) = Float::from(10u32).positive_difference_prec_round_ref_val(
    Float::from(7u32),
    1,
    Ceiling,
);
assert_eq!(d.to_string(), "4.0");
assert_eq!(o, Greater);
Source

pub fn positive_difference_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you know you’ll be using Nearest, consider using Float::positive_difference_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::positive_difference_round instead. If both of these things are true, consider using Float::positive_difference instead.

§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(), other.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the positive difference is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (d, o) =
    Float::from(3u32).positive_difference_prec_round_ref_ref(&Float::ONE, 10, Floor);
assert_eq!(d.to_string(), "2.0000");
assert_eq!(o, Equal);

let (d, o) =
    Float::from(10u32).positive_difference_prec_round_ref_ref(&Float::from(7u32), 1, Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Less);

let (d, o) = Float::from(10u32).positive_difference_prec_round_ref_ref(
    &Float::from(7u32),
    1,
    Ceiling,
);
assert_eq!(d.to_string(), "4.0");
assert_eq!(o, Greater);
Source

pub fn positive_difference_prec_ref_val( &self, other: Self, prec: u64, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::positive_difference instead.

§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(), other.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_prec_ref_val(Float::ONE, 10);
assert_eq!(d.to_string(), "2.0000");
assert_eq!(o, Equal);
Source

pub fn positive_difference_prec_ref_ref( &self, other: &Self, prec: u64, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::positive_difference instead.

§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(), other.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_prec_ref_ref(&Float::ONE, 10);
assert_eq!(d.to_string(), "2.0000");
assert_eq!(o, Equal);
Source

pub fn positive_difference_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the maximum of the precisions of the inputs, with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you want to specify an output precision, consider using Float::positive_difference_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::positive_difference instead.

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

§Panics

Panics if rm is Exact and the positive difference is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_round_ref_val(Float::ONE, Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Equal);
Source

pub fn positive_difference_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the maximum of the precisions of the inputs, with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you want to specify an output precision, consider using Float::positive_difference_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::positive_difference instead.

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

§Panics

Panics if rm is Exact and the positive difference is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_round_ref_ref(&Float::ONE, Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Equal);
Source

pub fn positive_difference_ref_val(&self, other: Self) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the maximum of the precisions of the inputs. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to specify an output precision, consider using Float::positive_difference_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_round instead.

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

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_ref_val(Float::ONE);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Equal);

let (d, o) = Float::from(3u32).positive_difference_ref_val(Float::from(5u32));
assert_eq!(d.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn positive_difference_ref_ref(&self, other: &Self) -> (Self, Ordering)

Computes the positive difference of two Floats — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the maximum of the precisions of the inputs. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is the positive difference, mpfr_dim and C’s fdim. Zero is returned for $x\leq y$ as a matter of definition — negative values are representable, but the function chooses $+0.0$ instead — so this is not a saturating subtraction. The comparison treats zeros of both signs as equal and infinities as their usual extremes.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including $f(\pm0.0,\pm0.0,p)$ and $f(\infty,\infty,p)$
  • $f(\infty,y,p)=\infty$ if $y$ is not NaN and $y\neq\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN and $x\neq-\infty$

Overflow and underflow are as for subtraction:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to specify an output precision, consider using Float::positive_difference_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_round instead.

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

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::One;
use malachite_float::Float;

let (d, o) = Float::from(3u32).positive_difference_ref_ref(&Float::ONE);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Equal);

let (d, o) = Float::from(3u32).positive_difference_ref_ref(&Float::from(5u32));
assert_eq!(d.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn positive_difference_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you know you’ll be using Nearest, consider using Float::positive_difference_rational_prec instead. If you know that your target precision is the Float’s, consider using Float::positive_difference_rational_round instead. If both of these things are true, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the positive difference is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32).positive_difference_rational_prec_round_ref_val(
    Rational::from_signeds(1, 3),
    10,
    Floor,
);
assert_eq!(d.to_string(), "2.6641");
assert_eq!(o, Less);

let (d, o) = Float::from(3u32).positive_difference_rational_prec_round_ref_val(
    Rational::from_signeds(1, 3),
    10,
    Ceiling,
);
assert_eq!(d.to_string(), "2.6680");
assert_eq!(o, Greater);
Source

pub fn positive_difference_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you know you’ll be using Nearest, consider using Float::positive_difference_rational_prec instead. If you know that your target precision is the Float’s, consider using Float::positive_difference_rational_round instead. If both of these things are true, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the positive difference is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32).positive_difference_rational_prec_round_ref_ref(
    &Rational::from_signeds(1, 3),
    10,
    Floor,
);
assert_eq!(d.to_string(), "2.6641");
assert_eq!(o, Less);

let (d, o) = Float::from(3u32).positive_difference_rational_prec_round_ref_ref(
    &Rational::from_signeds(1, 3),
    10,
    Ceiling,
);
assert_eq!(d.to_string(), "2.6680");
assert_eq!(o, Greater);
Source

pub fn positive_difference_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_rational_prec_round instead. If you know that your target precision is the Float’s, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32)
    .positive_difference_rational_prec_ref_val(Rational::from_signeds(1, 3), 10);
assert_eq!(d.to_string(), "2.6680");
assert_eq!(o, Greater);
Source

pub fn positive_difference_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_rational_prec_round instead. If you know that your target precision is the Float’s, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32)
    .positive_difference_rational_prec_ref_ref(&Rational::from_signeds(1, 3), 10);
assert_eq!(d.to_string(), "2.6680");
assert_eq!(o, Greater);
Source

pub fn positive_difference_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you want to specify an output precision, consider using Float::positive_difference_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the positive difference is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32)
    .positive_difference_rational_round_ref_val(Rational::from_signeds(1, 3), Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Less);
Source

pub fn positive_difference_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p+1}$.

If you want to specify an output precision, consider using Float::positive_difference_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::positive_difference_rational instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the positive difference is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) = Float::from(3u32)
    .positive_difference_rational_round_ref_ref(&Rational::from_signeds(1, 3), Floor);
assert_eq!(d.to_string(), "2.0");
assert_eq!(o, Less);
Source

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

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to specify an output precision, consider using Float::positive_difference_rational_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_rational_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) =
    Float::from(3u32).positive_difference_rational_ref_val(Rational::from_signeds(1, 3));
assert_eq!(d.to_string(), "3.0");
assert_eq!(o, Greater);
Source

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

Computes the positive difference of a Float and a Rational — $x-y$ if $x>y$, and $+0.0$ otherwise — rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded result is less than, equal to, or greater than the exact positive difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison and the difference are both exact: the Rational operand is never rounded before use, so the correct branch is always chosen and the winning difference is correctly rounded.

Special cases:

  • $f(\text{NaN},y,p)=\text{NaN}$
  • $f(x,y,p)=+0.0$ if $x\leq y$, including for a zero Float of either sign against a zero Rational
  • $f(\infty,y,p)=\infty$

$$ f(x,y,p) = \begin{cases} x-y+\varepsilon & x>y \\ +0.0 & \text{otherwise,} \end{cases} $$

  • If $x\leq y$ or the exact difference is representable, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 (x-y)\rfloor-p}$.

If you want to specify an output precision, consider using Float::positive_difference_rational_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::positive_difference_rational_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (d, o) =
    Float::from(3u32).positive_difference_rational_ref_ref(&Rational::from_signeds(1, 3));
assert_eq!(d.to_string(), "3.0");
assert_eq!(o, Greater);
Source

pub fn pow_prec_round_ref_ref( &self, y: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\rfloor-p+1}$.
  • If $x^y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(x,\pm0.0,p,m)=1.0$ for any $x$, even NaN
  • $f(1.0,y,p,m)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,p,m)=f(x,\text{NaN},p,m)=\text{NaN}$ otherwise
  • $f(x,\infty,p,m)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,p,m)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,p,m)=1.0$
  • $f(-1.0,y,p,m)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,p,m)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,p,m)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,p,m)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,p,m)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,p,m)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above, with the rounding directions reflected.

If you know you’ll be using Nearest, consider using Float::pow_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::pow_round_ref_ref instead. If both of these things are true, consider using Pow::pow instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 5, Floor);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 5, Ceiling);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 5, Nearest);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 20, Floor);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 20, Ceiling);
assert_eq!(p.to_string(), "15.588470");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_ref(&Float::from(2.5), 20, Nearest);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);
Source

pub fn pow_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\rfloor-p+1}$.
  • If $x^y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(x,\pm0.0,p,m)=1.0$ for any $x$, even NaN
  • $f(1.0,y,p,m)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,p,m)=f(x,\text{NaN},p,m)=\text{NaN}$ otherwise
  • $f(x,\infty,p,m)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,p,m)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,p,m)=1.0$
  • $f(-1.0,y,p,m)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,p,m)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,p,m)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,p,m)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,p,m)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,p,m)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above, with the rounding directions reflected.

If you know you’ll be using Nearest, consider using Float::pow_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::pow_round_ref_val instead. If both of these things are true, consider using Pow::pow instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 5, Floor);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 5, Ceiling);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 5, Nearest);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 20, Floor);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 20, Ceiling);
assert_eq!(p.to_string(), "15.588470");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_prec_round_ref_val(Float::from(2.5), 20, Nearest);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);
Source

pub fn pow_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the specified precision and to the nearest value. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(x,\pm0.0,p)=1.0$ for any $x$, even NaN
  • $f(1.0,y,p)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$ otherwise
  • $f(x,\infty,p)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,p)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,p)=1.0$
  • $f(-1.0,y,p)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,p)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,p)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,p)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,p)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,p)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above.

If you want to use a rounding mode other than Nearest, consider using Float::pow_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Pow::pow instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_prec_ref_ref(&Float::from(2.5), 5);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_ref_ref(&Float::from(2.5), 20);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);
Source

pub fn pow_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the maximum of the precisions of the two inputs and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\rfloor-p+1}$.
  • If $x^y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(x,\pm0.0,m)=1.0$ for any $x$, even NaN
  • $f(1.0,y,m)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,m)=f(x,\text{NaN},m)=\text{NaN}$ otherwise
  • $f(x,\infty,m)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,m)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,m)=1.0$
  • $f(-1.0,y,m)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,m)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,m)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,m)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,m)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,m)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above, with the rounding directions reflected.

If you want to specify an output precision, consider using Float::pow_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using Pow::pow instead.

§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_round_ref_ref(&Float::from(2.5), Floor);
assert_eq!(p.to_string(), "14.0");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_round_ref_ref(&Float::from(2.5), Ceiling);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_round_ref_ref(&Float::from(2.5), Nearest);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);
Source

pub fn pow_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the maximum of the precisions of the two inputs and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\rfloor-p+1}$.
  • If $x^y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(x,\pm0.0,m)=1.0$ for any $x$, even NaN
  • $f(1.0,y,m)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,m)=f(x,\text{NaN},m)=\text{NaN}$ otherwise
  • $f(x,\infty,m)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,m)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,m)=1.0$
  • $f(-1.0,y,m)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,m)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,m)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,m)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,m)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,m)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above, with the rounding directions reflected.

If you want to specify an output precision, consider using Float::pow_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using Pow::pow instead.

§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_round_ref_val(Float::from(2.5), Floor);
assert_eq!(p.to_string(), "14.0");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_round_ref_val(Float::from(2.5), Ceiling);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);

let (p, o) = (&Float::from(3)).pow_round_ref_val(Float::from(2.5), Nearest);
assert_eq!(p.to_string(), "16.0");
assert_eq!(o, Greater);
Source

pub fn pow_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Raises a Float to a Float power, rounding the result to the specified precision and to the nearest value. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(x,\pm0.0,p)=1.0$ for any $x$, even NaN
  • $f(1.0,y,p)=1.0$ for any $y$, even NaN
  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=\text{NaN}$ otherwise
  • $f(x,\infty,p)=\infty$ if $|x|>1$, and $0.0$ if $|x|<1$
  • $f(x,-\infty,p)=0.0$ if $|x|>1$, and $\infty$ if $|x|<1$
  • $f(-1.0,\pm\infty,p)=1.0$
  • $f(-1.0,y,p)=1.0$ if $y$ is an even integer, and $-1.0$ if $y$ is an odd integer
  • $f(\infty,y,p)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(-\infty,y,p)=-\infty$ if $y$ is a positive odd integer, $\infty$ if $y$ is positive and not an odd integer, $-0.0$ if $y$ is a negative odd integer, and $0.0$ if $y$ is negative and not an odd integer
  • $f(0.0,y,p)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(-0.0,y,p)=-0.0$ if $y$ is a positive odd integer, $0.0$ if $y$ is positive and not an odd integer, $-\infty$ if $y$ is a negative odd integer, and $\infty$ if $y$ is negative and not an odd integer
  • $f(x,y,p)=\text{NaN}$ if $x$ is finite and negative and $y$ is finite and not an integer

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd integer $y$) mirror the bullets above.

If you want to use a rounding mode other than Nearest, consider using Float::pow_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Pow::pow instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_prec_ref_val(Float::from(2.5), 5);
assert_eq!(p.to_string(), "15.5");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_prec_ref_val(Float::from(2.5), 20);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);
Source

pub fn pow_integer_prec_round_ref_val( &self, other: Integer, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Integer by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_integer_prec_round_ref_ref documentation for information on special cases, overflow, and underflow.

§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_prec_round_ref_val(Integer::from(5), 20, Floor);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let x = Float::from(3);
let (p, o) = (&x).pow_integer_prec_round_ref_val(Integer::from(-2), 10, Ceiling);
assert_eq!(p.to_string(), "0.11121");
assert_eq!(o, Greater);
Source

pub fn pow_integer_prec_round_ref_ref( &self, other: &Integer, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the specified precision and with the specified rounding mode. Both are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

Special cases:

  • $f(x,0)=1.0$ for any $x$, even NaN
  • $f(1.0,n)=1.0$
  • $f(\text{NaN},n)=\text{NaN}$ if $n \neq 0$
  • $f(-1.0,n)=1.0$ if $n$ is even, and $-1.0$ if $n$ is odd
  • $f(\infty,n)=\infty$ if $n>0$, and $0.0$ if $n<0$
  • $f(-\infty,n)=-\infty$ if $n$ is positive and odd, $\infty$ if $n$ is positive and even, $-0.0$ if $n$ is negative and odd, and $0.0$ if $n$ is negative and even
  • $f(0.0,n)=0.0$ if $n>0$, and $\infty$ if $n<0$
  • $f(-0.0,n)=-0.0$ if $n$ is positive and odd, $0.0$ if $n$ is positive and even, $-\infty$ if $n$ is negative and odd, and $\infty$ if $n$ is negative and even

Overflow and underflow:

  • If $f(x,n,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,n,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,n,p,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,n,p,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,n,p,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,n,p,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • Negative results (from negative $x$ and odd $n$) mirror the bullets above, with the rounding directions reflected.
§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_prec_round_ref_ref(&Integer::from(5), 20, Floor);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let x = Float::from(3);
let (p, o) = (&x).pow_integer_prec_round_ref_ref(&Integer::from(-2), 10, Ceiling);
assert_eq!(p.to_string(), "0.11121");
assert_eq!(o, Greater);
Source

pub fn pow_integer_prec_ref_val( &self, other: Integer, prec: u64, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the specified precision and to the nearest value. The Float is taken by reference and the Integer by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,n,p) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_integer_prec_round_ref_ref documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::pow_integer_prec_round_ref_val instead.

§Worst-case complexity

$T(n) = O(n^{3/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()).

§Examples
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_prec_ref_val(Integer::from(5), 20);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_integer_prec_ref_val(Integer::from(-2), 10);
assert_eq!(p.to_string(), "0.11108");
assert_eq!(o, Less);
Source

pub fn pow_integer_prec_ref_ref( &self, other: &Integer, prec: u64, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the specified precision and to the nearest value. Both are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,n,p) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_integer_prec_round_ref_ref documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::pow_integer_prec_round_ref_ref instead.

§Worst-case complexity

$T(n) = O(n^{3/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()).

§Examples
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_prec_ref_ref(&Integer::from(5), 20);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_integer_prec_ref_ref(&Integer::from(-2), 10);
assert_eq!(p.to_string(), "0.11108");
assert_eq!(o, Less);
Source

pub fn pow_integer_round_ref_val( &self, other: Integer, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the precision of the base and with the specified rounding mode. The Float is taken by reference and the Integer by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_integer_prec_round_ref_ref documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::pow_integer_prec_round_ref_val instead.

§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the base’s precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_round_ref_val(Integer::from(5), Floor);
assert_eq!(p.to_string(), "1.9e2");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_integer_round_ref_val(Integer::from(5), Ceiling);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_integer_round_ref_ref( &self, other: &Integer, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of an Integer, rounding the result to the precision of the base and with the specified rounding mode. Both are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_integer_prec_round_ref_ref documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::pow_integer_prec_round_ref_ref instead.

§Worst-case complexity

$T(n) = O(n^{3/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

Panics if rm is Exact but the result cannot be represented exactly with the base’s precision.

§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_integer_round_ref_ref(&Integer::from(5), Floor);
assert_eq!(p.to_string(), "1.9e2");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_integer_round_ref_ref(&Integer::from(5), Ceiling);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_u_prec_round_ref( &self, n: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a u64, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_u_prec_round documentation for information on special cases, overflow, and underflow.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_u_prec_round_ref(5, 20, Floor);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_u_prec_round_ref(5, 2, Ceiling);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_u_prec_ref(&self, n: u64, prec: u64) -> (Self, Ordering)

Raises a Float to the power of a u64, rounding the result to the specified precision and to the nearest value. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,n,p) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_u_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::pow_u_prec_round_ref instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_u_prec_ref(5, 20);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_u_prec_ref(5, 2);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_u_round_ref(&self, n: u64, rm: RoundingMode) -> (Self, Ordering)

Raises a Float to the power of a u64, rounding the result to the precision of the base and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_u_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::pow_u_prec_round_ref instead.

§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 rm is Exact but the result cannot be represented exactly with the base’s precision.

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

let (p, o) = (&Float::from(3)).pow_u_round_ref(5, Floor);
assert_eq!(p.to_string(), "1.9e2");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_u_round_ref(5, Ceiling);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_s_prec_round_ref( &self, n: i64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a i64, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_s_prec_round documentation for information on special cases, overflow, and underflow.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = (&Float::from(3)).pow_s_prec_round_ref(5, 20, Floor);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_s_prec_round_ref(-2, 10, Ceiling);
assert_eq!(p.to_string(), "0.11121");
assert_eq!(o, Greater);
Source

pub fn pow_s_prec_ref(&self, n: i64, prec: u64) -> (Self, Ordering)

Raises a Float to the power of a i64, rounding the result to the specified precision and to the nearest value. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,n,p) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_s_prec_round documentation for information on special cases, overflow, and underflow.

If you want to use a rounding mode other than Nearest, consider using Float::pow_s_prec_round_ref instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is max(prec, self.significant_bits()), and $m$ is the number of significant bits of the exponent n.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (p, o) = (&Float::from(3)).pow_s_prec_ref(5, 20);
assert_eq!(p.to_string(), "243.00000");
assert_eq!(o, Equal);

let (p, o) = (&Float::from(3)).pow_s_prec_ref(-2, 10);
assert_eq!(p.to_string(), "0.11108");
assert_eq!(o, Less);
Source

pub fn pow_s_round_ref(&self, n: i64, rm: RoundingMode) -> (Self, Ordering)

Raises a Float to the power of a i64, rounding the result to the precision of the base and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

$$ f(x,n,p,m) = x^n+\varepsilon. $$

  • If $x^n$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^n$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^n|\rfloor-p+1}$.
  • If $x^n$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^n|\rfloor-p}$.

See the Float::pow_s_prec_round documentation for information on special cases, overflow, and underflow.

If you want to specify an output precision, consider using Float::pow_s_prec_round_ref instead.

§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 rm is Exact but the result cannot be represented exactly with the base’s precision.

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

let (p, o) = (&Float::from(3)).pow_s_round_ref(5, Floor);
assert_eq!(p.to_string(), "1.9e2");
assert_eq!(o, Less);

let (p, o) = (&Float::from(3)).pow_s_round_ref(5, Ceiling);
assert_eq!(p.to_string(), "2.6e2");
assert_eq!(o, Greater);
Source

pub fn pow_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn pow_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the specified precision and with the specified rounding mode. Both the Float and the Rational are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn pow_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the specified precision and to the nearest value. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn pow_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the specified precision and to the nearest value. Both the Float and the Rational are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn pow_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the precision of the base and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn pow_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to the power of a Rational, rounding the result to the precision of the base and with the specified rounding mode. Both the Float and the Rational are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The output precision is the precision of self. See RoundingMode for a description of the possible rounding modes.

See the Float::pow_rational_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn powr_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::powr_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn powr_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y) = x^y+\varepsilon. $$

  • If $x^y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^y|\rfloor-p+1}$.
  • If $x^y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^y|\rfloor-p}$.

If the output has a precision, it is prec.

powr(x, y) is $e^{y\ln x}$; unlike pow, its base is restricted to $x\geq 0$ and it never produces a negative result.

Special cases:

  • $f(x,y)=\text{NaN}$ if $x$ is NaN, if $x<0$, if $x$ is $\pm0$ or $\infty$ and $y=0$, or if $x=1$ and $y$ is infinite
  • $f(x,0)=1.0$ if $x$ is finite and positive
  • $f(1.0,y)=1.0$ if $y$ is finite
  • $f(\infty,y)=\infty$ if $y>0$, and $0.0$ if $y<0$
  • $f(\pm0.0,y)=0.0$ if $y>0$, and $\infty$ if $y<0$
  • $f(x,\infty)=\infty$ if $x>1$, and $0.0$ if $0<x<1$
  • $f(x,-\infty)=0.0$ if $x>1$, and $\infty$ if $0<x<1$

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$ and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$ and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (p, o) = Float::from(3).powr_prec_round(Float::from(2.5), 20, Floor);
assert_eq!(p.to_string(), "15.588455");
assert_eq!(o, Less);

let (p, o) = Float::from(3).powr_prec_round(Float::from(2.5), 20, Ceiling);
assert_eq!(p.to_string(), "15.588470");
assert_eq!(o, Greater);

// A negative base gives NaN (unlike `pow`).
let (p, o) = Float::from(-2).powr_prec_round(Float::from(3), 10, Nearest);
assert_eq!(p.to_string(), "NaN");
assert_eq!(o, Equal);
Source

pub fn powr_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the specified precision and to the nearest value. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See the Float::powr_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn powr_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the specified precision and to the nearest value. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the power is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See the Float::powr_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn powr_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the maximum of the precisions of the inputs and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::powr_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn powr_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Raises a Float to a Float power using the IEEE 754 powr function, rounding the result to the maximum of the precisions of the inputs and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded power is less than, equal to, or greater than the exact power. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

See the Float::powr_prec_round documentation for information on special cases, overflow, and underflow.

Source

pub fn power_of_10_x_minus_1_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $10^x-1$, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference.

Source

pub fn power_of_10_x_minus_1_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $10^x-1$, rounding the result to the nearest value of the specified precision. The Float is taken by reference.

Source

pub fn power_of_10_x_minus_1_round_ref( &self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $10^x-1$, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference.

Source

pub fn power_of_2_x_minus_1_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $2^x-1$, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference.

Source

pub fn power_of_2_x_minus_1_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $2^x-1$, rounding the result to the nearest value of the specified precision. The Float is taken by reference.

Source

pub fn power_of_2_x_minus_1_round_ref( &self, rm: RoundingMode, ) -> (Self, Ordering)

Computes $2^x-1$, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference.

Source

pub fn reciprocal_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Takes the reciprocal of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal is less than, equal to, or greater than the exact reciprocal. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = 1/x+\varepsilon. $$

  • If $1/x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |1/x|\rfloor-p+1}$.
  • If $1/x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |1/x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=0.0$
  • $f(-\infty,p,m)=-0.0$
  • $f(0.0,p,m)=\infty$
  • $f(-0.0,p,m)=-\infty$

Overflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.

This function cannot underflow.

If you know you’ll be using Nearest, consider using Float::reciprocal_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::reciprocal_round_ref instead. If both of these things are true, consider using (&Float)::reciprocal() instead.

§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(), prec).

§Panics

Panics if rm is Exact but prec is too small for an exact reciprocation.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(5, Floor);
assert_eq!(reciprocal.to_string(), "0.312");
assert_eq!(o, Less);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(5, Ceiling);
assert_eq!(reciprocal.to_string(), "0.328");
assert_eq!(o, Greater);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(5, Nearest);
assert_eq!(reciprocal.to_string(), "0.312");
assert_eq!(o, Less);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Floor);
assert_eq!(reciprocal.to_string(), "0.31830978");
assert_eq!(o, Less);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Ceiling);
assert_eq!(reciprocal.to_string(), "0.31831026");
assert_eq!(o, Greater);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Nearest);
assert_eq!(reciprocal.to_string(), "0.31830978");
assert_eq!(o, Less);
Source

pub fn reciprocal_prec_ref(&self, prec: u64) -> (Self, Ordering)

Takes the reciprocal of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal is less than, equal to, or greater than the exact reciprocal. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the reciprocal is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = 1/x+\varepsilon. $$

  • If $1/x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/x$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |1/x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=0.0$
  • $f(-\infty,p)=-0.0$
  • $f(0.0,p)=\infty$
  • $f(-0.0,p)=-\infty$

Overflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.

This function cannot underflow.

If you want to use a rounding mode other than Nearest, consider using Float::reciprocal_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float)::reciprocal() instead.

§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(), prec).

§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal, o) = Float::from(PI).reciprocal_prec_ref(5);
assert_eq!(reciprocal.to_string(), "0.312");
assert_eq!(o, Less);

let (reciprocal, o) = Float::from(PI).reciprocal_prec_ref(20);
assert_eq!(reciprocal.to_string(), "0.31830978");
assert_eq!(o, Less);
Source

pub fn reciprocal_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Takes the reciprocal of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal is less than, equal to, or greater than the exact reciprocal. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = 1/x+\varepsilon. $$

  • If $1/x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/x$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |1/x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $1/x$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |1/x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=0.0$
  • $f(-\infty,m)=-0.0$
  • $f(0.0,m)=\infty$
  • $f(-0.0,m)=-\infty$

Overflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.

This function cannot underflow.

If you want to specify an output precision, consider using Float::reciprocal_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float)::reciprocal() instead.

§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 rm is Exact but the precision of the input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal, o) = Float::from(PI).reciprocal_round_ref(Floor);
assert_eq!(reciprocal.to_string(), "0.31830988618379052");
assert_eq!(o, Less);

let (reciprocal, o) = Float::from(PI).reciprocal_round_ref(Ceiling);
assert_eq!(reciprocal.to_string(), "0.31830988618379097");
assert_eq!(o, Greater);

let (reciprocal, o) = Float::from(PI).reciprocal_round_ref(Nearest);
assert_eq!(reciprocal.to_string(), "0.31830988618379052");
assert_eq!(o, Less);
Source

pub fn reciprocal_sqrt_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the reciprocal of the square root of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The reciprocal square root of any nonzero negative number is NaN.

Using this function is more accurate than taking the square root and then the reciprocal, or vice versa.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = 1/\sqrt{x}+\varepsilon. $$

  • If $1/\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/\sqrt{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 1/\sqrt{x}\rfloor-p+1}$.
  • If $1/\sqrt{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 1/\sqrt{x}\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=0.0$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(0.0,p,m)=\infty$
  • $f(-0.0,p,m)=\infty$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::reciprocal_sqrt_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::reciprocal_sqrt_round_ref instead. If both of these things are true, consider using (&Float).reciprocal_sqrt()instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(5, Floor);
assert_eq!(reciprocal_sqrt.to_string(), "0.562");
assert_eq!(o, Less);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(5, Ceiling);
assert_eq!(reciprocal_sqrt.to_string(), "0.594");
assert_eq!(o, Greater);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(5, Nearest);
assert_eq!(reciprocal_sqrt.to_string(), "0.562");
assert_eq!(o, Less);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(20, Floor);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418896");
assert_eq!(o, Less);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(20, Ceiling);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418991");
assert_eq!(o, Greater);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_round_ref(20, Nearest);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418991");
assert_eq!(o, Greater);

This is mpfr_rec_sqrt from rec_sqrt.c, MPFR 4.3.0.

Source

pub fn reciprocal_sqrt_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes the reciprocal of the square root of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The reciprocal square root of any nonzero negative number is NaN.

Using this function is more accurate than taking the square root and then the reciprocal, or vice versa.

If the reciprocal square root is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = 1/\sqrt{x}+\varepsilon. $$

  • If $1/\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/\sqrt{x}$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 1/\sqrt{x}\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=0.0$
  • $f(-\infty,p)=\text{NaN}$
  • $f(0.0,p)=\infty$
  • $f(-0.0,p)=\infty$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::reciprocal_sqrt_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).reciprocal_sqrt() instead.

§Worst-case complexity

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

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

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

§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_ref(5);
assert_eq!(reciprocal_sqrt.to_string(), "0.562");
assert_eq!(o, Less);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_prec_ref(20);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418991");
assert_eq!(o, Greater);
Source

pub fn reciprocal_sqrt_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes the reciprocal of the square root of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded reciprocal square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The reciprocal square root of any nonzero negative number is NaN.

Using this function is more accurate than taking the square root and then the reciprocal, or vice versa.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = 1/\sqrt{x}+\varepsilon. $$

  • If $1/\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $1/\sqrt{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 1/\sqrt{x}\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $1/\sqrt{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 1/\sqrt{x}\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=0.0$
  • $f(-\infty,m)=\text{NaN}$
  • $f(0.0,m)=\infty$
  • $f(-0.0,m)=\infty$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::reciprocal_sqrt_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).reciprocal_sqrt() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_round_ref(Floor);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418958354775572");
assert_eq!(o, Less);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_round_ref(Ceiling);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418958354775661");
assert_eq!(o, Greater);

let (reciprocal_sqrt, o) = Float::from(PI).reciprocal_sqrt_round_ref(Nearest);
assert_eq!(reciprocal_sqrt.to_string(), "0.56418958354775661");
assert_eq!(o, Greater);
Source

pub fn rem_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::rem_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_round instead. If both of these things are true, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_prec_round_ref_val(Float::from(7u32), 1, Floor);
assert_eq!(r.to_string(), "2.0");
assert_eq!(o, Less);

let (r, o) = Float::from(10u32).rem_prec_round_ref_val(Float::from(7u32), 1, Ceiling);
assert_eq!(r.to_string(), "4.0");
assert_eq!(o, Greater);
Source

pub fn rem_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::rem_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_round instead. If both of these things are true, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_prec_round_ref_ref(&Float::from(7u32), 1, Floor);
assert_eq!(r.to_string(), "2.0");
assert_eq!(o, Less);

let (r, o) = Float::from(10u32).rem_prec_round_ref_ref(&Float::from(7u32), 1, Ceiling);
assert_eq!(r.to_string(), "4.0");
assert_eq!(o, Greater);
Source

pub fn rem_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::rem_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_prec_ref_val(Float::from(7u32), 1);
assert_eq!(r.to_string(), "4.0");
assert_eq!(o, Greater);

let (r, o) = Float::from(10u32).rem_prec_ref_val(Float::from(7u32), 2);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

pub fn rem_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::rem_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_prec_ref_ref(&Float::from(7u32), 1);
assert_eq!(r.to_string(), "4.0");
assert_eq!(o, Greater);

let (r, o) = Float::from(10u32).rem_prec_ref_ref(&Float::from(7u32), 2);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

pub fn rem_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_round_ref_val(Float::from(7u32), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);

let (r, o) = (-Float::from(10u32)).rem_round_ref_val(Float::from(7u32), Floor);
assert_eq!(r.to_string(), "-3.0");
assert_eq!(o, Equal);
Source

pub fn rem_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using % instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_round_ref_ref(&Float::from(7u32), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);

let (r, o) = (-Float::from(10u32)).rem_round_ref_ref(&Float::from(7u32), Floor);
assert_eq!(r.to_string(), "-3.0");
assert_eq!(o, Equal);
Source

pub fn rem_and_quotient_bits_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. (MPFR documents the same contract for its quo output, but its C implementation can overflow a long when the low 63 bits are all ones and the quotient rounds away from zero; this implementation always keeps the modular contract.)

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::rem_and_quotient_bits_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_and_quotient_bits_round instead. If both of these things are true, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(100u32);
let y = Float::from(7u32);
let (r, o, q) = x.rem_and_quotient_bits_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. (MPFR documents the same contract for its quo output, but its C implementation can overflow a long when the low 63 bits are all ones and the quotient rounds away from zero; this implementation always keeps the modular contract.)

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::rem_and_quotient_bits_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_and_quotient_bits_round instead. If both of these things are true, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(100u32);
let y = Float::from(7u32);
let (r, o, q) = x.rem_and_quotient_bits_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_prec_ref_val( &self, other: Self, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::rem_and_quotient_bits_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(100u32).rem_and_quotient_bits_prec_ref_val(Float::from(7u32), 5);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_prec_ref_ref( &self, other: &Self, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::rem_and_quotient_bits_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(100u32).rem_and_quotient_bits_prec_ref_ref(&Float::from(7u32), 5);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_and_quotient_bits_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(100u32).rem_and_quotient_bits_round_ref_val(Float::from(7u32), Floor);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_and_quotient_bits_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::rem_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(100u32).rem_and_quotient_bits_round_ref_ref(&Float::from(7u32), Floor);
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_ref_val( &self, other: Self, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_and_quotient_bits_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::rem_and_quotient_bits_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) = Float::from(100u32).rem_and_quotient_bits_ref_val(Float::from(7u32));
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn rem_and_quotient_bits_ref_ref( &self, other: &Self, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::rem_and_quotient_bits_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::rem_and_quotient_bits_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) = Float::from(100u32).rem_and_quotient_bits_ref_ref(&Float::from(7u32));
assert_eq!(r.to_string(), "2.00");
assert_eq!(o, Equal);
assert_eq!(q, 14);
Source

pub fn ieee_remainder_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::ieee_remainder_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_round instead. If both of these things are true, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) =
    Float::from(14u32).ieee_remainder_prec_round_ref_val(Float::from(3u32), 10, Nearest);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);

let (r, o) =
    Float::from(10u32).ieee_remainder_prec_round_ref_val(Float::from(7u32), 1, Floor);
assert_eq!(r.to_string(), "2.0");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::ieee_remainder_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_round instead. If both of these things are true, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) =
    Float::from(14u32).ieee_remainder_prec_round_ref_ref(&Float::from(3u32), 10, Nearest);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);

let (r, o) =
    Float::from(10u32).ieee_remainder_prec_round_ref_ref(&Float::from(7u32), 1, Floor);
assert_eq!(r.to_string(), "2.0");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_prec_ref_val( &self, other: Self, prec: u64, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o) = Float::from(14u32).ieee_remainder_prec_ref_val(Float::from(3u32), 10);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
Source

pub fn ieee_remainder_prec_ref_ref( &self, other: &Self, prec: u64, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o) = Float::from(14u32).ieee_remainder_prec_ref_ref(&Float::from(3u32), 10);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
Source

pub fn ieee_remainder_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(14u32).ieee_remainder_round_ref_val(Float::from(3u32), Floor);
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
Source

pub fn ieee_remainder_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::ieee_remainder instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(14u32).ieee_remainder_round_ref_ref(&Float::from(3u32), Floor);
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
Source

pub fn ieee_remainder_ref_val(&self, other: Self) -> Self

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use malachite_float::Float;

let r = Float::from(14u32).ieee_remainder_ref_val(Float::from(3u32));
assert_eq!(r.to_string(), "-1.0");

assert_eq!(
    Float::from(10u32)
        .ieee_remainder_ref_val(Float::from(3u32))
        .to_string(),
    "1.0"
);
Source

pub fn ieee_remainder_ref_ref(&self, other: &Self) -> Self

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use malachite_float::Float;

let r = Float::from(14u32).ieee_remainder_ref_ref(&Float::from(3u32));
assert_eq!(r.to_string(), "-1.0");

let r = Float::from(10u32).ieee_remainder_ref_ref(&Float::from(3u32));
assert_eq!(r.to_string(), "1.0");
Source

pub fn ieee_remainder_and_quotient_bits_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. (MPFR documents the same contract for its quo output, but its C implementation can overflow a long when the low 63 bits are all ones and the quotient rounds away from zero; this implementation always keeps the modular contract.)

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::ieee_remainder_and_quotient_bits_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_and_quotient_bits_round instead. If both of these things are true, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(14u32);
let y = Float::from(3u32);
let (r, o, q) = x.ieee_remainder_and_quotient_bits_prec_round_ref_val(y, 10, Floor);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. (MPFR documents the same contract for its quo output, but its C implementation can overflow a long when the low 63 bits are all ones and the quotient rounds away from zero; this implementation always keeps the modular contract.)

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::ieee_remainder_and_quotient_bits_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_and_quotient_bits_round instead. If both of these things are true, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(14u32);
let y = Float::from(3u32);
let (r, o, q) = x.ieee_remainder_and_quotient_bits_prec_round_ref_ref(&y, 10, Floor);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_prec_ref_val( &self, other: Self, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_and_quotient_bits_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(14u32).ieee_remainder_and_quotient_bits_prec_ref_val(Float::from(3u32), 10);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_prec_ref_ref( &self, other: &Self, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_and_quotient_bits_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let x = Float::from(14u32);
let y = Float::from(3u32);
let (r, o, q) = x.ieee_remainder_and_quotient_bits_prec_ref_ref(&y, 10);
assert_eq!(r.to_string(), "-1.0000");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_and_quotient_bits_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(14u32);
let y = Float::from(3u32);
let (r, o, q) = x.ieee_remainder_and_quotient_bits_round_ref_val(y, Floor);
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the maximum of the precisions of the inputs, with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_and_quotient_bits_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::ieee_remainder_and_quotient_bits instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(14u32);
let y = Float::from(3u32);
let (r, o, q) = x.ieee_remainder_and_quotient_bits_round_ref_ref(&y, Floor);
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_ref_val( &self, other: Self, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_and_quotient_bits_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_and_quotient_bits_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(14u32).ieee_remainder_and_quotient_bits_ref_val(Float::from(3u32));
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn ieee_remainder_and_quotient_bits_ref_ref( &self, other: &Self, ) -> (Self, Ordering, i64)

Computes the remainder of two Floats, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the remainder to the nearest value of the maximum of the precisions of the inputs. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or the inputs are special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,p)=f(x,\text{NaN},p)=f(\pm\infty,y,p)=f(x,\pm0.0,p) = \text{NaN}$
  • $f(x,\pm\infty,p)=x$ if $x$ is finite
  • $f(\pm0.0,y,p)=\pm0.0$ if $y$ is not NaN and $y\neq 0$
  • If the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, since it is smaller than $y$ in magnitude, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::ieee_remainder_and_quotient_bits_prec instead. If you want to use a rounding mode other than Nearest, consider using Float::ieee_remainder_and_quotient_bits_round instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o, q) =
    Float::from(14u32).ieee_remainder_and_quotient_bits_ref_ref(&Float::from(3u32));
assert_eq!(r.to_string(), "-1.0");
assert_eq!(o, Equal);
assert_eq!(q, 5);
Source

pub fn rem_unsigned_prec_round_ref( &self, other: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a u64, with the quotient rounded toward zero, rounding the remainder to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The conversion of the modulus to a Float is exact, so this behaves exactly like the corresponding rem function with Float::from(other), except that a zero modulus yields NaN (matching mpfr_fmod_ui) rather than following the Float special cases.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_unsigned_prec_round_ref(7, 1, Floor);
assert_eq!(r.to_string(), "2.0");
assert_eq!(o, Less);

let (r, o) = Float::from(10u32).rem_unsigned_prec_round_ref(7, 1, Ceiling);
assert_eq!(r.to_string(), "4.0");
assert_eq!(o, Greater);
Source

pub fn rem_unsigned_prec_ref(&self, other: u64, prec: u64) -> (Self, Ordering)

Computes the remainder of a Float by a u64, with the quotient rounded toward zero, rounding the remainder to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The conversion of the modulus to a Float is exact, so this behaves exactly like the corresponding rem function with Float::from(other), except that a zero modulus yields NaN (matching mpfr_fmod_ui) rather than following the Float special cases.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_unsigned_prec_ref(3, 10);
assert_eq!(r.to_string(), "1.0000");
assert_eq!(o, Equal);
Source

pub fn rem_unsigned_round_ref( &self, other: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a u64, with the quotient rounded toward zero, rounding the remainder to self.significant_bits() bits, with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The conversion of the modulus to a Float is exact, so this behaves exactly like the corresponding rem function with Float::from(other), except that a zero modulus yields NaN (matching mpfr_fmod_ui) rather than following the Float special cases.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let (r, o) = Float::from(10u32).rem_unsigned_round_ref(3, Floor);
assert_eq!(r.to_string(), "1.0");
assert_eq!(o, Equal);
Source

pub fn rem_unsigned_ref(&self, other: u64) -> Self

Computes the remainder of a Float by a u64, with the quotient rounded toward zero, rounding the remainder to the nearest value of self.significant_bits() bits. The Float is taken by reference.

The conversion of the modulus to a Float is exact, so this behaves exactly like the corresponding rem function with Float::from(other), except that a zero modulus yields NaN (matching mpfr_fmod_ui) rather than following the Float special cases.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use malachite_float::Float;

assert_eq!(Float::from(10u32).rem_unsigned_ref(3).to_string(), "1.0");

assert_eq!(Float::from(10u32).rem_unsigned_ref(0).to_string(), "NaN");
Source

pub fn rem_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.rem_rational_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.rem_rational_prec_round_ref_val(y, 5, Ceiling);
assert_eq!(r.to_string(), "0.594");
assert_eq!(o, Greater);
Source

pub fn rem_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.rem_rational_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.rem_rational_prec_round_ref_ref(&y, 5, Ceiling);
assert_eq!(r.to_string(), "0.594");
assert_eq!(o, Greater);
Source

pub fn rem_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(10u32).rem_rational_prec_ref_val(Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn rem_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(10u32).rem_rational_prec_ref_ref(&Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn rem_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(10u32).rem_rational_round_ref_val(Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
Source

pub fn rem_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(10u32).rem_rational_round_ref_ref(&Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
Source

pub fn rem_rational_and_quotient_bits_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. This is the same contract as the corresponding Float-Float functions.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. This is the same contract as the corresponding Float-Float functions.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_prec_ref_val(y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_prec_ref_ref(&y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_round_ref_val(y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_round_ref_ref(&y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_ref_val( &self, other: Rational, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_ref_val(y);
assert_eq!(r.to_string(), "0.62");
assert_eq!(o, Greater);
assert_eq!(q, 3);
Source

pub fn rem_rational_and_quotient_bits_ref_ref( &self, other: &Rational, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded toward zero, as for the % operator on primitive floats and C’s fmod, rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{trunc}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{trunc}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.rem_rational_and_quotient_bits_ref_ref(&y);
assert_eq!(r.to_string(), "0.62");
assert_eq!(o, Greater);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_prec_ref_val(y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_prec_ref_ref(&y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_round_ref_val(y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.ieee_remainder_rational_round_ref_ref(&y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
Source

pub fn ieee_remainder_rational_ref_val(&self, other: Rational) -> Self

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use malachite_float::Float;
use malachite_q::Rational;

let r = Float::from(10u32).ieee_remainder_rational_ref_val(Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "0.62");
Source

pub fn ieee_remainder_rational_ref_ref(&self, other: &Rational) -> Self

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use malachite_float::Float;
use malachite_q::Rational;

let r = Float::from(10u32).ieee_remainder_rational_ref_ref(&Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "0.62");
Source

pub fn ieee_remainder_rational_and_quotient_bits_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. This is the same contract as the corresponding Float-Float functions.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$. This is the same contract as the corresponding Float-Float functions.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the exact remainder is not representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) =
    x.ieee_remainder_rational_and_quotient_bits_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_prec_ref_val(y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_prec_ref_ref(&y, 5);
assert_eq!(r.to_string(), "0.562");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_round_ref_val(y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p+1}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the exact remainder is not representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_round_ref_ref(&y, Floor);
assert_eq!(r.to_string(), "0.50");
assert_eq!(o, Less);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_ref_val( &self, other: Rational, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_ref_val(y);
assert_eq!(r.to_string(), "0.62");
assert_eq!(o, Greater);
assert_eq!(q, 3);
Source

pub fn ieee_remainder_rational_and_quotient_bits_ref_ref( &self, other: &Rational, ) -> (Self, Ordering, i64)

Computes the remainder of a Float by a Rational, with the quotient rounded to the nearest integer, ties to even; this is the IEEE 754 remainder operation, C’s remainder, rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded remainder is less than, equal to, or greater than the exact remainder, along with the low bits of the quotient as an i64. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational modulus is used exactly, so the result is the correctly-rounded remainder of the exact input values. Converting the modulus to a Float first would perturb the remainder by up to the quotient times the conversion error.

The returned i64 agrees with the exact quotient $q$ in its low 63 bits and has $q$’s sign: it equals $\pm(|q|\bmod 2^{63})$.

$$ f(x,y,p) = x - y\operatorname{roundeven}(x/y) + \varepsilon. $$

  • If the exact remainder is zero or an input is special, $\varepsilon$ is 0.
  • Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |x-y\operatorname{roundeven}(x/y)|\rfloor-p}$.

Special cases:

  • $f(\text{NaN},y,p)=f(\pm\infty,y,p)=f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,y,p)=\pm0.0$ if $y\neq 0$
  • Otherwise, if the exact remainder is zero, a zero with the sign of $x$ is returned.
  • The quotient bits are 0 in all of the above special cases.

The remainder never overflows, but it can underflow, since its granularity may lie far below the minimum positive Float:

  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(10u32);
let y = Rational::from_signeds(22, 7);
let (r, o, q) = x.ieee_remainder_rational_and_quotient_bits_ref_ref(&y);
assert_eq!(r.to_string(), "0.62");
assert_eq!(o, Greater);
assert_eq!(q, 3);
Source

pub fn root_u_prec_round_ref( &self, k: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Takes the $k$th root of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p+1}$.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=\infty$
  • $f(-\infty,k,p,m)=-\infty$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p,m)=\pm0.0$ if $k$ is odd and $0.0$ if $k$ is even
  • $f(x,0,p,m)=\text{NaN}$
  • $f(x,1,p,m)=x$
  • $f(x,k,p,m)=\text{NaN}$ if $x<0$ and $k$ is even

The result never overflows or underflows: its exponent is close to the exponent of $x$ divided by $k$.

If you know you’ll be using Nearest, consider using Float::root_u_prec instead. If you know that your target precision is the precision of the input, consider using Float::root_u_round instead. If both of these things are true, consider using the Root implementation instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (root, o) = Float::from(2.0).root_u_prec_round_ref(3, 20, Floor);
assert_eq!(root.to_string(), "1.2599201");
assert_eq!(o, Less);

let (root, o) = Float::from(2.0).root_u_prec_round_ref(3, 20, Ceiling);
assert_eq!(root.to_string(), "1.2599220");
assert_eq!(o, Greater);
Source

pub fn root_u_prec_ref(&self, k: u64, prec: u64) -> (Self, Ordering)

Takes the $k$th root of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the root is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,k,p) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},k,p)=\text{NaN}$
  • $f(\infty,k,p)=\infty$
  • $f(-\infty,k,p)=-\infty$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p)=\pm0.0$ if $k$ is odd and $0.0$ if $k$ is even
  • $f(x,0,p,m)=\text{NaN}$
  • $f(x,1,p,m)=x$
  • $f(x,k,p)=\text{NaN}$ if $x<0$ and $k$ is even

The result never overflows or underflows: its exponent is close to the exponent of $x$ divided by $k$.

If you want to use a rounding mode other than Nearest, consider using Float::root_u_prec_round instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (root, o) = Float::from(2.0).root_u_prec_ref(3, 20);
assert_eq!(root.to_string(), "1.2599201");
assert_eq!(o, Less);

let (root, o) = Float::from(2.0).root_u_prec_ref(3, 53);
assert_eq!(root.to_string(), "1.2599210498948732");
assert_eq!(o, Greater);
Source

pub fn root_u_round_ref(&self, k: u64, rm: RoundingMode) -> (Self, Ordering)

Takes the $k$th root of a Float, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p+1}$.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=\infty$
  • $f(-\infty,k,p,m)=-\infty$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p,m)=\pm0.0$ if $k$ is odd and $0.0$ if $k$ is even
  • $f(x,0,p,m)=\text{NaN}$
  • $f(x,1,p,m)=x$
  • $f(x,k,p,m)=\text{NaN}$ if $x<0$ and $k$ is even

The result never overflows or underflows: its exponent is close to the exponent of $x$ divided by $k$.

§Worst-case complexity

$T(n) = O(n^{3/2} \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 rm is Exact but the result cannot be represented exactly with the input precision.

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

let x = Float::from_rational_prec(Rational::TWO, 20).0;
let (root, o) = x.root_u_round_ref(3, Floor);
assert_eq!(root.to_string(), "1.2599201");
assert_eq!(o, Less);
Source

pub fn root_s_prec_round_ref( &self, k: i64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Takes the $k$th root of a Float, where $k$ may be negative, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p+1}$.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases for $k<0$ (for $k\geq 0$ the cases are those of the unsigned version):

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=0.0$
  • $f(-\infty,k,p,m)=-0.0$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p,m)=\pm\infty$ if $k$ is odd and $\infty$ if $k$ is even
  • $f(x,k,p,m)=\text{NaN}$ if $x<0$ and $k$ is even

Overflow and underflow are possible only for $k=-1$ (the reciprocal); for other $k$ the result’s exponent is close to the exponent of $x$ divided by $k$, always within range.

If you know you’ll be using Nearest, consider using Float::root_s_prec instead. If you know that your target precision is the precision of the input, consider using Float::root_s_round instead. If both of these things are true, consider using the Root implementation instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

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

let (root, o) = Float::from(2.0).root_s_prec_round_ref(-3, 20, Floor);
assert_eq!(root.to_string(), "0.79370022");
assert_eq!(o, Less);

let (root, o) = Float::from(2.0).root_s_prec_round_ref(-3, 20, Ceiling);
assert_eq!(root.to_string(), "0.79370117");
assert_eq!(o, Greater);
Source

pub fn root_s_prec_ref(&self, k: i64, prec: u64) -> (Self, Ordering)

Takes the $k$th root of a Float, where $k$ may be negative, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the root is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,k,p) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases for $k<0$ (for $k\geq 0$ the cases are those of the unsigned version):

  • $f(\text{NaN},k,p)=\text{NaN}$
  • $f(\infty,k,p)=0.0$
  • $f(-\infty,k,p)=-0.0$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p)=\pm\infty$ if $k$ is odd and $\infty$ if $k$ is even
  • $f(x,k,p)=\text{NaN}$ if $x<0$ and $k$ is even

Overflow and underflow are possible only for $k=-1$ (the reciprocal); for other $k$ the result’s exponent is close to the exponent of $x$ divided by $k$, always within range.

If you want to use a rounding mode other than Nearest, consider using Float::root_s_prec_round instead.

§Worst-case complexity

$T(n, m) = O(n^{3/2} \log n \log\log n + m)$

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

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

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (root, o) = Float::from(2.0).root_s_prec_ref(-3, 53);
assert_eq!(root.to_string(), "0.79370052598409979");
assert_eq!(o, Greater);
Source

pub fn root_s_round_ref(&self, k: i64, rm: RoundingMode) -> (Self, Ordering)

Takes the $k$th root of a Float, where $k$ may be negative, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded root is less than, equal to, or greater than the exact root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,k,p,m) = \sqrt[k]{x}+\varepsilon. $$

  • If $\sqrt[k]{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p+1}$.
  • If $\sqrt[k]{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sqrt[k]{x}|\rfloor-p}$.

If the output has a precision, it is the precision of the input.

Special cases for $k<0$ (for $k\geq 0$ the cases are those of the unsigned version):

  • $f(\text{NaN},k,p,m)=\text{NaN}$
  • $f(\infty,k,p,m)=0.0$
  • $f(-\infty,k,p,m)=-0.0$ if $k$ is odd and NaN if $k$ is even
  • $f(\pm0.0,k,p,m)=\pm\infty$ if $k$ is odd and $\infty$ if $k$ is even
  • $f(x,k,p,m)=\text{NaN}$ if $x<0$ and $k$ is even

Overflow and underflow are possible only for $k=-1$ (the reciprocal); for other $k$ the result’s exponent is close to the exponent of $x$ divided by $k$, always within range.

§Worst-case complexity

$T(n) = O(n^{3/2} \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 rm is Exact but the result cannot be represented exactly with the input precision.

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

let x = Float::from_rational_prec(Rational::TWO, 20).0;
let (root, o) = x.root_s_round_ref(-3, Ceiling);
assert_eq!(root.to_string(), "0.79370117");
assert_eq!(o, Greater);
Source

pub fn round_to_integer_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering, bool)

Rounds a Float to an integer, representable at the specified precision, in the direction given by the specified rounding mode. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

The result is produced by a single rounding to an integer representable at the target precision: if the input’s integer part needs more bits than the precision provides, no intermediate integer is formed. For example, $10.5$ rounded to the nearest integer at a precision of 2 bits is $12$: not first $10$, and then $10$ rounded again. The rounding mode gives the integer-rounding direction: Floor and Ceiling are the floor and ceiling functions, Down is truncation, Up rounds away from zero, and Nearest rounds to the nearest integer with ties to even. Exact is not allowed.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero or if rm is Exact.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(2.5f64);
assert_eq!(
    x.round_to_integer_prec_round_ref(4, Floor),
    (Float::TWO, Less, false)
);
assert_eq!(
    x.round_to_integer_prec_round_ref(4, Ceiling),
    (Float::from(3u32), Greater, false)
);
assert_eq!(
    x.round_to_integer_prec_round_ref(4, Nearest),
    (Float::TWO, Less, false)
);

// A single rounding: the nearest integer to 10.5 representable at 2 bits is 12.
let x = Float::from(10.5f64);
assert_eq!(
    x.round_to_integer_prec_round_ref(2, Nearest),
    (Float::from(12u32), Greater, false)
);

// 7 is an integer, but needs rounding to fit 2 bits.
let x = Float::from(7u32);
assert_eq!(
    x.round_to_integer_prec_round_ref(2, Nearest),
    (Float::from(8u32), Greater, true)
);
Source

pub fn round_to_integer_prec_ref(&self, prec: u64) -> (Self, Ordering, bool)

Rounds a Float to the nearest integer representable at the specified precision, with ties going to even. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

The result is produced by a single rounding to an integer representable at the target precision: if the input’s integer part needs more bits than the precision provides, no intermediate integer is formed. For example, $10.5$ rounded to the nearest integer at a precision of 2 bits is $12$: not first $10$, and then $10$ rounded again.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;

let x = Float::from(2.5f64);
assert_eq!(x.round_to_integer_prec_ref(4), (Float::TWO, Less, false));
assert_eq!(
    Float::from(4u32).round_to_integer_prec(2),
    (Float::from(4u32), Equal, true)
);
Source

pub fn round_to_integer_round_ref( &self, rm: RoundingMode, ) -> (Self, Ordering, bool)

Rounds a Float to an integer, representable at the input’s own precision, in the direction given by the specified rounding mode. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

The rounding mode gives the integer-rounding direction: Floor and Ceiling are the floor and ceiling functions, Down is truncation, Up rounds away from zero, and Nearest rounds to the nearest integer with ties to even. Exact is not allowed.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§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 rm is Exact.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(2.5f64);
assert_eq!(
    x.round_to_integer_round_ref(Ceiling),
    (Float::from(3u32), Greater, false)
);
assert_eq!(
    x.round_to_integer_round_ref(Floor),
    (Float::TWO, Less, false)
);
Source

pub fn round_to_integer_ref(&self) -> (Self, Ordering, bool)

Rounds a Float to the nearest integer representable at the input’s own precision, with ties going to even. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§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

Never panics.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::basic::traits::Two;
use malachite_float::Float;

// ties to even
let x = Float::from(2.5f64);
assert_eq!(x.round_to_integer_ref(), (Float::TWO, Less, false));
Source

pub fn round_to_integer_ties_away_prec_ref( &self, prec: u64, ) -> (Self, Ordering, bool)

Rounds a Float to the nearest integer representable at the specified precision, with ties going away from zero. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

The result is produced by a single rounding to an integer representable at the target precision: if the input’s integer part needs more bits than the precision provides, no intermediate integer is formed. For example, $10.5$ rounded to the nearest integer at a precision of 2 bits is $12$: not first $10$, and then $10$ rounded again. Ties round away from zero, as in IEEE 754’s roundTiesToAway and MPFR’s mpfr_round; the other integer-rounding directions are available through Float::round_to_integer_prec_round.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

// ties away from zero
let x = Float::from(2.5f64);
assert_eq!(
    x.round_to_integer_ties_away_prec_ref(4),
    (Float::from(3u32), Greater, false)
);
Source

pub fn round_to_integer_ties_away_ref(&self) -> (Self, Ordering, bool)

Rounds a Float to the nearest integer representable at the input’s own precision, with ties going away from zero. An Ordering comparing the result to the exact input is also returned, along with a bool indicating whether the input was an integer. The Float is taken by reference.

Ties round away from zero, as in IEEE 754’s roundTiesToAway and MPFR’s mpfr_round; the other integer-rounding directions are available through Float::round_to_integer_prec_round.

The pair of the Ordering and the bool carries the same information as mpfr_rint’s ternary value: (Equal, true) means the input was an integer representable at the target precision, returned unchanged; (Less, true) and (Greater, true) mean the input was an integer that required rounding to fit the precision; (Less, false) and (Greater, false) mean the input was not an integer. (Equal, false) cannot occur.

NaNs, infinities, and zeros are returned unchanged with Equal; of these, only zeros are considered integers.

If rounding away from zero at the maximum exponent produces an integer too large to represent, the result is $\pm\infty$.

§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

Never panics.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;

// ties away from zero
let x = Float::from(2.5f64);
assert_eq!(
    x.round_to_integer_ties_away_ref(),
    (Float::from(3u32), Greater, false)
);
Source

pub fn round_to_integer_then_prec_round_ref( &self, irm: RoundingMode, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Rounds a Float to an integer in the direction irm, and then correctly rounds that exact integer to the specified precision with rm. An Ordering comparing the result to the exact integer is also returned. The Float is taken by reference.

Unlike Float::round_to_integer_prec_round, which rounds once, this function is the composition of two roundings, matching MPFR’s mpfr_rint_-prefixed functions: the exact integer is formed first, then rounded to the target precision. The two can differ: under this function with both modes Nearest, $10.5$ becomes $10$, which then rounds to $8$ at a precision of 2 bits, while the single-rounding form gives $12$.

NaNs, infinities, and non-integer-producing specials pass through the final rounding only. If the integer overflows the exponent range, the result follows rm: $\pm\infty$ for the modes rounding away from zero, and the maximum finite value at the target precision for the modes rounding toward zero.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, if irm is Exact, or if rm is Exact and the integer is not exactly representable at the target precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(10.5f64);
assert_eq!(
    x.round_to_integer_then_prec_round_ref(Nearest, 2, Nearest),
    (Float::from(8u32), Less)
);
assert_eq!(
    Float::from(2.5f64).round_to_integer_then_prec_round_ref(Ceiling, 10, Nearest),
    (Float::from(3u32), Equal)
);
Source

pub fn round_to_integer_ties_away_then_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Rounds a Float to the nearest integer with ties going away from zero, and then correctly rounds that exact integer to the specified precision with rm. An Ordering comparing the result to the exact integer is also returned. The Float is taken by reference.

Unlike Float::round_to_integer_prec_round, which rounds once, this function is the composition of two roundings, matching MPFR’s mpfr_rint_-prefixed functions: the exact integer is formed first, then rounded to the target precision. The two can differ: under this function with both modes Nearest, $10.5$ becomes $10$, which then rounds to $8$ at a precision of 2 bits, while the single-rounding form gives $12$.

NaNs, infinities, and non-integer-producing specials pass through the final rounding only. If the integer overflows the exponent range, the result follows rm: $\pm\infty$ for the modes rounding away from zero, and the maximum finite value at the target precision for the modes rounding toward zero.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the integer is not exactly representable at the target precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

let x = Float::from(10.5f64);
assert_eq!(
    x.round_to_integer_ties_away_then_prec_round_ref(2, Nearest),
    (Float::from(12u32), Greater)
);
Source

pub fn sec_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sec x$, the secant of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \sec x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sec x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sec x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=1.0$

Overflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Underflow is not possible, since $|\sec x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you know you’ll be using Nearest, consider using Float::sec_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::sec_round_ref instead. If both of these things are true, consider using (&Float).sec() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the cosine at working precision $n$, summed by binary splitting of the Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, sec therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the secant of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "1.81");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "1.88");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "1.88");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "1.8508148");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "1.8508167");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "1.8508148");
assert_eq!(o, Less);
Source

pub fn sec_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\sec x$, the secant of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the secant is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \sec x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\sec x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=1.0$

Overflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.

Underflow is not possible, since $|\sec x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you want to use a rounding mode other than Nearest, consider using Float::sec_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).sec() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the cosine at working precision $n$, summed by binary splitting of the Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, sec therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_ref(5);
assert_eq!(c.to_string(), "1.88");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_prec_ref(20);
assert_eq!(c.to_string(), "1.8508148");
assert_eq!(o, Less);
Source

pub fn sec_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\sec x$, the secant of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \sec x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sec x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sec x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=1.0$

Overflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.

Underflow is not possible, since $|\sec x| \geq 1$. Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, which takes more than $2^{30}$ bits of precision.

If you want to specify an output precision, consider using Float::sec_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).sec() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, sec therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the secant of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_round_ref(Floor);
assert_eq!(c.to_string(), "1.8508157176809256179117532413979");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_round_ref(Ceiling);
assert_eq!(c.to_string(), "1.8508157176809256179117532413995");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sec_round_ref(Nearest);
assert_eq!(c.to_string(), "1.8508157176809256179117532413979");
assert_eq!(o, Less);
Source

pub fn sec_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sec(2\pi x/u)$, the secant of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::sec_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.sec_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(t.to_string(), "1.6035");
assert_eq!(o, Less);
Source

pub fn sec_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\sec(2\pi x/u)$, the secant of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::sec_with_period_prec and Float::sec_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.sec_with_period_prec_ref(7, 10);
assert_eq!(t.to_string(), "1.6035");
assert_eq!(o, Less);
Source

pub fn sec_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sec(2\pi x/u)$, the secant of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::sec_with_period_round and Float::sec_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (t, o) = Float::from_unsigned_prec(1u32, 10)
    .0
    .sec_with_period_round_ref(7, Floor);
assert_eq!(t.to_string(), "1.6035");
assert_eq!(o, Less);
Source

pub fn sec_with_period_ref(&self, u: u64) -> Self

Computes $\sec(2\pi x/u)$, the secant of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the secant is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::sec_with_period_prec_round for the error bounds, the special and closed-form cases, overflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::sec_with_period_round_ref instead. If you want to specify an output precision, consider using Float::sec_with_period_prec_ref. If you want both of these things, consider using Float::sec_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from_unsigned_prec(1u32, 10).0).sec_with_period_ref(7);
assert_eq!(t.to_string(), "1.6035");
Source

pub fn sec_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sec(\pi x)$, the secant of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sec_with_period with a period of 2: see Float::sec_with_period_prec_round_ref for the error bounds, the special and closed-form cases (even integers give $1$ and odd ones $-1$; half-integers are poles and give $\infty$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ give $\pm2$; and odd multiples of $1/6$, and multiples of $1/5$ and $1/10$, give $\pm2\sqrt3/3$, $\pm2\varphi$, or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).sec_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "1.0508");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).sec_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "1.0527");
assert_eq!(o, Greater);

// a half-turn is exactly zero, reached from below
let (t, o) = (&Float::ONE).sec_pi_prec_round_ref(10, Exact);
assert_eq!(t.to_string(), "-1.0000");
assert_eq!(o, Equal);
Source

pub fn sec_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\sec(\pi x)$, the secant of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sec_with_period with a period of 2: see Float::sec_with_period_prec_ref for the error bounds, the special and closed-form cases (even integers give $1$ and odd ones $-1$; half-integers are poles and give $\infty$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ give $\pm2$; and odd multiples of $1/6$, and multiples of $1/5$ and $1/10$, give $\pm2\sqrt3/3$, $\pm2\varphi$, or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).sec_pi_prec_ref(10);
assert_eq!(t.to_string(), "1.0508");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).sec_pi_prec_ref(53);
assert_eq!(t.to_string(), "1.0514622242382672");
assert_eq!(o, Less);
Source

pub fn sec_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\sec(\pi x)$, the secant of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded secant is less than, equal to, or greater than the exact secant. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sec_with_period with a period of 2: see Float::sec_with_period_round_ref for the error bounds, the special and closed-form cases (even integers give $1$ and odd ones $-1$; half-integers are poles and give $\infty$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ give $\pm2$; and odd multiples of $1/6$, and multiples of $1/5$ and $1/10$, give $\pm2\sqrt3/3$, $\pm2\varphi$, or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (t, o) = (Float::from(0.1f64)).sec_pi_round_ref(Floor);
assert_eq!(t.to_string(), "1.0514622242382670");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).sec_pi_round_ref(Nearest);
assert_eq!(t.to_string(), "1.0514622242382674");
assert_eq!(o, Greater);
Source

pub fn sec_pi_ref(&self) -> Self

Computes $\sec(\pi x)$, the secant of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the secant is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is sec_with_period with a period of 2: see Float::sec_with_period for the error bounds, the special and closed-form cases (even integers give $1$ and odd ones $-1$; half-integers are poles and give $\infty$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ give $\pm2$; and odd multiples of $1/6$, and multiples of $1/5$ and $1/10$, give $\pm2\sqrt3/3$, $\pm2\varphi$, or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::sec_pi_round_ref instead. If you want to specify an output precision, consider using Float::sec_pi_prec_ref. If you want both of these things, consider using Float::sec_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from(0.1f64)).sec_pi_ref();
assert_eq!(t.to_string(), "1.0514622242382674");
Source

pub fn shl_prec_round_ref<T: PrimitiveInt>( &self, bits: T, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Left-shifts a Float (multiplies it by a power of 2), rounding the result with the specified rounding mode and precision, and taking the Float by reference.

NaN, infinities, and zeros are unchanged. If the output has a precision, it is prec.

$$ f(x,k,p,m) = x2^k. $$

  • If $f(x,k,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,k,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,k,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,k,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is prec.
  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,k,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::shl_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::shl_round instead. If both of these things are true, or you don’t care about overflow or underflow behavior, consider using << instead.

§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 rm is Exact and the result overflows or underflows, or cannot be expressed exactly with the specified precision.

§Examples

See here.

Source

pub fn shl_prec_ref<T: PrimitiveInt>( &self, bits: T, prec: u64, ) -> (Self, Ordering)

Left-shifts a Float (multiplies it by a power of 2), rounding the result with the specified precision, and taking the Float by reference.

NaN, infinities, and zeros are unchanged. If the output has a precision, it is prec.

$$ f(x,k,p) = x2^k. $$

  • If $f(x,k,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,k,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,k,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know that your target precision is the precision of the input, or you don’t care about overflow or underflow behavior, consider using << instead.

§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

See here.

Source

pub fn shr_prec_round_ref<T: PrimitiveInt>( &self, bits: T, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Right-shifts a Float (divides it by a power of 2), rounding the result with the specified rounding mode and precision, and taking the Float by reference.

NaN, infinities, and zeros are unchanged. If the output has a precision, it is prec.

$$ f(x,k,p,m) = x/2^k. $$

  • If $f(x,k,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,k,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,k,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,k,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is prec.
  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,k,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::shr_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::shr_round instead. If both of these things are true, or you don’t care about overflow or underflow behavior, consider using >> instead.

§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 rm is Exact and the result overflows or underflows, or cannot be expressed exactly with the specified precision.

§Examples

See here.

Source

pub fn shr_prec_ref<T: PrimitiveInt>( &self, bits: T, prec: u64, ) -> (Self, Ordering)

Right-shifts a Float (divides it by a power of 2), rounding the result with the specified precision, and taking the Float by reference.

NaN, infinities, and zeros are unchanged. If the output has a precision, it is prec.

$$ f(x,k,p) = x/2^k. $$

  • If $f(x,k,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,k,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,k,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,k,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,k,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,k,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you know that your target precision is the precision of the input, or you don’t care about overflow or underflow behavior, consider using >> instead.

§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

See here.

Source

pub fn sin_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sin x$, the sine of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \sin x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sin x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm0.0$

Overflow and underflow:

  • Since $|\sin x|\leq 1$, the result never overflows.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you know you’ll be using Nearest, consider using Float::sin_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::sin_round_ref instead. If both of these things are true, consider using (&Float).sin() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived) cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, sin therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the sine of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "0.812");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "0.844");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "0.844");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "0.84147072");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "0.84147167");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "0.84147072");
assert_eq!(o, Less);
Source

pub fn sin_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\sin x$, the sine of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sine is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \sin x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=1.0$

Overflow and underflow:

  • Since $|\sin x|\leq 1$, the result never overflows.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you want to use a rounding mode other than Nearest, consider using Float::sin_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).sin() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived) cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, sin therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_ref(5);
assert_eq!(c.to_string(), "0.844");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_prec_ref(20);
assert_eq!(c.to_string(), "0.84147072");
assert_eq!(o, Less);
Source

pub fn sin_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\sin x$, the sine of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \sin x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sin x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=1.0$

Overflow and underflow:

  • Since $|\sin x|\leq 1$, the result never overflows.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of precision, or an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you want to specify an output precision, consider using Float::sin_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).sin() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, sin therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the sine of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_round_ref(Floor);
assert_eq!(c.to_string(), "0.84147098480789650665250232163005");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_round_ref(Ceiling);
assert_eq!(c.to_string(), "0.84147098480789650665250232163084");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).sin_round_ref(Nearest);
assert_eq!(c.to_string(), "0.84147098480789650665250232163005");
assert_eq!(o, Less);
Source

pub fn sin_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sin(2\pi x/u)$, the sine of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,u,p,m) = \sin(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, $u\neq 0$, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin(2\pi x/u)|\rfloor-p+1}$.
  • If $x$ is finite, $u\neq 0$, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sin(2\pi x/u)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},u,p,m)=\text{NaN}$
  • $f(\pm\infty,u,p,m)=\text{NaN}$
  • $f(x,0,p,m)=\text{NaN}$
  • $f(\pm0.0,u,p,m)=\pm0.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $0.0$ with the sign of $x$ (following IEEE 754-2019’s sinPi, so that the function is odd); if it is an odd multiple of $1/4$, the result is exactly $1$ or $-1$; and if it is $\pm1/12$ or $\pm5/12$ modulo $1$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 3, 6, 8, or 20, the result is $\pm\sqrt3/2$, $\pm\sqrt2/2$, $\pm\varphi/2$, or $\pm(\varphi-1)/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a sine, which is far faster.

Overflow and underflow:

  • Since $|\sin(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,u,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of a multiple of $1/2$ without being one, which takes more than $2^{30}$ bits of precision, or an $x$ so small that $2\pi x/u$ is below $2^{-2^{30}}$.

If you know you’ll be using Nearest, consider using Float::sin_with_period_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::sin_with_period_round_ref instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the sine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision (which is the case unless $x/u$ is a multiple of $1/4$, or is $\pm1/12$ or $\pm5/12$ modulo $1$, or $x$ is zero or not finite, or $u$ is zero).

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::ONE).sin_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(c.to_string(), "0.78125");
assert_eq!(o, Less);

let (c, o) = (&Float::ONE).sin_with_period_prec_round_ref(7, 10, Ceiling);
assert_eq!(c.to_string(), "0.78223");
assert_eq!(o, Greater);

let (c, o) = (&Float::ONE).sin_with_period_prec_round_ref(7, 10, Nearest);
assert_eq!(c.to_string(), "0.78223");
assert_eq!(o, Greater);

// a twelfth of a turn is exact
let (c, o) = (&Float::from(30u32)).sin_with_period_prec_round_ref(360, 10, Exact);
assert_eq!(c.to_string(), "0.50000");
assert_eq!(o, Equal);

// a half turn is exactly zero
let (c, o) = (&Float::from(180u32)).sin_with_period_prec_round_ref(360, 10, Nearest);
assert_eq!(c.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn sin_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\sin(2\pi x/u)$, the sine of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the sine is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,u,p) = \sin(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $u\neq 0$, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin(2\pi x/u)|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},u,p)=\text{NaN}$
  • $f(\pm\infty,u,p)=\text{NaN}$
  • $f(x,0,p)=\text{NaN}$
  • $f(\pm0.0,u,p)=\pm0.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $0.0$ with the sign of $x$ (following IEEE 754-2019’s sinPi, so that the function is odd); if it is an odd multiple of $1/4$, the result is exactly $1$ or $-1$; and if it is $\pm1/12$ or $\pm5/12$ modulo $1$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 3, 6, 8, or 20, the result is $\pm\sqrt3/2$, $\pm\sqrt2/2$, $\pm\varphi/2$, or $\pm(\varphi-1)/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a sine, which is far faster.

Overflow and underflow:

  • Since $|\sin(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of a multiple of $1/2$ without being one, which takes more than $2^{30}$ bits of precision, or an $x$ so small that $2\pi x/u$ is below $2^{-2^{30}}$.

If you want to use a rounding mode other than Nearest, consider using Float::sin_with_period_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using Float::sin_with_period_round_ref with Nearest instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the sine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::ONE).sin_with_period_prec_ref(7, 10);
assert_eq!(c.to_string(), "0.78223");
assert_eq!(o, Greater);

let (c, o) = (&Float::ONE).sin_with_period_prec_ref(360, 53);
assert_eq!(c.to_string(), "0.017452406437283512");
assert_eq!(o, Less);

// an eighth of a turn: sqrt(2)/2
let (c, o) = (&Float::ONE).sin_with_period_prec_ref(8, 10);
assert_eq!(c.to_string(), "0.70703");
assert_eq!(o, Less);
Source

pub fn sin_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sin(2\pi x/u)$, the sine of a Float measured in $u$ths of a turn, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,u,m) = \sin(2\pi x/u)+\varepsilon. $$

  • If $x$ is not finite or $u=0$, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, $u\neq 0$, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\sin(2\pi x/u)|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite, $u\neq 0$, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\sin(2\pi x/u)|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},u,m)=\text{NaN}$
  • $f(\pm\infty,u,m)=\text{NaN}$
  • $f(x,0,m)=\text{NaN}$
  • $f(\pm0.0,u,m)=\pm0.0$
  • If $x/u$ is a multiple of $1/2$, the result is exactly $0.0$ with the sign of $x$ (following IEEE 754-2019’s sinPi, so that the function is odd); if it is an odd multiple of $1/4$, the result is exactly $1$ or $-1$; and if it is $\pm1/12$ or $\pm5/12$ modulo $1$, the result is exactly $1/2$ or $-1/2$.

When $x/u$ in lowest terms has denominator 3, 6, 8, or 20, the result is $\pm\sqrt3/2$, $\pm\sqrt2/2$, $\pm\varphi/2$, or $\pm(\varphi-1)/2$, and is computed from a single correctly rounded constant rather than from $\pi$ and a sine, which is far faster.

Overflow and underflow:

  • Since $|\sin(2\pi x/u)|\leq 1$, the result never overflows.
  • If $0<f(x,u,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,u,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,u,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,u,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,u,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,u,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Underflow requires $x/u$ within $2^{-2^{30}}$ of a multiple of $1/2$ without being one, which takes more than $2^{30}$ bits of precision, or an $x$ so small that $2\pi x/u$ is below $2^{-2^{30}}$.

If you want to specify an output precision, consider using Float::sin_with_period_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using Float::sin_with_period_prec_ref with the input’s precision instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the argument is reduced modulo $u$ exactly, and the sine of $2\pi x/u$ is then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many bits.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision (which is the case unless $x/u$ is a multiple of $1/4$ or $1/6$, or $x$ is zero or not finite, or $u$ is zero).

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).sin_with_period_round_ref(7, Floor);
assert_eq!(c.to_string(), "0.78125");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).sin_with_period_round_ref(7, Ceiling);
assert_eq!(c.to_string(), "0.78223");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 10).0).sin_with_period_round_ref(7, Nearest);
assert_eq!(c.to_string(), "0.78223");
assert_eq!(o, Greater);
Source

pub fn sin_with_period_ref(&self, u: u64) -> Self

Computes $\sin(2\pi x/u)$, the sine of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the sine is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::sin_with_period_prec_round for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::sin_with_period_round_ref instead. If you want to specify an output precision, consider using Float::sin_with_period_prec_ref. If you want both of these things, consider using Float::sin_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let s = (&Float::from_unsigned_prec(1u32, 10).0).sin_with_period_ref(7);
assert_eq!(s.to_string(), "0.78223");
Source

pub fn sin_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\sin(\pi x)$, the sine of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sin_with_period with a period of 2: see Float::sin_with_period_prec_round_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$ with the sign of the input, half-integers give $\pm1$, odd multiples of $1/6$ give $\pm1/2$, and multiples of $1/3$, $1/4$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (Float::from(0.1f64)).sin_pi_prec_round_ref(10, Floor);
assert_eq!(c.to_string(), "0.30859");
assert_eq!(o, Less);

let (c, o) = (Float::from(0.1f64)).sin_pi_prec_round_ref(10, Ceiling);
assert_eq!(c.to_string(), "0.30908");
assert_eq!(o, Greater);

// a half-turn is exactly zero
let (c, o) = (&Float::ONE).sin_pi_prec_round_ref(10, Exact);
assert_eq!(c.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn sin_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\sin(\pi x)$, the sine of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sin_with_period with a period of 2: see Float::sin_with_period_prec_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$ with the sign of the input, half-integers give $\pm1$, odd multiples of $1/6$ give $\pm1/2$, and multiples of $1/3$, $1/4$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (Float::from(0.1f64)).sin_pi_prec_ref(10);
assert_eq!(c.to_string(), "0.30908");
assert_eq!(o, Greater);

let (c, o) = (Float::from(0.1f64)).sin_pi_prec_ref(53);
assert_eq!(c.to_string(), "0.30901699437494745");
assert_eq!(o, Greater);
Source

pub fn sin_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\sin(\pi x)$, the sine of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded sine is less than, equal to, or greater than the exact sine. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is sin_with_period with a period of 2: see Float::sin_with_period_round_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$ with the sign of the input, half-integers give $\pm1$, odd multiples of $1/6$ give $\pm1/2$, and multiples of $1/3$, $1/4$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (c, o) = (Float::from(0.1f64)).sin_pi_round_ref(Floor);
assert_eq!(c.to_string(), "0.30901699437494734");
assert_eq!(o, Less);

let (c, o) = (Float::from(0.1f64)).sin_pi_round_ref(Nearest);
assert_eq!(c.to_string(), "0.30901699437494745");
assert_eq!(o, Greater);
Source

pub fn sin_pi_ref(&self) -> Self

Computes $\sin(\pi x)$, the sine of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the sine is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is sin_with_period with a period of 2: see Float::sin_with_period for the error bounds, the special and closed-form cases (integers give $\pm0.0$ with the sign of the input, half-integers give $\pm1$, odd multiples of $1/6$ give $\pm1/2$, and multiples of $1/3$, $1/4$, and $1/10$ have closed forms), overflow and underflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::sin_pi_round_ref instead. If you want to specify an output precision, consider using Float::sin_pi_prec_ref. If you want both of these things, consider using Float::sin_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let s = (&Float::from(0.1f64)).sin_pi_ref();
assert_eq!(s.to_string(), "0.30901699437494745");
Source

pub fn sin_cos_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin x$ and $\cos x$, the sine and cosine of a Float, together, rounding both results to the specified precision and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values.

See Float::sin_cos_prec_round for the error bounds, the special cases, overflow and underflow, and the complexity; this function behaves the same way.

§Panics

Panics if rm is Exact, since the sine and cosine of a finite nonzero Float are never exactly representable, or if prec is zero.

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

let x = Float::from_unsigned_prec(1u32, 100).0;
let (s, c, o_s, o_c) = x.sin_cos_prec_round_ref(5, Floor);
assert_eq!(s.to_string(), "0.812");
assert_eq!(c.to_string(), "0.531");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);

let (s, c, o_s, o_c) = x.sin_cos_prec_round_ref(20, Nearest);
assert_eq!(s.to_string(), "0.84147072");
assert_eq!(c.to_string(), "0.54030228");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_prec_ref(&self, prec: u64) -> (Self, Self, Ordering, Ordering)

Computes $\sin x$ and $\cos x$, the sine and cosine of a Float, together, rounding both results to the nearest value of the specified precision. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values.

See Float::sin_cos_prec and Float::sin_cos_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (s, c, o_s, o_c) = Float::from_unsigned_prec(1u32, 100).0.sin_cos_prec_ref(5);
assert_eq!(s.to_string(), "0.844");
assert_eq!(c.to_string(), "0.531");
assert_eq!(o_s, Greater);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_round_ref( &self, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin x$ and $\cos x$, the sine and cosine of a Float, together, rounding both results to the precision of the input and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values.

See Float::sin_cos_round and Float::sin_cos_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact, since the sine and cosine of a finite nonzero Float are never exactly representable.

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

let (s, c, o_s, o_c) = Float::from_unsigned_prec(1u32, 5)
    .0
    .sin_cos_round_ref(Floor);
assert_eq!(s.to_string(), "0.812");
assert_eq!(c.to_string(), "0.531");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin(2\pi x/u)$ and $\cos(2\pi x/u)$, the sine and cosine of a Float measured in $u$ths of a turn, together, rounding both results to the specified precision and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

See Float::sin_cos_with_period_prec_round for the error bounds, the special cases, overflow and underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the results cannot be represented exactly with the given precision (which is the case unless $x/u$ is a multiple of $1/4$, or $x$ is zero or not finite, or $u$ is zero).

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (s, c, o_s, o_c) = Float::ONE.sin_cos_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(s.to_string(), "0.78125");
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);

let (s, c, o_s, o_c) = Float::ONE.sin_cos_with_period_prec_round_ref(7, 10, Ceiling);
assert_eq!(s.to_string(), "0.78223");
assert_eq!(c.to_string(), "0.62402");
assert_eq!(o_s, Greater);
assert_eq!(o_c, Greater);
Source

pub fn sin_cos_with_period_prec_ref( &self, u: u64, prec: u64, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin(2\pi x/u)$ and $\cos(2\pi x/u)$, the sine and cosine of a Float measured in $u$ths of a turn, together, rounding both results to the nearest value of the specified precision. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

See Float::sin_cos_with_period_prec and Float::sin_cos_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (s, c, o_s, o_c) = Float::ONE.sin_cos_with_period_prec_ref(7, 10);
assert_eq!(s.to_string(), "0.78223");
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o_s, Greater);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin(2\pi x/u)$ and $\cos(2\pi x/u)$, the sine and cosine of a Float measured in $u$ths of a turn, together, rounding both results to the precision of the input and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

See Float::sin_cos_with_period_round and Float::sin_cos_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the results cannot be represented exactly with the precision of the input (which is the case unless $x/u$ is a multiple of $1/4$, or $x$ is zero or not finite, or $u$ is zero).

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

let (s, c, o_s, o_c) = Float::from_unsigned_prec(1u32, 10)
    .0
    .sin_cos_with_period_round_ref(7, Floor);
assert_eq!(s.to_string(), "0.78125");
assert_eq!(c.to_string(), "0.62305");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_with_period_ref(&self, u: u64) -> (Self, Self)

Computes $\sin(2\pi x/u)$ and $\cos(2\pi x/u)$, the sine and cosine of a Float measured in $u$ths of a turn (so that u = 360 is degrees), together, rounding both results to the precision of the input and to the nearest Floats. The Float is taken by reference.

If either result is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::sin_cos_with_period_prec_round for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::sin_cos_with_period_round_ref instead. If you want to specify an output precision, consider using Float::sin_cos_with_period_prec_ref. If you want both of these things, consider using Float::sin_cos_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let (s, c) = (&Float::from_unsigned_prec(1u32, 10).0).sin_cos_with_period_ref(7);
assert_eq!(s.to_string(), "0.78223");
assert_eq!(c.to_string(), "0.62305");
Source

pub fn sin_cos_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin(\pi x)$ and $\cos(\pi x)$, the sine and cosine of a Float measured in half-turns, together, rounding both results to the specified precision and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

This is sin_cos_with_period with a period of 2: see Float::sin_cos_with_period_prec_round_ref for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the results cannot be represented exactly with the given precision.

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

let (s, c, o_s, o_c) = Float::from(0.1f64).sin_cos_pi_prec_round_ref(10, Floor);
assert_eq!(s.to_string(), "0.30859");
assert_eq!(c.to_string(), "0.95020");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_pi_prec_ref(&self, prec: u64) -> (Self, Self, Ordering, Ordering)

Computes $\sin(\pi x)$ and $\cos(\pi x)$, the sine and cosine of a Float measured in half-turns, together, rounding both results to the nearest value of the specified precision. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

This is sin_cos_with_period with a period of 2: see Float::sin_cos_with_period_prec_ref for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (s, c, o_s, o_c) = Float::from(0.1f64).sin_cos_pi_prec_ref(10);
assert_eq!(s.to_string(), "0.30908");
assert_eq!(c.to_string(), "0.95117");
assert_eq!(o_s, Greater);
assert_eq!(o_c, Greater);
Source

pub fn sin_cos_pi_round_ref( &self, rm: RoundingMode, ) -> (Self, Self, Ordering, Ordering)

Computes $\sin(\pi x)$ and $\cos(\pi x)$, the sine and cosine of a Float measured in half-turns, together, rounding both results to the precision of the input and with the specified rounding mode. The Float is taken by reference. Two Orderings are also returned, indicating whether the rounded sine and cosine are less than, equal to, or greater than the exact values. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal for it.

This is sin_cos_with_period with a period of 2: see Float::sin_cos_with_period_round_ref for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the results cannot be represented exactly with the precision of the input.

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

let (s, c, o_s, o_c) = Float::from(0.1f64).sin_cos_pi_round_ref(Floor);
assert_eq!(s.to_string(), "0.30901699437494734");
assert_eq!(c.to_string(), "0.95105651629515342");
assert_eq!(o_s, Less);
assert_eq!(o_c, Less);
Source

pub fn sin_cos_pi_ref(&self) -> (Self, Self)

Computes $\sin(\pi x)$ and $\cos(\pi x)$, the sine and cosine of a Float measured in half-turns, together, rounding both results to the precision of the input and to the nearest Floats. The Float is taken by reference.

If either result is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is sin_cos_with_period with a period of 2: see Float::sin_cos_with_period for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::sin_cos_pi_round_ref instead. If you want to specify an output precision, consider using Float::sin_cos_pi_prec_ref. If you want both of these things, consider using Float::sin_cos_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let (s, c) = (&Float::from(0.1f64)).sin_cos_pi_ref();
assert_eq!(s.to_string(), "0.30901699437494745");
assert_eq!(c.to_string(), "0.95105651629515364");
Source

pub fn sqrt_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the square root of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The square root of any nonzero negative number is NaN.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \sqrt{x}+\varepsilon. $$

  • If $\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x}\rfloor-p+1}$.
  • If $\sqrt{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x}\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\infty,p,m)=\infty$
  • $f(-\infty,p,m)=\text{NaN}$
  • $f(0.0,p,m)=0.0$
  • $f(-0.0,p,m)=-0.0$

Neither overflow nor underflow is possible.

If you know you’ll be using Nearest, consider using Float::sqrt_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::sqrt_round_ref instead. If both of these things are true, consider using (&Float).sqrt()instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(5, Floor);
assert_eq!(sqrt.to_string(), "1.75");
assert_eq!(o, Less);

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(5, Ceiling);
assert_eq!(sqrt.to_string(), "1.81");
assert_eq!(o, Greater);

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(5, Nearest);
assert_eq!(sqrt.to_string(), "1.75");
assert_eq!(o, Less);

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(20, Floor);
assert_eq!(sqrt.to_string(), "1.7724533");
assert_eq!(o, Less);

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(20, Ceiling);
assert_eq!(sqrt.to_string(), "1.7724552");
assert_eq!(o, Greater);

let (sqrt, o) = Float::from(PI).sqrt_prec_round_ref(20, Nearest);
assert_eq!(sqrt.to_string(), "1.7724533");
assert_eq!(o, Less);
Source

pub fn sqrt_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes the square root of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The square root of any nonzero negative number is NaN.

If the square root is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \sqrt{x}+\varepsilon. $$

  • If $\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x}$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x}\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\infty,p)=\infty$
  • $f(-\infty,p)=\text{NaN}$
  • $f(0.0,p)=0.0$
  • $f(-0.0,p)=-0.0$

Neither overflow nor underflow is possible.

If you want to use a rounding mode other than Nearest, consider using Float::sqrt_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).sqrt() instead.

§Worst-case complexity

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

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

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

§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sqrt, o) = Float::from(PI).sqrt_prec_ref(5);
assert_eq!(sqrt.to_string(), "1.75");
assert_eq!(o, Less);

let (sqrt, o) = Float::from(PI).sqrt_prec_ref(20);
assert_eq!(sqrt.to_string(), "1.7724533");
assert_eq!(o, Less);
Source

pub fn sqrt_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes the square root of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square root is less than, equal to, or greater than the exact square root. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The square root of any nonzero negative number is NaN.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \sqrt{x}+\varepsilon. $$

  • If $\sqrt{x}$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\sqrt{x}$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 \sqrt{x}\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $\sqrt{x}$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 \sqrt{x}\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\infty,m)=\infty$
  • $f(-\infty,m)=\text{NaN}$
  • $f(0.0,m)=0.0$
  • $f(-0.0,m)=-0.0$

Neither overflow nor underflow is possible.

If you want to specify an output precision, consider using Float::sqrt_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).sqrt() instead.

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

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sqrt, o) = Float::from(PI).sqrt_round_ref(Floor);
assert_eq!(sqrt.to_string(), "1.7724538509055154");
assert_eq!(o, Less);

let (sqrt, o) = Float::from(PI).sqrt_round_ref(Ceiling);
assert_eq!(sqrt.to_string(), "1.7724538509055172");
assert_eq!(o, Greater);

let (sqrt, o) = Float::from(PI).sqrt_round_ref(Nearest);
assert_eq!(sqrt.to_string(), "1.7724538509055154");
assert_eq!(o, Less);
Source

pub fn square_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Squares a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square is less than, equal to, or greater than the exact square. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = x^2+\varepsilon. $$

  • If $x^2$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^2$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^2|\rfloor-p+1}$.
  • If $x^2$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^2|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\infty$
  • $f(\pm0.0,p,m)=0.0$

Overflow and underflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.

Since the result is never negative, negative overflow and underflow cannot occur.

If you know you’ll be using Nearest, consider using Float::square_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::square_round_ref instead. If both of these things are true, consider using (&Float).square()instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but prec is too small for an exact squaring.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (square, o) = Float::from(PI).square_prec_round_ref(5, Floor);
assert_eq!(square.to_string(), "9.50");
assert_eq!(o, Less);

let (square, o) = Float::from(PI).square_prec_round_ref(5, Ceiling);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);

let (square, o) = Float::from(PI).square_prec_round_ref(5, Nearest);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);

let (square, o) = Float::from(PI).square_prec_round_ref(20, Floor);
assert_eq!(square.to_string(), "9.8695984");
assert_eq!(o, Less);

let (square, o) = Float::from(PI).square_prec_round_ref(20, Ceiling);
assert_eq!(square.to_string(), "9.8696136");
assert_eq!(o, Greater);

let (square, o) = Float::from(PI).square_prec_round_ref(20, Nearest);
assert_eq!(square.to_string(), "9.8695984");
assert_eq!(o, Less);
Source

pub fn square_prec_ref(&self, prec: u64) -> (Self, Ordering)

Squares a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square is less than, equal to, or greater than the exact square. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the square is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = x^2+\varepsilon. $$

  • If $x^2$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^2$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x^2|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\infty$
  • $f(\pm0.0,p)=0.0$

Overflow and underflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.

Since the result is never negative, negative overflow and underflow cannot occur.

If you want to use a rounding mode other than Nearest, consider using Float::square_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).square() instead.

§Worst-case complexity

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

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

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

§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (square, o) = Float::from(PI).square_prec_ref(5);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);

let (square, o) = Float::from(PI).square_prec_ref(20);
assert_eq!(square.to_string(), "9.8695984");
assert_eq!(o, Less);
Source

pub fn square_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Squares a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded square is less than, equal to, or greater than the exact square. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = x^2+\varepsilon. $$

  • If $x^2$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x^2$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x^2|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x^2$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x^2|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\infty$
  • $f(\pm0.0,m)=0.0$

Overflow and underflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.

Since the result is never negative, negative overflow and underflow cannot occur.

If you want to specify an output precision, consider using Float::square_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).square() instead.

§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 rm is Exact but the precision of the input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (square, o) = Float::from(PI).square_round_ref(Floor);
assert_eq!(square.to_string(), "9.8696044010893473");
assert_eq!(o, Less);

let (square, o) = Float::from(PI).square_round_ref(Ceiling);
assert_eq!(square.to_string(), "9.8696044010893615");
assert_eq!(o, Greater);

let (square, o) = Float::from(PI).square_round_ref(Nearest);
assert_eq!(square.to_string(), "9.8696044010893615");
assert_eq!(o, Greater);
Source

pub fn sub_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts two Floats, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\infty,\infty,p,m)=f(-\infty,-\infty,p,m)= \text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,p,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p,m)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,p,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,p,m)=0.0$
  • $f(-0.0,0.0,p,m)=-0.0$
  • $f(0.0,0.0,p,m)=f(-0.0,-0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,p,m)=f(-0.0,-0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,x,p,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,p,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_prec_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::sub_round_ref_val instead. If both of these things are true, consider using - instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Panics

Panics if rm is Exact but prec is too small for an exact subtraction.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "0.438");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "0.42331123");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);
Source

pub fn sub_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts two Floats, rounding the result to the specified precision and with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=f(x,\text{NaN},p,m)=f(\infty,\infty,p,m)=f(-\infty,-\infty,p,m)= \text{NaN}$
  • $f(\infty,x,p,m)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,p,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p,m)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,p,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,p,m)=0.0$
  • $f(-0.0,0.0,p,m)=-0.0$
  • $f(0.0,0.0,p,m)=f(-0.0,-0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,p,m)=f(-0.0,-0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,x,p,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,p,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_prec_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::sub_round_ref_ref instead. If both of these things are true, consider using - instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Panics

Panics if rm is Exact but prec is too small for an exact subtraction.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "0.438");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "0.42331123");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);
Source

pub fn sub_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Subtracts two Floats, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the difference is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\infty,\infty,p)=f(-\infty,-\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,p)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,p)=0.0$
  • $f(-0.0,0.0,p)=-0.0$
  • $f(0.0,0.0,p)=f(-0.0,-0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,p)=f(-0.0,-0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,x,p)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,p)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_prec_round_ref_val instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using - instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_prec_ref_val(Float::from(E), 5);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_ref_val(Float::from(E), 20);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);
Source

pub fn sub_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Subtracts two Floats, rounding the result to the nearest value of the specified precision. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the difference is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=f(x,\text{NaN},p)=f(\infty,\infty,p)=f(-\infty,-\infty,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,p)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,p)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,p)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,p)=0.0$
  • $f(-0.0,0.0,p)=-0.0$
  • $f(0.0,0.0,p)=f(-0.0,-0.0,p,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,p)=f(-0.0,-0.0,p,m)=-0.0$ if $m$ is Floor
  • $f(x,x,p)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,p)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_prec_round_ref_ref instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using - instead.

§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 prec, and $m$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_prec_ref_ref(&Float::from(E), 5);
assert_eq!(sum.to_string(), "0.422");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_prec_ref_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "0.42331076");
assert_eq!(o, Less);
Source

pub fn sub_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts two Floats, rounding the result with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\infty,\infty,m)=f(-\infty,-\infty,m)= \text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,m)=0.0$
  • $f(-0.0,0.0,m)=-0.0$
  • $f(0.0,0.0,m)=f(-0.0,-0.0,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,m)=f(-0.0,-0.0,m)=-0.0$ if $m$ is Floor
  • $f(x,x,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using - instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(m)$

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_round_ref_val(Float::from(-E), Floor);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_round_ref_val(Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.8598744820488387");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_round_ref_val(Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);
Source

pub fn sub_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts two Floats, rounding the result with the specified rounding mode. Both Floats are taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precision of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},x,m)=f(x,\text{NaN},m)=f(\infty,\infty,m)=f(-\infty,-\infty,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $\infty$
  • $f(x,-\infty,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $-\infty$
  • $f(x,\infty,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,-0.0,m)=0.0$
  • $f(-0.0,0.0,m)=-0.0$
  • $f(0.0,0.0,m)=f(-0.0,-0.0,m)=0.0$ if $m$ is not Floor
  • $f(0.0,0.0,m)=f(-0.0,-0.0,m)=-0.0$ if $m$ is Floor
  • $f(x,x,m)=0.0$ if $x$ is finite and nonzero and $m$ is not Floor
  • $f(x,x,m)=-0.0$ if $x$ is finite and nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using - instead.

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_round_ref_ref(&Float::from(-E), Floor);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_round_ref_ref(&Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.8598744820488387");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_round_ref_ref(&Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.8598744820488378");
assert_eq!(o, Less);
Source

pub fn sub_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$
  • $f(-\infty,x,p,m)=-\infty$
  • $f(0.0,0,p,m)=0.0$
  • $f(-0.0,0,p,m)=-0.0$
  • $f(x,x,p,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,x,p,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_rational_prec_ref_val instead. If you know that your target precision is the precision of the Float input, consider using Float::sub_rational_round_ref_val instead. If both of these things are true, consider using - instead.

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

§Panics

Panics if rm is Exact but prec is too small for an exact subtraction.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(sum.to_string(), "2.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(sum.to_string(), "2.88");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(sum.to_string(), "2.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(sum.to_string(), "2.8082581");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(sum.to_string(), "2.8082619");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_val(
    Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(sum.to_string(), "2.8082581");
assert_eq!(o, Less);
Source

pub fn sub_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,p,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p,m)=\text{NaN}$
  • $f(\infty,x,p,m)=\infty$
  • $f(-\infty,x,p,m)=-\infty$
  • $f(0.0,0,p,m)=0.0$
  • $f(-0.0,0,p,m)=-0.0$
  • $f(x,x,p,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,x,p,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_rational_prec_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using Float::sub_rational_round_ref_ref instead. If both of these things are true, consider using - instead.

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

§Panics

Panics if rm is Exact but prec is too small for an exact subtraction.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Floor,
);
assert_eq!(sum.to_string(), "2.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Ceiling,
);
assert_eq!(sum.to_string(), "2.88");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    5,
    Nearest,
);
assert_eq!(sum.to_string(), "2.75");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Floor,
);
assert_eq!(sum.to_string(), "2.8082581");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Ceiling,
);
assert_eq!(sum.to_string(), "2.8082619");
assert_eq!(o, Greater);

let (sum, o) = Float::from(PI).sub_rational_prec_round_ref_ref(
    &Rational::from_unsigneds(1u8, 3),
    20,
    Nearest,
);
assert_eq!(sum.to_string(), "2.8082581");
assert_eq!(o, Less);
Source

pub fn sub_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the difference is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$
  • $f(-\infty,x,p)=-\infty$
  • $f(0.0,0,p)=0.0$
  • $f(-0.0,0,p)=-0.0$
  • $f(x,x,p)=0.0$ if $x$ is nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_rational_prec_round_ref_val instead. If you know that your target precision is the precision of the Float input, consider using - instead.

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

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_rational_prec_ref_val(Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "1.62");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_ref_val(Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "1.6415920");
assert_eq!(o, Less);
Source

pub fn sub_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the difference is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,p) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},x,p)=\text{NaN}$
  • $f(\infty,x,p)=\infty$
  • $f(-\infty,x,p)=-\infty$
  • $f(0.0,0,p)=0.0$
  • $f(-0.0,0,p)=-0.0$
  • $f(x,x,p)=0.0$ if $x$ is nonzero

Overflow and underflow:

  • If $f(x,y,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_rational_prec_round_ref_ref instead. If you know that your target precision is the precision of the Float input, consider using - instead.

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

§Examples
use core::f64::consts::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) = Float::from(PI).sub_rational_prec_ref_ref(&Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "1.62");
assert_eq!(o, Less);

let (sum, o) = Float::from(PI).sub_rational_prec_ref_ref(&Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "1.6415920");
assert_eq!(o, Less);
Source

pub fn sub_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0,m)=0.0$
  • $f(-0.0,0,m)=-0.0$
  • $f(x,0,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(0.0,x,m)=f(-0.0,x,m)=-x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,x,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,x,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_rational_prec_round_ref_val instead. If you know you’ll be using the Nearest rounding mode, consider using - instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "2.8082593202564574");
assert_eq!(o, Less);

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "2.8082593202564610");
assert_eq!(o, Greater);

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_val(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "2.8082593202564610");
assert_eq!(o, Greater);
Source

pub fn sub_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts a Float by a Rational, rounding the result with the specified rounding mode. The Float and the Rational are both are taken by reference. An Ordering is also returned, indicating whether the rounded difference is less than, equal to, or greater than the exact difference. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the Float input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,m) = x-y+\varepsilon. $$

  • If $x-y$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-y$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p+1}$, where $p$ is the precision of the input Float.
  • If $x-y$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the input Float.

If the output has a precision, it is the precision of the Float input.

Special cases:

  • $f(\text{NaN},x,m)=\text{NaN}$
  • $f(\infty,x,m)=\infty$ if $x$ is not NaN or $-\infty$
  • $f(-\infty,x,m)=-\infty$ if $x$ is not NaN or $\infty$
  • $f(0.0,0,m)=0.0$
  • $f(-0.0,0,m)=-0.0$
  • $f(x,0,m)=x$ if $x$ is not NaN and $x$ is nonzero
  • $f(0.0,x,m)=f(-0.0,x,m)=-x$ if $x$ is not NaN and $x$ is nonzero
  • $f(x,x,m)=0.0$ if $x$ is nonzero and $m$ is not Floor
  • $f(x,x,m)=-0.0$ if $x$ is nonzero and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the input.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_rational_prec_round_ref_ref instead. If you know you’ll be using the Nearest rounding mode, consider using - instead.

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

§Panics

Panics if rm is Exact but the precision of the Float input is not high enough to represent the output.

§Examples
use core::f64::consts::PI;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "2.8082593202564574");
assert_eq!(o, Less);

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "2.8082593202564610");
assert_eq!(o, Greater);

let (sum, o) =
    Float::from(PI).sub_rational_round_ref_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "2.8082593202564610");
assert_eq!(o, Greater);
Source

pub fn sub_mul_prec_round_ref_val_val( &self, y: Self, z: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Floor);
assert_eq!(diff.to_string(), "-0.719");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Ceiling);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 5, Nearest);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Floor);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Ceiling);
assert_eq!(diff.to_string(), "-0.70263767");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_val(y.clone(), z.clone(), 20, Nearest);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_round_ref_val_ref( &self, y: Self, z: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the specified precision and with the specified rounding mode. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Floor);
assert_eq!(diff.to_string(), "-0.719");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Ceiling);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 5, Nearest);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Floor);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Ceiling);
assert_eq!(diff.to_string(), "-0.70263767");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_val_ref(y.clone(), &z, 20, Nearest);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_round_ref_ref_val( &self, y: &Self, z: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the specified precision and with the specified rounding mode. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Floor);
assert_eq!(diff.to_string(), "-0.719");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Ceiling);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 5, Nearest);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Floor);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Ceiling);
assert_eq!(diff.to_string(), "-0.70263767");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_val(&y, z.clone(), 20, Nearest);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_round_ref_ref_ref( &self, y: &Self, z: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the specified precision and with the specified rounding mode. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=f(x,y,\text{NaN},p,m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p,m)=f(x,\pm0.0,\pm\infty,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,p,m)=f(-0.0,y,z,p,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 5, Floor);
assert_eq!(diff.to_string(), "-0.719");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 5, Ceiling);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 5, Nearest);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 20, Floor);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 20, Ceiling);
assert_eq!(diff.to_string(), "-0.70263767");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_round_ref_ref_ref(&y, &z, 20, Nearest);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_ref_val_val( &self, y: Self, z: Self, prec: u64, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of the same sign
  • $f(x,y,z,p)=0.0$ if $x=yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_ref_val_val(y.clone(), z.clone(), 5);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_ref_val_val(y.clone(), z.clone(), 20);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_ref_val_ref( &self, y: Self, z: &Self, prec: u64, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the nearest value of the specified precision. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of the same sign
  • $f(x,y,z,p)=0.0$ if $x=yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_ref_val_ref(y.clone(), &z, 5);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_ref_val_ref(y.clone(), &z, 20);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_ref_ref_val( &self, y: &Self, z: Self, prec: u64, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the nearest value of the specified precision. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of the same sign
  • $f(x,y,z,p)=0.0$ if $x=yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_ref_ref_val(&y, z.clone(), 5);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_ref_ref_val(&y, z.clone(), 20);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_prec_ref_ref_ref( &self, y: &Self, z: &Self, prec: u64, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result to the nearest value of the specified precision. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=f(x,y,\text{NaN},p)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,p)=f(x,\pm0.0,\pm\infty,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,p)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,p)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,p)=f(-0.0,y,z,p)=0.0$ if $x$ and $yz$ are zeros of the same sign
  • $f(x,y,z,p)=0.0$ if $x=yz$, $x$ is finite and nonzero,

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_prec_ref_ref_ref(&y, &z, 5);
assert_eq!(diff.to_string(), "-0.688");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_prec_ref_ref_ref(&y, &z, 20);
assert_eq!(diff.to_string(), "-0.70263863");
assert_eq!(o, Less);
Source

pub fn sub_mul_round_ref_val_val( &self, y: Self, z: Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result with the specified rounding mode. The first Float is taken by reference and the second and third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_round_ref_val_val(y.clone(), z.clone(), Floor);
assert_eq!(diff.to_string(), "-0.70263837456932388");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_round_ref_val_val(y.clone(), z.clone(), Ceiling);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_round_ref_val_val(y.clone(), z.clone(), Nearest);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);
Source

pub fn sub_mul_round_ref_val_ref( &self, y: Self, z: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result with the specified rounding mode. The first and third Floats are taken by reference and the second by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_round_ref_val_ref(y.clone(), &z, Floor);
assert_eq!(diff.to_string(), "-0.70263837456932388");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_round_ref_val_ref(y.clone(), &z, Ceiling);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_round_ref_val_ref(y.clone(), &z, Nearest);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);
Source

pub fn sub_mul_round_ref_ref_val( &self, y: &Self, z: Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result with the specified rounding mode. The first two Floats are taken by reference and the third by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_round_ref_ref_val(&y, z.clone(), Floor);
assert_eq!(diff.to_string(), "-0.70263837456932388");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_round_ref_ref_val(&y, z.clone(), Ceiling);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_round_ref_ref_val(&y, z.clone(), Nearest);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);
Source

pub fn sub_mul_round_ref_ref_ref( &self, y: &Self, z: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of two other Floats from a Float, rounding the result with the specified rounding mode. All three Floats are taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the maximum of the precisions of the inputs. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the inputs.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the inputs.

If the output has a precision, it is the maximum of the precisions of the inputs.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=f(x,y,\text{NaN},m)=\text{NaN}$
  • $f(x,\pm\infty,\pm0.0,m)=f(x,\pm0.0,\pm\infty,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if neither $y$ nor $z$ is NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if neither $y$ nor $z$ is NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • $f(0.0,y,z,m)=0.0$ if $yz=-0.0$
  • $f(-0.0,y,z,m)=-0.0$ if $yz=0.0$
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is not Floor
  • $f(0.0,y,z,m)=f(-0.0,y,z,m)=-0.0$ if $x$ and $yz$ are zeros of the same sign and $m$ is Floor
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the inputs is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI, SQRT_2};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Float::from(SQRT_2);

let (diff, o) = x.sub_mul_round_ref_ref_ref(&y, &z, Floor);
assert_eq!(diff.to_string(), "-0.70263837456932388");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_round_ref_ref_ref(&y, &z, Ceiling);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_round_ref_ref_ref(&y, &z, Nearest);
assert_eq!(diff.to_string(), "-0.70263837456932376");
assert_eq!(o, Greater);
Source

pub fn sub_mul_rational_prec_round_ref_val_val( &self, y: Self, z: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the specified precision and with the specified rounding mode. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_rational_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Floor);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Ceiling);
assert_eq!(diff.to_string(), "-5.25");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 5, Nearest);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Floor);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);

let (diff, o) =
    x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Ceiling);
assert_eq!(diff.to_string(), "-5.4015732");
assert_eq!(o, Greater);

let (diff, o) =
    x.sub_mul_rational_prec_round_ref_val_val(y.clone(), z.clone(), 20, Nearest);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_round_ref_val_ref( &self, y: Self, z: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the specified precision and with the specified rounding mode. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_rational_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Floor);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Ceiling);
assert_eq!(diff.to_string(), "-5.25");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 5, Nearest);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Floor);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Ceiling);
assert_eq!(diff.to_string(), "-5.4015732");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_val_ref(y.clone(), &z, 20, Nearest);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_round_ref_ref_val( &self, y: &Self, z: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the specified precision and with the specified rounding mode. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_rational_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Floor);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Ceiling);
assert_eq!(diff.to_string(), "-5.25");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 5, Nearest);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Floor);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Ceiling);
assert_eq!(diff.to_string(), "-5.4015732");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_val(&y, z.clone(), 20, Nearest);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_round_ref_ref_ref( &self, y: &Self, z: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the specified precision and with the specified rounding mode. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,p,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p,m)=f(x,\text{NaN},z,p,m)=\text{NaN}$
  • $f(x,\pm\infty,0,p,m)=\text{NaN}$
  • $f(\infty,y,z,p,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,p,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you know you’ll be using Nearest, consider using Float::sub_mul_rational_prec instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using Float::sub_mul_rational_round instead. If both of these things are true, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the fused multiply-subtract is not exactly representable with prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Floor);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Ceiling);
assert_eq!(diff.to_string(), "-5.25");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 5, Nearest);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Floor);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Ceiling);
assert_eq!(diff.to_string(), "-5.4015732");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_prec_round_ref_ref_ref(&y, &z, 20, Nearest);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_ref_val_val( &self, y: Self, z: Rational, prec: u64, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the nearest value of the specified precision. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_ref_val_val(y.clone(), z.clone(), 5);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_ref_val_val(y.clone(), z.clone(), 20);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_ref_val_ref( &self, y: Self, z: &Rational, prec: u64, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the nearest value of the specified precision. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_ref_val_ref(y.clone(), &z, 5);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_ref_val_ref(y.clone(), &z, 20);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_ref_ref_val( &self, y: &Self, z: Rational, prec: u64, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the nearest value of the specified precision. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_ref_ref_val(&y, z.clone(), 5);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_ref_ref_val(&y, z.clone(), 20);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_prec_ref_ref_ref( &self, y: &Self, z: &Rational, prec: u64, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result to the nearest value of the specified precision. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

If the diff is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,y,z,p) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},y,z,p)=f(x,\text{NaN},z,p)=\text{NaN}$
  • $f(x,\pm\infty,0,p)=\text{NaN}$
  • $f(\infty,y,z,p)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,p)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,p)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,p)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,p)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,p)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,p)=0.0$ if $x=yz$ and $x$ is finite and nonzero

Overflow and underflow:

  • If $f(x,y,z,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,y,z,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,y,z,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

If you want to use a rounding mode other than Nearest, consider using Float::sub_mul_rational_prec_round instead. If you know that your target precision is the maximum of the precisions of the inputs, consider using sub_mul instead.

§Worst-case complexity

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

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits() + y.significant_bits() + z.significant_bits(), and $m$ is max(self.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_prec_ref_ref_ref(&y, &z, 5);
assert_eq!(diff.to_string(), "-5.50");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_prec_ref_ref_ref(&y, &z, 20);
assert_eq!(diff.to_string(), "-5.4015808");
assert_eq!(o, Less);
Source

pub fn sub_mul_rational_round_ref_val_val( &self, y: Self, z: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result with the specified rounding mode. The first Float is taken by reference and the second Float and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_round_ref_val_val(y.clone(), z.clone(), Floor);
assert_eq!(diff.to_string(), "-5.4015788072814921");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_round_ref_val_val(y.clone(), z.clone(), Ceiling);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_round_ref_val_val(y.clone(), z.clone(), Nearest);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);
Source

pub fn sub_mul_rational_round_ref_val_ref( &self, y: Self, z: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result with the specified rounding mode. The second Float is taken by value and the first Float and the Rational by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_round_ref_val_ref(y.clone(), &z, Floor);
assert_eq!(diff.to_string(), "-5.4015788072814921");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_round_ref_val_ref(y.clone(), &z, Ceiling);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_round_ref_val_ref(y.clone(), &z, Nearest);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);
Source

pub fn sub_mul_rational_round_ref_ref_val( &self, y: &Self, z: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result with the specified rounding mode. The Floats are taken by reference and the Rational by value. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_round_ref_ref_val(&y, z.clone(), Floor);
assert_eq!(diff.to_string(), "-5.4015788072814921");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_round_ref_ref_val(&y, z.clone(), Ceiling);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_round_ref_ref_val(&y, z.clone(), Nearest);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);
Source

pub fn sub_mul_rational_round_ref_ref_ref( &self, y: &Self, z: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Subtracts the product of a Float and a Rational from another Float, rounding the result with the specified rounding mode. The Floats and the Rational are all taken by reference. An Ordering is also returned, indicating whether the rounded diff is less than, equal to, or greater than the exact diff. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The Rational multiplicand enters the product exactly: it is never rounded to a Float first, so the result is the true value of $x-yz$ with a single rounding at the end. Rounding the Rational first would perturb the result by $y$ times the conversion error.

The precision of the output is the maximum of the precisions of the input Floats. See RoundingMode for a description of the possible rounding modes.

$$ f(x,y,z,m) = x-yz+\varepsilon. $$

  • If $x-yz$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x-yz$ is finite and nonzero, and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |x-yz|\rfloor-p+1}$, where $p$ is the maximum precision of the input Floats.
  • If $x-yz$ is finite and nonzero, and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |x-yz|\rfloor-p}$, where $p$ is the maximum precision of the input Floats.

If the output has a precision, it is the maximum of the precisions of the input Floats.

Special cases:

  • $f(\text{NaN},y,z,m)=f(x,\text{NaN},z,m)=\text{NaN}$
  • $f(x,\pm\infty,0,m)=\text{NaN}$
  • $f(\infty,y,z,m)=\text{NaN}$ if $yz=\infty$
  • $f(-\infty,y,z,m)=\text{NaN}$ if $yz=-\infty$
  • $f(\infty,y,z,m)=\infty$ if $y$ is not NaN and $yz\neq\infty$
  • $f(-\infty,y,z,m)=-\infty$ if $y$ is not NaN and $yz\neq-\infty$
  • $f(x,y,z,m)=-\infty$ if $x$ is finite and $yz=\infty$
  • $f(x,y,z,m)=\infty$ if $x$ is finite and $yz=-\infty$
  • If $x$ and the product $yz$ are both zeros, the sign rules of Float addition apply to $x$ and $-yz$; the product is a zero whose sign is the XOR of the signs of $y$ and $z$, a zero Rational counting as positive.
  • $f(x,y,z,m)=0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is not Floor
  • $f(x,y,z,m)=-0.0$ if $x=yz$, $x$ is finite and nonzero, and $m$ is Floor

Overflow and underflow:

  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,y,z,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,y,z,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, where p is the precision of the output.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,y,z,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,y,z,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,y,z,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,y,z,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

If you want to specify an output precision, consider using Float::sub_mul_rational_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using sub_mul instead.

§Worst-case complexity

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

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

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

§Panics

Panics if rm is Exact but the maximum precision of the input Floats is not high enough to represent the output.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;

let x = Float::from(PI);
let y = Float::from(E);
let z = Rational::from_signeds(22, 7);

let (diff, o) = x.sub_mul_rational_round_ref_ref_ref(&y, &z, Floor);
assert_eq!(diff.to_string(), "-5.4015788072814921");
assert_eq!(o, Less);

let (diff, o) = x.sub_mul_rational_round_ref_ref_ref(&y, &z, Ceiling);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);

let (diff, o) = x.sub_mul_rational_round_ref_ref_ref(&y, &z, Nearest);
assert_eq!(diff.to_string(), "-5.4015788072814912");
assert_eq!(o, Greater);
Source

pub fn tan_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\tan x$, the tangent of a Float, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See RoundingMode for a description of the possible rounding modes.

$$ f(x,p,m) = \tan x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\tan x|\rfloor-p+1}$.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\tan x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p,m)=\text{NaN}$
  • $f(\pm\infty,p,m)=\text{NaN}$
  • $f(\pm0.0,p,m)=\pm0.0$

Overflow and underflow:

  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, and underflow an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, either of which takes more than $2^{30}$ bits of precision; underflow also occurs for an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you know you’ll be using Nearest, consider using Float::tan_prec_ref instead. If you know that your target precision is the precision of the input, consider using Float::tan_round_ref instead. If both of these things are true, consider using (&Float).tan() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived), and their quotient, cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, tan therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the tangent of a finite nonzero Float is never exactly representable, or if prec is zero.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(5, Floor);
assert_eq!(c.to_string(), "1.50");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(5, Ceiling);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(5, Nearest);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(20, Floor);
assert_eq!(c.to_string(), "1.5574074");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(20, Ceiling);
assert_eq!(c.to_string(), "1.5574093");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_round_ref(20, Nearest);
assert_eq!(c.to_string(), "1.5574074");
assert_eq!(o, Less);
Source

pub fn tan_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\tan x$, the tangent of a Float, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

If the tangent is equidistant from two Floats with the specified precision, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

$$ f(x,p) = \tan x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\tan x|\rfloor-p}$.

If the output has a precision, it is prec.

Special cases:

  • $f(\text{NaN},p)=\text{NaN}$
  • $f(\pm\infty,p)=\text{NaN}$
  • $f(\pm0.0,p)=1.0$

Overflow and underflow:

  • If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
  • If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
  • If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,p)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,p)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, and underflow an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, either of which takes more than $2^{30}$ bits of precision; underflow also occurs for an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you want to use a rounding mode other than Nearest, consider using Float::tan_prec_round_ref instead. If you know that your target precision is the precision of the input, consider using (&Float).tan() instead.

§Worst-case complexity

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

$M(n, m, e) = O((n+m+e) \log (n+m+e))$

where $T$ is time, $M$ is additional memory, $n$ is prec, $m$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the sine and cosine at working precision $n$ (for large $n$ by binary splitting of the Taylor series, otherwise the cosine, from which the sine is derived), and their quotient, cost the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a remainder of the $m$-bit input. Unlike most functions, tan therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_ref(5);
assert_eq!(c.to_string(), "1.56");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_prec_ref(20);
assert_eq!(c.to_string(), "1.5574074");
assert_eq!(o, Less);
Source

pub fn tan_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\tan x$, the tangent of a Float, rounding the result with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The precision of the output is the precision of the input. See RoundingMode for a description of the possible rounding modes.

$$ f(x,m) = \tan x+\varepsilon. $$

  • If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and $m$ is not Nearest, then $|\varepsilon| < 2^{\lfloor\log_2 |\tan x|\rfloor-p+1}$, where $p$ is the precision of the input.
  • If $x$ is finite and $m$ is Nearest, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\tan x|\rfloor-p}$, where $p$ is the precision of the input.

If the output has a precision, it is the precision of the input.

Special cases:

  • $f(\text{NaN},m)=\text{NaN}$
  • $f(\pm\infty,m)=\text{NaN}$
  • $f(\pm0.0,m)=1.0$

Overflow and underflow:

  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Ceiling, Up, or Nearest, $\infty$ is returned instead.
  • If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is Floor or Down, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Floor, Up, or Nearest, $-\infty$ is returned instead.
  • If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is Ceiling or Down, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Floor or Down, $0.0$ is returned instead.
  • If $0<f(x,m)<2^{-2^{30}}$, and $m$ is Ceiling or Up, $2^{-2^{30}}$ is returned instead.
  • If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is Nearest, $0.0$ is returned instead.
  • If $2^{-2^{30}-1}<f(x,m)<2^{-2^{30}}$, and $m$ is Nearest, $2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Ceiling or Down, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is Floor or Up, $-2^{-2^{30}}$ is returned instead.
  • If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is Nearest, $-0.0$ is returned instead.
  • If $-2^{-2^{30}}<f(x,m)<-2^{-2^{30}-1}$, and $m$ is Nearest, $-2^{-2^{30}}$ is returned instead.

Overflow requires an input within $2^{-2^{30}}$ of an odd multiple of $\pi/2$, and underflow an input within $2^{-2^{30}}$ of a nonzero multiple of $\pi$, either of which takes more than $2^{30}$ bits of precision; underflow also occurs for an input of magnitude $2^{-2^{30}}$, the smallest positive Float, rounded toward zero.

If you want to specify an output precision, consider using Float::tan_prec_round_ref instead. If you know you’ll be using the Nearest rounding mode, consider using (&Float).tan() instead.

§Worst-case complexity

$T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$

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

where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits(), and $e$ is the exponent of self (0 if self has no exponent or a negative one): the Taylor series at working precision $n$, summed by binary splitting for large $n$, costs the first term, and for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits. Unlike most functions, tan therefore gets slower as the magnitude of its input grows, not just as the precision does.

§Panics

Panics if rm is Exact, since the tangent of a finite nonzero Float is never exactly representable.

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

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_round_ref(Floor);
assert_eq!(c.to_string(), "1.5574077246549022305069748074575");
assert_eq!(o, Less);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_round_ref(Ceiling);
assert_eq!(c.to_string(), "1.5574077246549022305069748074591");
assert_eq!(o, Greater);

let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).tan_round_ref(Nearest);
assert_eq!(c.to_string(), "1.5574077246549022305069748074591");
assert_eq!(o, Greater);
Source

pub fn tan_with_period_prec_round_ref( &self, u: u64, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\tan(2\pi x/u)$, the tangent of a Float measured in $u$ths of a turn, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::tan_with_period_prec_round for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity; this function behaves the same way.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.tan_with_period_prec_round_ref(7, 10, Floor);
assert_eq!(t.to_string(), "1.2539");
assert_eq!(o, Less);
Source

pub fn tan_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering)

Computes $\tan(2\pi x/u)$, the tangent of a Float measured in $u$ths of a turn, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::tan_with_period_prec and Float::tan_with_period_prec_round; this function behaves the same way.

§Panics

Panics if prec is zero.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = Float::ONE.tan_with_period_prec_ref(7, 10);
assert_eq!(t.to_string(), "1.2539");
assert_eq!(o, Less);
Source

pub fn tan_with_period_round_ref( &self, u: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\tan(2\pi x/u)$, the tangent of a Float measured in $u$ths of a turn, rounding the result to the precision of the input and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

See Float::tan_with_period_round and Float::tan_with_period_prec_round; this function behaves the same way.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the precision of the input.

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

let (t, o) = Float::from_unsigned_prec(1u32, 10)
    .0
    .tan_with_period_round_ref(7, Floor);
assert_eq!(t.to_string(), "1.2539");
assert_eq!(o, Less);
Source

pub fn tan_with_period_ref(&self, u: u64) -> Self

Computes $\tan(2\pi x/u)$, the tangent of a Float measured in $u$ths of a turn (so that u = 360 is degrees), rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the tangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

See Float::tan_with_period_prec_round for the error bounds, the special and closed-form cases, overflow and underflow, and the complexity; this function behaves the same way with prec equal to the precision of the input and rm equal to Nearest.

If you want to use a rounding mode other than Nearest, consider using Float::tan_with_period_round_ref instead. If you want to specify an output precision, consider using Float::tan_with_period_prec_ref. If you want both of these things, consider using Float::tan_with_period_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from_unsigned_prec(1u32, 10).0).tan_with_period_ref(7);
assert_eq!(t.to_string(), "1.2539");
Source

pub fn tan_pi_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes $\tan(\pi x)$, the tangent of a Float measured in half-turns, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is tan_with_period with a period of 2: see Float::tan_with_period_prec_round_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$, with the sign of the input at even integers and the opposite sign at odd ones; half-integers are poles and give $\pm\infty$; odd multiples of $1/4$ give $\pm1$; and multiples of $1/3$ and $1/6$ give $\pm\sqrt3$ or $\pm\sqrt3/3$), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero, or if rm is Exact but the result cannot be represented exactly with the given precision.

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).tan_pi_prec_round_ref(10, Floor);
assert_eq!(t.to_string(), "0.32471");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).tan_pi_prec_round_ref(10, Ceiling);
assert_eq!(t.to_string(), "0.32520");
assert_eq!(o, Greater);

// a half-turn is exactly zero, reached from below
let (t, o) = (&Float::ONE).tan_pi_prec_round_ref(10, Exact);
assert_eq!(t.to_string(), "-0.0");
assert_eq!(o, Equal);
Source

pub fn tan_pi_prec_ref(&self, prec: u64) -> (Self, Ordering)

Computes $\tan(\pi x)$, the tangent of a Float measured in half-turns, rounding the result to the nearest value of the specified precision. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is tan_with_period with a period of 2: see Float::tan_with_period_prec_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$, with the sign of the input at even integers and the opposite sign at odd ones; half-integers are poles and give $\pm\infty$; odd multiples of $1/4$ give $\pm1$; and multiples of $1/3$ and $1/6$ give $\pm\sqrt3$ or $\pm\sqrt3/3$), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if prec is zero.

§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;

let (t, o) = (Float::from(0.1f64)).tan_pi_prec_ref(10);
assert_eq!(t.to_string(), "0.32471");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).tan_pi_prec_ref(53);
assert_eq!(t.to_string(), "0.32491969623290634");
assert_eq!(o, Less);
Source

pub fn tan_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering)

Computes $\tan(\pi x)$, the tangent of a Float measured in half-turns, rounding the result with the specified rounding mode. The precision of the output is the precision of the input. The Float is taken by reference. An Ordering is also returned, indicating whether the rounded tangent is less than, equal to, or greater than the exact tangent. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

This is tan_with_period with a period of 2: see Float::tan_with_period_round_ref for the error bounds, the special and closed-form cases (integers give $\pm0.0$, with the sign of the input at even integers and the opposite sign at odd ones; half-integers are poles and give $\pm\infty$; odd multiples of $1/4$ give $\pm1$; and multiples of $1/3$ and $1/6$ give $\pm\sqrt3$ or $\pm\sqrt3/3$), overflow and underflow, and the complexity, with $u = 2$.

§Panics

Panics if rm is Exact but the result cannot be represented exactly with the input precision.

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

let (t, o) = (Float::from(0.1f64)).tan_pi_round_ref(Floor);
assert_eq!(t.to_string(), "0.32491969623290629");
assert_eq!(o, Less);

let (t, o) = (Float::from(0.1f64)).tan_pi_round_ref(Nearest);
assert_eq!(t.to_string(), "0.32491969623290640");
assert_eq!(o, Greater);
Source

pub fn tan_pi_ref(&self) -> Self

Computes $\tan(\pi x)$, the tangent of a Float measured in half-turns, rounding the result to the precision of the input and to the nearest Float. The Float is taken by reference.

If the tangent is equidistant from two Floats with the precision of the input, the Float with fewer 1s in its binary expansion is chosen. See RoundingMode for a description of the Nearest rounding mode.

This is tan_with_period with a period of 2: see Float::tan_with_period for the error bounds, the special and closed-form cases (integers give $\pm0.0$, with the sign of the input at even integers and the opposite sign at odd ones; half-integers are poles and give $\pm\infty$; odd multiples of $1/4$ give $\pm1$; and multiples of $1/3$ and $1/6$ give $\pm\sqrt3$ or $\pm\sqrt3/3$), overflow and underflow, and the complexity, with $u = 2$.

If you want to use a rounding mode other than Nearest, consider using Float::tan_pi_round_ref instead. If you want to specify an output precision, consider using Float::tan_pi_prec_ref. If you want both of these things, consider using Float::tan_pi_prec_round_ref.

§Examples
use malachite_float::Float;

let t = (&Float::from(0.1f64)).tan_pi_ref();
assert_eq!(t.to_string(), "0.32491969623290640");
Source

pub fn can_round( &self, err: i64, rnd1: RoundingMode, rnd2: RoundingMode, prec: u64, ) -> bool

Determines whether an approximation is accurate enough to commit to a correctly rounded result.

self should be an approximation of some unknown real number $x$, obtained by rounding in the direction rnd1 with error at most $2^{e-\text{{err}}}$, where $e$ is the raw exponent of self (so the error is at most one ulp of self when err equals the precision of self). This function returns whether that information suffices to round $x$ correctly to precision prec in the direction rnd2 — that is, whether every real number consistent with the approximation rounds to the same value. If it returns true, rounding self to precision prec with rnd2 gives that value.

This is the test at the heart of Ziv’s strategy for computing correctly rounded functions: compute an approximation with a known error bound, and retry with more precision until this function accepts it.

If self is NaN, infinite, or zero, the result is false: no error bound of this form conveys enough information to round those.

§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 prec is zero, or if rnd1 or rnd2 is Exact.

§Examples
use malachite_base::num::basic::traits::Two;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;

// A 100-bit approximation of sqrt(2), accurate to about 90 bits, is more than enough
// to round to double precision...
let x = Float::TWO.sqrt_prec(100).0;
assert!(x.can_round(90, Nearest, Nearest, 53));

// ...but knowing only 53 of its bits is not.
assert!(!x.can_round(53, Nearest, Nearest, 53));
Source

pub fn is_nan(&self) -> bool

Determines whether a Float is NaN.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_finite(&self) -> bool

Determines whether a Float is finite.

NaN is not finite.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_infinite(&self) -> bool

Determines whether a Float is infinite.

NaN is not infinite.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_positive_zero(&self) -> bool

Determines whether a Float is positive zero.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_negative_zero(&self) -> bool

Determines whether a Float is negative zero.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_zero(&self) -> bool

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

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_normal(&self) -> bool

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

There is no notion of subnormal Floats.

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_sign_positive(&self) -> bool

Determines whether a Float’s sign is positive.

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

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn is_sign_negative(&self) -> bool

Determines whether a Float’s sign is negative.

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

§Worst-case complexity

Constant time and additional memory.

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

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

pub fn classify(&self) -> FpCategory

Classifies a Float into one of several categories.

§Worst-case complexity

Constant time and additional memory.

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

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

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

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

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

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

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

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

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

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

pub fn complexity(&self) -> u64

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

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

and, if $x$ is finite and nonzero,

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

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

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

See also the Float implementation of SignificantBits.

§Worst-case complexity

Constant time and additional memory.

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

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

pub const MIN_POSITIVE: Self

Source

pub fn abs_is_min_positive_value(&self) -> bool

Returns whether the absolute value of a Float is equal to the minimum representable positive value, or $2^{-2^{30}}$.

$$ f(x) = (|x|=2^{-2^{30}}). $$

§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_float::Float;

assert!(Float::min_positive_value_prec(100).abs_is_min_positive_value());
assert!((-Float::min_positive_value_prec(100)).abs_is_min_positive_value());
assert!(!(Float::min_positive_value_prec(100) << 1u32).abs_is_min_positive_value());
Source

pub fn abs_is_max_finite_value_with_prec(&self) -> bool

Returns whether the absolute value of a Float is equal to the maximum representable finite value with that precision.

$$ f(x) = (|x|=(1-(1/2)^p)2^{2^{30}-1}), $$ where $p$ is the precision of the $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_float::Float;

assert!(Float::max_finite_value_with_prec(100).abs_is_max_finite_value_with_prec());
assert!((-Float::max_finite_value_with_prec(100)).abs_is_max_finite_value_with_prec());
assert!(
    !(Float::max_finite_value_with_prec(100) >> 1u32).abs_is_max_finite_value_with_prec()
);
Source

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

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

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_base::num::arithmetic::traits::PowerOf2;
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_base::num::basic::traits::One;
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::Float;
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_nz::natural::Natural;

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

#[cfg(not(feature = "32_bit_limbs"))]
{
    assert_eq!(Float::ONE.to_significand(), Some(Natural::power_of_2(63)));
    assert_eq!(
        Float::from(std::f64::consts::PI).to_significand().unwrap(),
        14488038916154245120u64
    );
}
Source

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

Returns a reference to the significand of a Float.

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

§Worst-case complexity

Constant time and additional memory.

§Examples
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_base::num::arithmetic::traits::PowerOf2;
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_base::num::basic::traits::One;
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::Float;
#[cfg(not(feature = "32_bit_limbs"))]
use malachite_nz::natural::Natural;

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

#[cfg(not(feature = "32_bit_limbs"))]
{
    assert_eq!(
        *Float::ONE.significand_ref().unwrap(),
        Natural::power_of_2(63)
    );
    assert_eq!(
        *Float::from(std::f64::consts::PI).significand_ref().unwrap(),
        14488038916154245120u64
    );
}
Source

pub fn get_exponent(&self) -> Option<i32>

Returns a Float’s exponent.

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

and, if $x$ is finite and nonzero,

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

The output is in the range $[-(2^{30}-1), 2^{30}-1]$.

§Worst-case complexity

Constant time and additional memory.

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

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

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

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

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

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

§Worst-case complexity

Constant time and additional memory.

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

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

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

pub fn get_min_prec(&self) -> Option<u64>

Returns the minimum precision necessary to represent the given Float’s value.

For example, Float:one_prec(100) has a precision of 100, but its minimum precision is 1, because that’s all that’s necessary to represent the value 1.

The minimum precision is always less than or equal to the actual precision.

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

§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(): the trailing-zeros scan runs through the low zero limbs of the significand.

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

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

assert_eq!(Float::ONE.get_min_prec(), Some(1));
assert_eq!(Float::one_prec(100).get_min_prec(), Some(1));
assert_eq!(Float::from(std::f64::consts::PI).get_min_prec(), Some(50));
Source

pub fn subnormalize_ref( &self, o: Ordering, normal_exp_min: i64, rm: RoundingMode, ) -> (Self, Ordering)

Emulates gradual underflow, adjusting a rounded result as if it had been computed in a floating-point format with a limited exponent range and subnormal numbers, such as an IEEE 754 format.

self should be the result of a computation correctly rounded to its own precision, with o indicating whether that result is less than, equal to, or greater than the exact value, and rm the rounding mode that was used. If the value is at least $2^{\text{{normal\_exp\_min}}-1}$ in absolute value (or is NaN, infinite, or zero), it is returned unchanged along with o. Otherwise it lies in the emulated format’s subnormal range, where fewer than prec significand bits are available, and it is rounded again to the available precision, with a correction that makes the result identical to what a single rounding of the exact value into the subnormal format would have produced. The returned Ordering compares the final result to the exact value. Values smaller than half the minimum subnormal round to zero.

The precision of the result equals the precision of the input, except that zero results carry no precision.

To emulate a standard format, pass the format’s minimum normal exponent: for example, $-125$ for IEEE 754 binary32 and $-1021$ for binary64, using the convention in which the significand lies in $[1/2, 1)$. This function is the analogue of mpfr_subnormalize, with the exponent range passed explicitly rather than set globally, and with values below the smallest subnormal handled here rather than by the preceding operation’s underflow.

The Float is taken by reference.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the value is not exactly representable in the emulated format.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;

// Values smaller than half the minimum subnormal round to zero.
let x = Float::from_natural_prec(Natural::from(8u32), 4).0 >> 15u32;
assert_eq!(x.to_string(), "0.000244");
let (y, o) = x.subnormalize_ref(Equal, -5, Nearest);
assert_eq!(y.to_string(), "0.0");
assert_eq!(o, Less);
Source

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

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

If the Float is positive, its ulp is the distance to the next-largest Float with the same precision; if it is negative, the next-smallest. (This definition works even if the Float is the largest in its binade. If the Float is the largest in its binade and has the maximum exponent, we can define its ulp to be the distance to the next-smallest Float with the same precision if positive, and to the next-largest Float with the same precision if negative.)

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

This function does not overflow or underflow, technically. But it is possible that a Float’s ulp is too small to represent, for example if the Float has the minimum exponent and its precision is greater than 1, or if the precision is extremely large in general. In such cases, None is returned.

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

and, if $x$ is finite and nonzero,

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

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

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

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

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

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

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

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

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

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

pub fn min_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the specified precision and with the specified rounding mode. An Ordering is also returned, indicating whether the rounded minimum is less than, equal to, or greater than the exact minimum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then rounded to prec bits using rm, as by Float::from_float_prec_round; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is prec.

If you know you’ll be using Nearest, consider using Float::min_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::min_round instead. If both of these things are true, consider using Float::min instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the selected operand cannot be represented exactly at a precision of prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_prec_round_ref_val(Float::from(E), 5, Floor);
assert_eq!(min.to_string(), "2.62");
assert_eq!(o, Less);

let (min, o) = Float::from(PI).min_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(min.to_string(), "2.75");
assert_eq!(o, Greater);

let (min, o) = Float::from(PI).min_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(min.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn min_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the specified precision and with the specified rounding mode. An Ordering is also returned, indicating whether the rounded minimum is less than, equal to, or greater than the exact minimum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then rounded to prec bits using rm, as by Float::from_float_prec_round; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

Both Floats are taken by reference.

If the output has a precision, it is prec.

If you know you’ll be using Nearest, consider using Float::min_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::min_round instead. If both of these things are true, consider using Float::min instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the selected operand cannot be represented exactly at a precision of prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(min.to_string(), "2.62");
assert_eq!(o, Less);

let (min, o) = Float::from(PI).min_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(min.to_string(), "2.75");
assert_eq!(o, Greater);

let (min, o) = Float::from(PI).min_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(min.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn min_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the specified precision and with the Nearest rounding mode. An Ordering is also returned, indicating whether the rounded minimum is less than, equal to, or greater than the exact minimum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then rounded to prec bits using the Nearest rounding mode, as by Float::from_float_prec; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is prec.

If you want to use a rounding mode other than Nearest, consider using Float::min_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::min instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_prec_ref_val(Float::from(E), 5);
assert_eq!(min.to_string(), "2.75");
assert_eq!(o, Greater);

let (min, o) = Float::from(PI).min_prec_ref_val(Float::from(E), 20);
assert_eq!(min.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn min_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the specified precision and with the Nearest rounding mode. An Ordering is also returned, indicating whether the rounded minimum is less than, equal to, or greater than the exact minimum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then rounded to prec bits using the Nearest rounding mode, as by Float::from_float_prec; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

Both Floats are taken by reference.

If the output has a precision, it is prec.

If you want to use a rounding mode other than Nearest, consider using Float::min_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::min instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_prec_ref_ref(&Float::from(E), 5);
assert_eq!(min.to_string(), "2.75");
assert_eq!(o, Greater);

let (min, o) = Float::from(PI).min_prec_ref_ref(&Float::from(E), 20);
assert_eq!(min.to_string(), "2.7182808");
assert_eq!(o, Less);
Source

pub fn min_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the maximum of the operands’ precisions and with the specified rounding mode. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the result does not depend on rm, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to specify an output precision, consider using Float::min_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::min instead.

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_round_ref_val(Float::from(E), Floor);
assert_eq!(min.to_string(), "2.7182818284590451");
assert_eq!(o, Equal);

let (min, o) = Float::NAN.min_round_ref_val(Float::from(PI), Floor);
assert_eq!(min.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (min, o) = Float::ZERO.min_round_ref_val(Float::NEGATIVE_ZERO, Floor);
assert_eq!(min.to_string(), "-0.0");
assert_eq!(o, Equal);
Source

pub fn min_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the maximum of the operands’ precisions and with the specified rounding mode. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the result does not depend on rm, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

Both Floats are taken by reference.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to specify an output precision, consider using Float::min_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::min instead.

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_round_ref_ref(&Float::from(E), Floor);
assert_eq!(min.to_string(), "2.7182818284590451");
assert_eq!(o, Equal);

let (min, o) = Float::NAN.min_round_ref_ref(&Float::from(PI), Floor);
assert_eq!(min.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (min, o) = Float::ZERO.min_round_ref_ref(&Float::NEGATIVE_ZERO, Floor);
assert_eq!(min.to_string(), "-0.0");
assert_eq!(o, Equal);
Source

pub fn min_ref_val(&self, other: Self) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the maximum of the operands’ precisions. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to use a rounding mode other than Nearest, consider using Float::min_round instead. If you want to specify an output precision, consider using Float::min_prec instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_ref_val(Float::from(E));
assert_eq!(min.to_string(), "2.7182818284590451");
assert_eq!(o, Equal);

let (min, o) = Float::NAN.min_ref_val(Float::from(PI));
assert_eq!(min.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (min, o) = Float::ZERO.min_ref_val(Float::NEGATIVE_ZERO);
assert_eq!(min.to_string(), "-0.0");
assert_eq!(o, Equal);
Source

pub fn min_ref_ref(&self, other: &Self) -> (Self, Ordering)

Returns the minimum of two Floats, rounding the result to the maximum of the operands’ precisions. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a negative zero is selected if either zero is negative, and a positive zero otherwise. Otherwise, the smaller operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

Both Floats are taken by reference.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to use a rounding mode other than Nearest, consider using Float::min_round instead. If you want to specify an output precision, consider using Float::min_prec instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (min, o) = Float::from(PI).min_ref_ref(&Float::from(E));
assert_eq!(min.to_string(), "2.7182818284590451");
assert_eq!(o, Equal);

let (min, o) = Float::NAN.min_ref_ref(&Float::from(PI));
assert_eq!(min.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (min, o) = Float::ZERO.min_ref_ref(&Float::NEGATIVE_ZERO);
assert_eq!(min.to_string(), "-0.0");
assert_eq!(o, Equal);
Source

pub fn max_prec_round_ref_val( &self, other: Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the specified precision and with the specified rounding mode. An Ordering is also returned, indicating whether the rounded maximum is less than, equal to, or greater than the exact maximum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then rounded to prec bits using rm, as by Float::from_float_prec_round; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is prec.

If you know you’ll be using Nearest, consider using Float::max_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::max_round instead. If both of these things are true, consider using Float::max instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the selected operand cannot be represented exactly at a precision of prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_prec_round_ref_val(Float::from(E), 5, Floor);
assert_eq!(max.to_string(), "3.12");
assert_eq!(o, Less);

let (max, o) = Float::from(PI).max_prec_round_ref_val(Float::from(E), 5, Ceiling);
assert_eq!(max.to_string(), "3.25");
assert_eq!(o, Greater);

let (max, o) = Float::from(PI).max_prec_round_ref_val(Float::from(E), 20, Nearest);
assert_eq!(max.to_string(), "3.1415939");
assert_eq!(o, Greater);
Source

pub fn max_prec_round_ref_ref( &self, other: &Self, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the specified precision and with the specified rounding mode. An Ordering is also returned, indicating whether the rounded maximum is less than, equal to, or greater than the exact maximum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then rounded to prec bits using rm, as by Float::from_float_prec_round; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

Both Floats are taken by reference.

If the output has a precision, it is prec.

If you know you’ll be using Nearest, consider using Float::max_prec instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::max_round instead. If both of these things are true, consider using Float::max instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact but the selected operand cannot be represented exactly at a precision of prec bits.

§Examples
use core::f64::consts::{E, PI};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_prec_round_ref_ref(&Float::from(E), 5, Floor);
assert_eq!(max.to_string(), "3.12");
assert_eq!(o, Less);

let (max, o) = Float::from(PI).max_prec_round_ref_ref(&Float::from(E), 5, Ceiling);
assert_eq!(max.to_string(), "3.25");
assert_eq!(o, Greater);

let (max, o) = Float::from(PI).max_prec_round_ref_ref(&Float::from(E), 20, Nearest);
assert_eq!(max.to_string(), "3.1415939");
assert_eq!(o, Greater);
Source

pub fn max_prec_ref_val(&self, other: Self, prec: u64) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the specified precision and with the Nearest rounding mode. An Ordering is also returned, indicating whether the rounded maximum is less than, equal to, or greater than the exact maximum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then rounded to prec bits using the Nearest rounding mode, as by Float::from_float_prec; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is prec.

If you want to use a rounding mode other than Nearest, consider using Float::max_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::max instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_prec_ref_val(Float::from(E), 5);
assert_eq!(max.to_string(), "3.12");
assert_eq!(o, Less);

let (max, o) = Float::from(PI).max_prec_ref_val(Float::from(E), 20);
assert_eq!(max.to_string(), "3.1415939");
assert_eq!(o, Greater);
Source

pub fn max_prec_ref_ref(&self, other: &Self, prec: u64) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the specified precision and with the Nearest rounding mode. An Ordering is also returned, indicating whether the rounded maximum is less than, equal to, or greater than the exact maximum. Whenever this function returns a NaN it also returns Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then rounded to prec bits using the Nearest rounding mode, as by Float::from_float_prec; like that function, this function may overflow if the selected operand has the maximum exponent, and it never underflows.

Both Floats are taken by reference.

If the output has a precision, it is prec.

If you want to use a rounding mode other than Nearest, consider using Float::max_prec_round instead. If you know that your target precision is the maximum of the precisions of the two inputs, consider using Float::max instead.

§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_prec_ref_ref(&Float::from(E), 5);
assert_eq!(max.to_string(), "3.12");
assert_eq!(o, Less);

let (max, o) = Float::from(PI).max_prec_ref_ref(&Float::from(E), 20);
assert_eq!(max.to_string(), "3.1415939");
assert_eq!(o, Greater);
Source

pub fn max_round_ref_val( &self, other: Self, rm: RoundingMode, ) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the maximum of the operands’ precisions and with the specified rounding mode. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the result does not depend on rm, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to specify an output precision, consider using Float::max_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::max instead.

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_round_ref_val(Float::from(E), Floor);
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::NAN.max_round_ref_val(Float::from(PI), Floor);
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::ZERO.max_round_ref_val(Float::NEGATIVE_ZERO, Floor);
assert_eq!(max.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn max_round_ref_ref( &self, other: &Self, rm: RoundingMode, ) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the maximum of the operands’ precisions and with the specified rounding mode. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the result does not depend on rm, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

Both Floats are taken by reference.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to specify an output precision, consider using Float::max_prec_round instead. If you know you’ll be using the Nearest rounding mode, consider using Float::max instead.

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_round_ref_ref(&Float::from(E), Floor);
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::NAN.max_round_ref_ref(&Float::from(PI), Floor);
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::ZERO.max_round_ref_ref(&Float::NEGATIVE_ZERO, Floor);
assert_eq!(max.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn max_ref_val(&self, other: Self) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the maximum of the operands’ precisions. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

The first Float is taken by reference and the second by value.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to use a rounding mode other than Nearest, consider using Float::max_round instead. If you want to specify an output precision, consider using Float::max_prec instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_ref_val(Float::from(E));
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::NAN.max_ref_val(Float::from(PI));
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::ZERO.max_ref_val(Float::NEGATIVE_ZERO);
assert_eq!(max.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn max_ref_ref(&self, other: &Self) -> (Self, Ordering)

Returns the maximum of two Floats, rounding the result to the maximum of the operands’ precisions. An Ordering is also returned; since the target precision is at least as high as the precision of the selected operand, the rounding is always exact, and the Ordering is always Equal.

If one of the operands is a NaN, the other operand is selected; if both are NaNs, the result is NaN. If both operands are zeros, a positive zero is selected if either zero is positive, and a negative zero otherwise. Otherwise, the larger operand is selected.

The selected operand is then padded to the target precision. This never rounds, overflows, or underflows.

Both Floats are taken by reference.

If the output has a precision, it is the maximum of the operands’ precisions.

If you want to use a rounding mode other than Nearest, consider using Float::max_round instead. If you want to specify an output precision, consider using Float::max_prec instead.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

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

§Examples
use core::f64::consts::{E, PI};
use malachite_base::num::basic::traits::{NaN, NegativeZero, Zero};
use malachite_float::Float;
use std::cmp::Ordering::*;

let (max, o) = Float::from(PI).max_ref_ref(&Float::from(E));
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::NAN.max_ref_ref(&Float::from(PI));
assert_eq!(max.to_string(), "3.1415926535897931");
assert_eq!(o, Equal);

let (max, o) = Float::ZERO.max_ref_ref(&Float::NEGATIVE_ZERO);
assert_eq!(max.to_string(), "0.0");
assert_eq!(o, Equal);
Source

pub fn min_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the winning operand is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.min_rational_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "3.00");
assert_eq!(o, Equal);
Source

pub fn min_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero, or if rm is Exact and the winning operand is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.min_rational_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "3.00");
assert_eq!(o, Equal);
Source

pub fn min_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).min_rational_prec_ref_val(Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "3.00");
assert_eq!(o, Equal);
Source

pub fn min_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).min_rational_prec_ref_ref(&Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "3.00");
assert_eq!(o, Equal);
Source

pub fn min_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the winning operand is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(3u32).min_rational_round_ref_val(Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

pub fn min_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the smaller of a Float and a Rational, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Panics

Panics if rm is Exact and the winning operand is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(3u32).min_rational_round_ref_ref(&Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

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

Computes the smaller of a Float and a Rational, rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).min_rational_ref_val(Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

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

Computes the smaller of a Float and a Rational, rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact smaller value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), so a negative zero is preserved.
§Worst-case complexity

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

$M(n) = O(n)$

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

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).min_rational_ref_ref(&Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Equal);
Source

pub fn max_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the winning operand is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.max_rational_prec_round_ref_val(y, 5, Floor);
assert_eq!(r.to_string(), "3.12");
assert_eq!(o, Less);

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.max_rational_prec_round_ref_val(y, 5, Ceiling);
assert_eq!(r.to_string(), "3.25");
assert_eq!(o, Greater);
Source

pub fn max_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the specified precision and with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits(), prec).

§Panics

Panics if prec is zero, or if rm is Exact and the winning operand is not exactly representable with prec bits.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.max_rational_prec_round_ref_ref(&y, 5, Floor);
assert_eq!(r.to_string(), "3.12");
assert_eq!(o, Less);

let x = Float::from(3u32);
let y = Rational::from_signeds(22, 7);
let (r, o) = x.max_rational_prec_round_ref_ref(&y, 5, Ceiling);
assert_eq!(r.to_string(), "3.25");
assert_eq!(o, Greater);
Source

pub fn max_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).max_rational_prec_ref_val(Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "3.12");
assert_eq!(o, Less);
Source

pub fn max_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the nearest value of the specified precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits(), prec).

§Panics

Panics if prec is zero.

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).max_rational_prec_ref_ref(&Rational::from_signeds(22, 7), 5);
assert_eq!(r.to_string(), "3.12");
assert_eq!(o, Less);
Source

pub fn max_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the Float’s precision, with the specified rounding mode. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits()).

§Panics

Panics if rm is Exact and the winning operand is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(3u32).max_rational_round_ref_val(Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Less);
Source

pub fn max_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the Float’s precision, with the specified rounding mode. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits()).

§Panics

Panics if rm is Exact and the winning operand is not exactly representable with the output precision.

§Examples
use core::cmp::Ordering::*;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) =
    Float::from(3u32).max_rational_round_ref_ref(&Rational::from_signeds(22, 7), Floor);
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Less);
Source

pub fn max_rational_ref_val(&self, other: Rational) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the nearest value of the Float’s precision. The Float is taken by reference and the Rational by value. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits()).

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).max_rational_ref_val(Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Less);
Source

pub fn max_rational_ref_ref(&self, other: &Rational) -> (Self, Ordering)

Computes the larger of a Float and a Rational, rounding the result to the nearest value of the Float’s precision. The Float and the Rational are both taken by reference. An Ordering is also returned, indicating whether the result is less than, equal to, or greater than the exact larger value. Although NaNs are not comparable to any Float, whenever this function returns a NaN it also returns Equal.

The comparison is exact, and only the winning operand is rounded. Converting the Rational to a Float first could select the wrong operand, when the conversion crosses the other operand’s value.

Special cases:

  • If the Float is NaN, the Rational operand is returned (rounded), as with the Float-Float functions.
  • If the operands are equal, the Float operand is returned (rounded), except that a negative zero loses the tie against the (unsigned, treated as positive) zero Rational: the result is then a positive zero, matching the positive-zero preference of mpfr_max.
§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.complexity(), other.significant_bits()).

§Examples
use core::cmp::Ordering::*;
use malachite_float::Float;
use malachite_q::Rational;

let (r, o) = Float::from(3u32).max_rational_ref_ref(&Rational::from_signeds(22, 7));
assert_eq!(r.to_string(), "3.0");
assert_eq!(o, Less);
Source

pub fn sci_mantissa_and_exponent_round<T: PrimitiveFloat>( &self, rm: RoundingMode, ) -> Option<(T, i32, Ordering)>

Returns a Float’s scientific mantissa and exponent, rounding according to the specified rounding mode. An Ordering is also returned, indicating whether the mantissa and exponent represent a value that is less than, equal to, or greater than the original value.

When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The conversion might not be exact, so we round to the nearest float using the provided rounding mode. If the rounding mode is Exact but the conversion is not exact, None is returned. $$ f(x, r) \approx \left (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor\right ). $$

This function does not overflow or underflow. The returned exponent is always in the range $[-2^{30}, 2^{30}-1]$. Notice that although a Float’s maximum scientific exponent is $2^{30}-2$, this function may return an exponent one larger than this limit due to rounding.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::num::float::NiceFloat;
use malachite_base::rounding_modes::RoundingMode::{self, *};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering::{self, *};

let test = |x: Float, rm: RoundingMode, out: Option<(f32, i32, Ordering)>| {
    assert_eq!(
        x.sci_mantissa_and_exponent_round(rm)
            .map(|(m, e, o)| (NiceFloat(m), e, o)),
        out.map(|(m, e, o)| (NiceFloat(m), e, o))
    );
};
test(Float::from(3u32), Floor, Some((1.5, 1, Equal)));
test(Float::from(3u32), Down, Some((1.5, 1, Equal)));
test(Float::from(3u32), Ceiling, Some((1.5, 1, Equal)));
test(Float::from(3u32), Up, Some((1.5, 1, Equal)));
test(Float::from(3u32), Nearest, Some((1.5, 1, Equal)));
test(Float::from(3u32), Exact, Some((1.5, 1, Equal)));

let x = Float::from(std::f64::consts::PI);
test(x.clone(), Floor, Some((1.5707963, 1, Less)));
test(x.clone(), Down, Some((1.5707963, 1, Less)));
test(x.clone(), Ceiling, Some((1.5707964, 1, Greater)));
test(x.clone(), Up, Some((1.5707964, 1, Greater)));
test(x.clone(), Nearest, Some((1.5707964, 1, Greater)));
test(x.clone(), Exact, None);

test(
    Float::from(1000000000u32),
    Nearest,
    Some((1.8626451, 29, Equal)),
);
test(
    Float::exact_from(Natural::from(10u32).pow(52)),
    Nearest,
    Some((1.670478, 172, Greater)),
);

test(Float::exact_from(Natural::from(10u32).pow(52)), Exact, None);
Source

pub const MAX_EXPONENT: i32 = 0x3fff_ffff

Source

pub const MIN_EXPONENT: i32

Trait Implementations§

Source§

impl Binary for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef to a binary String.

The output is the wrapped Float’s Binary output, followed by # and the precision. Using the # format flag prepends "0b" to the value, after any sign.

Like the hexadecimal form, this identifies a Float exactly: the digits are exact because the base is a power of two, and the suffix supplies the precision, which the digits alone may not determine.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.0.complexity().

§Examples
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(format!("{:b}", ComparableFloatRef(&Float::ONE)), "1.0#1");
assert_eq!(format!("{:#b}", ComparableFloatRef(&Float::ONE)), "0b1.0#1");
assert_eq!(
    format!("{:#b}", ComparableFloatRef(&Float::from(1.5))),
    "0b1.1#2"
);
assert_eq!(
    format!("{:#b}", ComparableFloatRef(&Float::from(255))),
    "0b11111111.0#8"
);
assert_eq!(format!("{:#b}", ComparableFloatRef(&Float::NAN)), "NaN");
Source§

impl<'a> Clone for ComparableFloatRef<'a>

Source§

fn clone(&self) -> ComparableFloatRef<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef 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.0.complexity().

§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::strings::ToDebugString;
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(ComparableFloatRef(&Float::ONE).to_debug_string(), "1.0#1");
assert_eq!(
    ComparableFloatRef(&Float::from(1.5)).to_debug_string(),
    "1.5#2"
);
Source§

impl Deref for ComparableFloatRef<'_>

Source§

fn deref(&self) -> &Float

Allows a ComparableFloatRef to dereference to a Float.

use malachite_base::num::basic::traits::One;
use malachite_float::{ComparableFloatRef, Float};

let x = Float::ONE;
let y = ComparableFloatRef(&x);
assert_eq!(*y, Float::ONE);
Source§

type Target = Float

The resulting type after dereferencing.
Source§

impl Display for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef to a String.

The output is the wrapped Float’s Display output, followed by # and the precision, as in "1.5#2". Because a Float’s decimal digits do not determine its precision, the suffix is what makes the output identify the value that ComparableFloatRef’s Eq compares. The special values and the zeros have no precision, so they are written exactly as Float writes 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 self.0.complexity().

§Examples
use malachite_base::num::basic::traits::{NaN, One, Zero};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(ComparableFloatRef(&Float::ONE).to_string(), "1.0#1");
assert_eq!(ComparableFloatRef(&Float::from(1.5)).to_string(), "1.5#2");
assert_eq!(ComparableFloatRef(&Float::from(255)).to_string(), "255.0#8");

// The specials and the zeros carry no precision.
assert_eq!(ComparableFloatRef(&Float::NAN).to_string(), "NaN");
assert_eq!(ComparableFloatRef(&Float::ZERO).to_string(), "0.0");
Source§

impl Eq for ComparableFloatRef<'_>

Source§

impl<'a> EqAbs<ComparableFloatRef<'a>> for ComparableFloatRef<'_>

Source§

fn eq_abs(&self, other: &ComparableFloatRef<'a>) -> bool

Compares the absolute values of two ComparableFloatRefs for equality.

This implementation ignores the IEEE 754 standard in favor of an equality operation that respects the expected properties of symmetry, reflexivity, and transitivity. Using ComparableFloatRef, NaNs are equal to themselves. There is a single, unique NaN; there’s no concept of signalling NaNs. ComparableFloatRefs with different precisions are unequal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::{NaN, NegativeZero, One, Two, Zero};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(
    ComparableFloatRef(&Float::NAN),
    ComparableFloatRef(&Float::NAN)
);
assert_eq!(
    ComparableFloatRef(&Float::ZERO),
    ComparableFloatRef(&Float::ZERO)
);
assert_eq!(
    ComparableFloatRef(&Float::NEGATIVE_ZERO),
    ComparableFloatRef(&Float::NEGATIVE_ZERO)
);
assert_ne!(
    ComparableFloatRef(&Float::ZERO),
    ComparableFloatRef(&Float::NEGATIVE_ZERO)
);

assert_eq!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::ONE)
);
assert_ne!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::TWO)
);
assert_ne!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::one_prec(100))
);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl Hash for ComparableFloatRef<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Computes a hash of a ComparableFloatRef.

The hash is compatible with ComparableFloatRef equality: all NaNs hash to the same value.

§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().

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 LowerHex for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef to a hexadecimal String.

The output is the wrapped Float’s LowerHex output, followed by # and the precision, as in "1.8#2". Using the # format flag prepends "0x" to the value, after any sign, giving "0x1.8#2".

This is the form that identifies a Float exactly: the digits are exact because the base is a power of two, and the suffix supplies the precision. It is also what a base-16 FromStringBase parse accepts, so the two round-trip, which is why the tests use it as their canonical label.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.0.complexity().

§Examples
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(format!("{:x}", ComparableFloatRef(&Float::ONE)), "1.0#1");
assert_eq!(format!("{:#x}", ComparableFloatRef(&Float::ONE)), "0x1.0#1");
assert_eq!(
    format!("{:#x}", ComparableFloatRef(&Float::from(1.5))),
    "0x1.8#2"
);
assert_eq!(
    format!("{:#x}", ComparableFloatRef(&Float::from(255))),
    "0xff.0#8"
);
assert_eq!(format!("{:#x}", ComparableFloatRef(&Float::NAN)), "NaN");
Source§

impl Octal for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef to an octal String.

The output is the wrapped Float’s Octal output, followed by # and the precision. Using the # format flag prepends "0o" to the value, after any sign.

Like the hexadecimal form, this identifies a Float exactly: the digits are exact because the base is a power of two, and the suffix supplies the precision, which the digits alone may not determine.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.0.complexity().

§Examples
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(format!("{:o}", ComparableFloatRef(&Float::ONE)), "1.0#1");
assert_eq!(format!("{:#o}", ComparableFloatRef(&Float::ONE)), "0o1.0#1");
assert_eq!(
    format!("{:#o}", ComparableFloatRef(&Float::from(1.5))),
    "0o1.4#2"
);
assert_eq!(
    format!("{:#o}", ComparableFloatRef(&Float::from(255))),
    "0o377.0#8"
);
assert_eq!(format!("{:#o}", ComparableFloatRef(&Float::NAN)), "NaN");
Source§

impl<'a> Ord for ComparableFloatRef<'a>

Source§

fn cmp(&self, other: &Self) -> Ordering

Compares two ComparableFloatRefs.

This implementation does not follow the IEEE 754 standard. This is how ComparableFloatRefs are ordered, least to greatest:

  • $-\infty$
  • Negative nonzero finite floats
  • Negative zero
  • NaN
  • Positive zero
  • Positive nonzero finite floats
  • $\infty$

When comparing two finite floats with the same numeric value but different precisions, the one with greater precision is ordered to be further from zero.

For different comparison behavior that follows the IEEE 754 standard, consider just using Float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero,
};
use malachite_float::{ComparableFloatRef, Float};
use std::cmp::Ordering::*;

assert_eq!(
    ComparableFloatRef(&Float::NAN).partial_cmp(&ComparableFloatRef(&Float::NAN)),
    Some(Equal)
);
assert!(ComparableFloatRef(&Float::ZERO) > ComparableFloatRef(&Float::NEGATIVE_ZERO));
assert!(ComparableFloatRef(&Float::ONE) < ComparableFloatRef(&Float::one_prec(100)));
assert!(ComparableFloatRef(&Float::INFINITY) > ComparableFloatRef(&Float::ONE));
assert!(ComparableFloatRef(&Float::NEGATIVE_INFINITY) < ComparableFloatRef(&Float::ONE));
assert!(ComparableFloatRef(&Float::ONE_HALF) < ComparableFloatRef(&Float::ONE));
assert!(ComparableFloatRef(&Float::ONE_HALF) > ComparableFloatRef(&Float::NEGATIVE_ONE));
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<'a> OrdAbs for ComparableFloatRef<'a>

Source§

fn cmp_abs(&self, other: &Self) -> Ordering

Compares the absolute values of two ComparableFloatRefs.

This implementation does not follow the IEEE 754 standard. This is how ComparableFloatRefs are ordered by absolute value, from least to greatest:

  • NaN
  • Positive and negative zero
  • Nonzero finite floats
  • $\infty$ and $-\infty$

For different comparison behavior that follows the IEEE 754 standard, consider just using Float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::{
    Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero,
};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::{ComparableFloatRef, Float};
use std::cmp::Ordering::*;

assert_eq!(
    ComparableFloatRef(&Float::NAN).partial_cmp_abs(&ComparableFloatRef(&Float::NAN)),
    Some(Equal)
);
assert_eq!(
    ComparableFloatRef(&Float::ZERO)
        .partial_cmp_abs(&ComparableFloatRef(&Float::NEGATIVE_ZERO)),
    Some(Equal)
);
assert!(ComparableFloatRef(&Float::ONE).lt_abs(&ComparableFloatRef(&Float::one_prec(100))));
assert!(ComparableFloatRef(&Float::INFINITY).gt_abs(&ComparableFloatRef(&Float::ONE)));
assert!(
    ComparableFloatRef(&Float::NEGATIVE_INFINITY).gt_abs(&ComparableFloatRef(&Float::ONE))
);
assert!(ComparableFloatRef(&Float::ONE_HALF).lt_abs(&ComparableFloatRef(&Float::ONE)));
assert!(
    ComparableFloatRef(&Float::ONE_HALF).lt_abs(&ComparableFloatRef(&Float::NEGATIVE_ONE))
);
Source§

impl<'a> PartialEq<ComparableFloatRef<'a>> for ComparableFloatRef<'_>

Source§

fn eq(&self, other: &ComparableFloatRef<'a>) -> bool

Compares two ComparableFloatRefs for equality.

This implementation ignores the IEEE 754 standard in favor of an equality operation that respects the expected properties of symmetry, reflexivity, and transitivity. Using ComparableFloatRef, NaNs are equal to themselves. There is a single, unique NaN; there’s no concept of signalling NaNs. Positive and negative zero are two distinct values, not equal to each other. ComparableFloatRefs with different precisions are unequal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::{NaN, NegativeZero, One, Two, Zero};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(
    ComparableFloatRef(&Float::NAN),
    ComparableFloatRef(&Float::NAN)
);
assert_eq!(
    ComparableFloatRef(&Float::ZERO),
    ComparableFloatRef(&Float::ZERO)
);
assert_eq!(
    ComparableFloatRef(&Float::NEGATIVE_ZERO),
    ComparableFloatRef(&Float::NEGATIVE_ZERO)
);
assert_ne!(
    ComparableFloatRef(&Float::ZERO),
    ComparableFloatRef(&Float::NEGATIVE_ZERO)
);

assert_eq!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::ONE)
);
assert_ne!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::TWO)
);
assert_ne!(
    ComparableFloatRef(&Float::ONE),
    ComparableFloatRef(&Float::one_prec(100))
);
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for ComparableFloatRef<'_>

Source§

fn partial_cmp(&self, other: &ComparableFloatRef<'_>) -> Option<Ordering>

Compares two ComparableFloatRefs.

See the documentation for the Ord implementation.

1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrdAbs for ComparableFloatRef<'_>

Source§

fn partial_cmp_abs(&self, other: &ComparableFloatRef<'_>) -> Option<Ordering>

Compares the absolute values of two ComparableFloatRefs.

See the documentation for the Ord 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 UpperHex for ComparableFloatRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a ComparableFloatRef to a hexadecimal String.

The output is the wrapped Float’s UpperHex output, followed by # and the precision. Using the # format flag prepends "0x" to the value, after any sign.

Like the hexadecimal form, this identifies a Float exactly: the digits are exact because the base is a power of two, and the suffix supplies the precision, which the digits alone may not determine.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.0.complexity().

§Examples
use malachite_base::num::basic::traits::{NaN, One};
use malachite_float::{ComparableFloatRef, Float};

assert_eq!(format!("{:X}", ComparableFloatRef(&Float::ONE)), "1.0#1");
assert_eq!(format!("{:#X}", ComparableFloatRef(&Float::ONE)), "0x1.0#1");
assert_eq!(
    format!("{:#X}", ComparableFloatRef(&Float::from(255))),
    "0xFF.0#8"
);
// As for `Float`, the prefix stays lowercase, matching the primitive integers.
assert_eq!(
    format!("{:#X}", ComparableFloatRef(&Float::from(-1.5))),
    "-0x1.8#2"
);
assert_eq!(format!("{:#X}", ComparableFloatRef(&Float::NAN)), "NaN");

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToBinaryString for T
where T: Binary,

Source§

fn to_binary_string(&self) -> String

Returns the String produced by Ts Binary implementation.

§Examples
use malachite_base::strings::ToBinaryString;

assert_eq!(5u64.to_binary_string(), "101");
assert_eq!((-100i16).to_binary_string(), "1111111110011100");
Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToLowerHexString for T
where T: LowerHex,

Source§

fn to_lower_hex_string(&self) -> String

Returns the String produced by Ts LowerHex implementation.

§Examples
use malachite_base::strings::ToLowerHexString;

assert_eq!(50u64.to_lower_hex_string(), "32");
assert_eq!((-100i16).to_lower_hex_string(), "ff9c");
Source§

impl<T> ToOctalString for T
where T: Octal,

Source§

fn to_octal_string(&self) -> String

Returns the String produced by Ts Octal implementation.

§Examples
use malachite_base::strings::ToOctalString;

assert_eq!(50u64.to_octal_string(), "62");
assert_eq!((-100i16).to_octal_string(), "177634");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToUpperHexString for T
where T: UpperHex,

Source§

fn to_upper_hex_string(&self) -> String

Returns the String produced by Ts UpperHex implementation.

§Examples
use malachite_base::strings::ToUpperHexString;

assert_eq!(50u64.to_upper_hex_string(), "32");
assert_eq!((-100i16).to_upper_hex_string(), "FF9C");
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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