pub struct Float(/* private fields */);
Expand description
A floating-point number.
Float
s are currently experimental. They are missing many important functions. However, the
functions that are currently implemented are thoroughly tested and documented, with the
exception of string conversion functions. The current string conversions are incomplete and will
be changed in the future to match MPFR’s behavior.
Float
s are similar to the primitive floats defined by the IEEE 754 standard. They include NaN,
positive and $-\infty$, and positive and negative zero. There is only one NaN; there is no
concept of a NaN payload.
All the finite Float
s are dyadic rationals (rational numbers whose denominator is a power of
2). A finite Float
consists of several fields:
- a sign, which denotes whether the
Float
is positive or negative; - a significand, which is a
Natural
number whose value is equal to theFloat
’s absolute value multiplied by a power of 2; - an exponent, which is one more than the floor of the base-2 logarithm of the
Float
’s absolute value; - and finally, a precision, which is greater than zero and indicates the number of significant
bits. It is common to think of a
Float
as an approximation to some real number, and the precision indicates how good the approximation is intended to be.
Float
s inherit some odd behavior from the IEEE 754 standard regarding comparison. A NaN
is
not equal to any Float
, including itself. Positive and negative zero compare as equal, despite
being two distinct values. Additionally, (and this is not IEEE 754’s fault), Float
s with
different precisions compare as equal if they represent the same numeric value.
In many cases, the above behavior is unsatisfactory, so the ComparableFloat
and
ComparableFloat
wrappers are provided. See their documentation for a description of their
comparison behavior.
In documentation, we will use the ‘$=$’ sign to mean that two Float
s are identical, writing
things like $-\text{NaN}=\text{NaN}$ and $-(0.0) = -0.0$.
The Float
type is designed to be very similar to the mpfr_t
type in
MPFR, and all Malachite
functions produce exactly the same result as their counterparts in MPFR, unless otherwise noted.
Here are the structural difference between Float
and mpfr_t
:
Float
can only represent a singleNaN
value, with no sign or payload.- Only finite, nonzero
Float
s have a significand, precision, and exponent. For otherFloat
s, these concepts are undefined. In particular, unlikempfr_t
zeros,Float
zeros do not have a precision. - The types of
mpfr_t
components are configuration- and platform-dependent. The types ofFloat
components are platform-independent, although theLimb
type is configuration-dependent: it isu64
by default, but may be changed tou32
using the--32_bit_limbs
compiler flag. The type of the exponent is alwaysi32
and the type of the precision is alwaysu64
. TheLimb
type only has a visible effect on the functions that extract the raw significand. All other functions have the same interface when compiled with eitherLimb
type.
Float
s whose precision is 64 bits or less can be represented without any memory allocation.
(Unless Malachite is compiled with 32_bit_limbs
, in which case the limit is 32).
Implementations§
Source§impl Float
impl Float
Sourcepub const fn abs_negative_zero(self) -> Float
pub const fn abs_negative_zero(self) -> Float
If self
is negative zero, returns positive zero; otherwise, returns self
, taking self
by value.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
assert_eq!(
ComparableFloat(Float::NAN.abs_negative_zero()),
ComparableFloat(Float::NAN)
);
assert_eq!(Float::INFINITY.abs_negative_zero(), Float::INFINITY);
assert_eq!(
Float::NEGATIVE_INFINITY.abs_negative_zero(),
Float::NEGATIVE_INFINITY
);
assert_eq!(
ComparableFloat(Float::ZERO.abs_negative_zero()),
ComparableFloat(Float::ZERO)
);
assert_eq!(
ComparableFloat(Float::NEGATIVE_ZERO.abs_negative_zero()),
ComparableFloat(Float::ZERO)
);
assert_eq!(Float::ONE.abs_negative_zero(), Float::ONE);
assert_eq!(Float::NEGATIVE_ONE.abs_negative_zero(), Float::NEGATIVE_ONE);
Sourcepub fn abs_negative_zero_ref(&self) -> Float
pub fn abs_negative_zero_ref(&self) -> Float
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
);
Sourcepub const fn abs_negative_zero_assign(&mut self)
pub const fn abs_negative_zero_assign(&mut self)
If self
is negative zero, replaces it with positive zero; otherwise, does nothing.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
let mut x = Float::NAN;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));
let mut x = Float::INFINITY;
x.abs_negative_zero_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x.abs_negative_zero_assign();
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::ZERO;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));
let mut x = Float::NEGATIVE_ZERO;
x.abs_negative_zero_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));
let mut x = Float::ONE;
x.abs_negative_zero_assign();
assert_eq!(x, Float::ONE);
let mut x = Float::NEGATIVE_ONE;
x.abs_negative_zero_assign();
assert_eq!(x, Float::NEGATIVE_ONE);
Source§impl Float
impl Float
Sourcepub fn add_prec_round(
self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_prec_round( self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, rounding the result to the specified precision and with the specified
rounding mode. Both Float
s are taken by value. An Ordering
is also returned,
indicating whether the rounded sum is less than, equal to, or greater than the exact sum.
Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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
instead. If you
know that your target precision is the maximum of the precisions of the two inputs, consider
using Float::add_round
instead. If both of these things are true, 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 prec
.
§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(Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "5.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round(Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "6.0");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_prec_round(Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "5.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round(Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round(Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "5.85988");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_prec_round(Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_round_val_ref(
self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_prec_round_val_ref( self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, rounding the result to the specified precision and with the specified
rounding mode. The first Float
is taken by value and the second by reference. An
Ordering
is also returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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_val_ref
instead.
If you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::add_round_val_ref
instead. If both of these things are true,
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 prec
.
§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.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "6.0");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "5.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "5.85988");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_prec_round_val_ref(&Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_round_ref_val(
&self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_prec_round_ref_val( &self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.8");
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.0");
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.8");
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.85987");
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.85988");
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.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_round_ref_ref(
&self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_prec_round_ref_ref( &self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, rounding the result to the specified precision and with the specified
rounding mode. Both Float
s 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.8");
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.0");
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.8");
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.85987");
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.85988");
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.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec(self, other: Float, prec: u64) -> (Float, Ordering)
pub fn add_prec(self, other: Float, prec: u64) -> (Float, Ordering)
Adds two Float
s, rounding the result to the nearest value of the specified precision.
Both Float
s are taken by value. An Ordering
is also returned, indicating whether the
rounded sum is less than, equal to, or greater than the exact sum. Although NaN
s are not
comparable to any Float
, whenever this function returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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
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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let (sum, o) = Float::from(PI).add_prec(Float::from(E), 5);
assert_eq!(sum.to_string(), "5.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec(Float::from(E), 20);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn add_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
Adds two Float
s, rounding the result to the nearest value of the specified precision.
The first Float
is taken by value and the second by reference. An Ordering
is also
returned, indicating whether the rounded sum is less than, equal to, or greater than the
exact sum. Although NaN
s are not comparable to any Float
, whenever this function
returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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_val_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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let (sum, o) = Float::from(PI).add_prec_val_ref(&Float::from(E), 5);
assert_eq!(sum.to_string(), "5.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_prec_val_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
pub fn add_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
Adds two Float
s, 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 NaN
s are not comparable to any Float
, whenever this function
returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.8");
assert_eq!(o, Less);
let (sum, o) = (&Float::from(PI)).add_prec_ref_val(Float::from(E), 20);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn add_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
Adds two Float
s, rounding the result to the nearest value of the specified precision.
Both Float
s 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 NaN
s are
not comparable to any Float
, whenever this function returns a NaN
it also returns
Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.8");
assert_eq!(o, Less);
let (sum, o) = (&Float::from(PI)).add_prec_ref_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "5.85987");
assert_eq!(o, Less);
Sourcepub fn add_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
pub fn add_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
Adds two Float
s, rounding the result with the specified rounding mode. Both Float
s
are taken by value. An Ordering
is also returned, indicating whether the rounded sum is
less than, equal to, or greater than the exact sum. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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
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(1)$
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(Float::from(E), Floor);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_round(Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_round(Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn add_round_val_ref(
self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_round_val_ref( self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, rounding the result with the specified rounding mode. The first
Float
is taken by value and the second by reference. An Ordering
is also returned,
indicating whether the rounded sum is less than, equal to, or greater than the exact sum.
Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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_val_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(m)$
where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits())
, and $m$ is 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_val_ref(&Float::from(E), Floor);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_round_val_ref(&Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_round_val_ref(&Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn add_round_ref_val(
&self,
other: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_round_ref_val( &self, other: Float, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.859874482048838");
assert_eq!(o, Less);
let (sum, o) = (&Float::from(PI)).add_round_ref_val(Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = (&Float::from(PI)).add_round_ref_val(Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn add_round_ref_ref(
&self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_round_ref_ref( &self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Adds two Float
s, rounding the result with the specified rounding mode. Both Float
s
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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn add_prec_round_assign(
&mut self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn add_prec_round_assign( &mut self, other: Float, prec: u64, rm: RoundingMode, ) -> Ordering
Adds a Float
to a Float
in place, rounding the result to the specified precision and
with the specified rounding mode. The Float
on the right-hand side is taken by value. An
Ordering
is returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s are not comparable to any Float
, whenever
this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::add_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::add_prec_assign
instead. If
you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::add_round_assign
instead. If both of these things are true,
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 prec
.
§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 mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign(Float::from(E), 5, Floor), Less);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign(Float::from(E), 5, Ceiling), Greater);
assert_eq!(x.to_string(), "6.0");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign(Float::from(E), 5, Nearest), Less);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign(Float::from(E), 20, Floor), Less);
assert_eq!(x.to_string(), "5.85987");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign(Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "5.85988");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign(Float::from(E), 20, Nearest), Less);
assert_eq!(x.to_string(), "5.85987");
Sourcepub fn add_prec_round_assign_ref(
&mut self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn add_prec_round_assign_ref( &mut self, other: &Float, prec: u64, rm: RoundingMode, ) -> Ordering
Adds a Float
to a Float
in place, rounding the result to the specified precision and
with the specified rounding mode. The Float
on the right-hand side is taken by
reference. An Ordering
is returned, indicating whether the rounded sum is less than,
equal to, or greater than the exact sum. Although NaN
s are not comparable to any
Float
, whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::add_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::add_prec_assign_ref
instead. If you know that your target precision is the maximum of the precisions of the two
inputs, consider using Float::add_round_assign_ref
instead. If both of these things are
true, 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 prec
.
§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 mut x = Float::from(PI);
assert_eq!(x.add_prec_round_assign_ref(&Float::from(E), 5, Floor), Less);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign_ref(&Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "6.0");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign_ref(&Float::from(E), 5, Nearest),
Less
);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign_ref(&Float::from(E), 20, Floor),
Less
);
assert_eq!(x.to_string(), "5.85987");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign_ref(&Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "5.85988");
let mut x = Float::from(PI);
assert_eq!(
x.add_prec_round_assign_ref(&Float::from(E), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "5.85987");
Sourcepub fn add_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
pub fn add_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
Adds a Float
to a Float
in place, rounding the result to the nearest value of the
specified precision. The Float
on the right-hand side is taken by value. An Ordering
is returned, indicating whether the rounded sum is less than, equal to, or greater than the
exact sum. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::add_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_prec_round_assign
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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(x.add_prec_assign(Float::from(E), 5), Less);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_assign(Float::from(E), 20), Less);
assert_eq!(x.to_string(), "5.85987");
Sourcepub fn add_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
pub fn add_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
Adds a Float
to a Float
in place, rounding the result to the nearest value of the
specified precision. The Float
on the right-hand side is taken by reference. An
Ordering
is returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s are not comparable to any Float
, whenever
this function sets the Float
to NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::add_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_prec_round_assign_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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(x.add_prec_assign_ref(&Float::from(E), 5), Less);
assert_eq!(x.to_string(), "5.8");
let mut x = Float::from(PI);
assert_eq!(x.add_prec_assign_ref(&Float::from(E), 20), Less);
assert_eq!(x.to_string(), "5.85987");
Sourcepub fn add_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
pub fn add_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
Adds a Float
to a Float
in place, rounding the result with the specified rounding
mode. The Float
on the right-hand side is taken by value. An Ordering
is returned,
indicating whether the rounded sum is less than, equal to, or greater than the exact sum.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to 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.
$$ x \gets 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| < 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.
See the Float::add_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using Float::add_prec_round_assign
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(1)$
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 mut x = Float::from(PI);
assert_eq!(x.add_round_assign(Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "5.859874482048838");
let mut x = Float::from(PI);
assert_eq!(x.add_round_assign(Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "5.859874482048839");
let mut x = Float::from(PI);
assert_eq!(x.add_round_assign(Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "5.859874482048838");
Sourcepub fn add_round_assign_ref(
&mut self,
other: &Float,
rm: RoundingMode,
) -> Ordering
pub fn add_round_assign_ref( &mut self, other: &Float, rm: RoundingMode, ) -> Ordering
Adds a Float
to a Float
in place, rounding the result with the specified rounding
mode. The Float
on the right-hand side is taken by reference. An Ordering
is
returned, indicating whether the rounded sum is less than, equal to, or greater than the
exact sum. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to 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.
$$ x \gets 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| < 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.
See the Float::add_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using
Float::add_prec_round_assign_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(m)$
where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits())
, and $m$ is 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 mut x = Float::from(PI);
assert_eq!(x.add_round_assign_ref(&Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "5.859874482048838");
let mut x = Float::from(PI);
assert_eq!(x.add_round_assign_ref(&Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "5.859874482048839");
let mut x = Float::from(PI);
assert_eq!(x.add_round_assign_ref(&Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "5.859874482048838");
Sourcepub fn add_rational_prec_round(
self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_prec_round( self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 value. An
Ordering
is also returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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
instead.
If you know that your target precision is the precision of the Float
input, consider
using Float::add_rational_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 \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(Rational::from_unsigneds(1u8, 3), 5, Floor);
assert_eq!(sum.to_string(), "3.4");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).add_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Ceiling);
assert_eq!(sum.to_string(), "3.5");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).add_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Nearest);
assert_eq!(sum.to_string(), "3.5");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).add_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Floor);
assert_eq!(sum.to_string(), "3.474922");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).add_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Ceiling);
assert_eq!(sum.to_string(), "3.474926");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).add_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Nearest);
assert_eq!(sum.to_string(), "3.474926");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_round_val_ref(
self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_prec_round_val_ref( self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 value 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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_val_ref
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::add_rational_round_val_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_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Floor,
);
assert_eq!(sum.to_string(), "3.4");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Ceiling,
);
assert_eq!(sum.to_string(), "3.5");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Nearest,
);
assert_eq!(sum.to_string(), "3.5");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Floor,
);
assert_eq!(sum.to_string(), "3.474922");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).add_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Ceiling,
);
assert_eq!(sum.to_string(), "3.474926");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Nearest,
);
assert_eq!(sum.to_string(), "3.474926");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_round_ref_val(
&self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.4");
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.5");
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.5");
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.474922");
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.474926");
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.474926");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_round_ref_ref(
&self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.4");
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.5");
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.5");
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.474922");
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.474926");
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.474926");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec(self, other: Rational, prec: u64) -> (Float, Ordering)
pub fn add_rational_prec(self, other: Rational, prec: u64) -> (Float, 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 value. An
Ordering
is also returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s are not comparable to any Float
, whenever
this function returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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
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(Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "4.8");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_rational_prec(Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "4.641594");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_val_ref(
self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn add_rational_prec_val_ref( self, other: &Rational, prec: u64, ) -> (Float, Ordering)
Adds a Float
and a Rational
, rounding the result to the nearest value of the
specified precision. The Float
is taken by value 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 NaN
s are not comparable to any Float
, whenever
this function returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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_val_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_val_ref(&Rational::exact_from(1.5), 5);
assert_eq!(sum.to_string(), "4.8");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).add_rational_prec_val_ref(&Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "4.641594");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_ref_val(
&self,
other: Rational,
prec: u64,
) -> (Float, Ordering)
pub fn add_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
, whenever
this function returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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.8");
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.641594");
assert_eq!(o, Greater);
Sourcepub fn add_rational_prec_ref_ref(
&self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn add_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
, whenever
this function returns a NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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)\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.
- 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.8");
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.641594");
assert_eq!(o, Greater);
Sourcepub fn add_rational_round(
self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_round( self, other: Rational, rm: RoundingMode, ) -> (Float, 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 value. An Ordering
is also
returned, indicating whether the rounded sum is less than, equal to, or greater than the
exact sum. Although NaN
s 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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
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(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "3.474925986923125");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).add_rational_round(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "3.474925986923129");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).add_rational_round(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "3.474925986923125");
assert_eq!(o, Less);
Sourcepub fn add_rational_round_val_ref(
self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_round_val_ref( self, other: &Rational, rm: RoundingMode, ) -> (Float, Ordering)
Adds a Float
and a Rational
, rounding the result with the specified rounding mode.
The Float
is taken by value 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 NaN
s 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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_val_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_val_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "3.474925986923125");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).add_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "3.474925986923129");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).add_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "3.474925986923125");
assert_eq!(o, Less);
Sourcepub fn add_rational_round_ref_val(
&self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.474925986923125");
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.474925986923129");
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.474925986923125");
assert_eq!(o, Less);
Sourcepub fn add_rational_round_ref_ref(
&self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn add_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.474925986923125");
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.474925986923129");
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.474925986923125");
assert_eq!(o, Less);
Sourcepub fn add_rational_prec_round_assign(
&mut self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn add_rational_prec_round_assign( &mut self, other: Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result to the specified precision
and with the specified rounding mode. The Rational
is taken by value. An Ordering
is
returned, indicating whether the rounded sum is less than, equal to, or greater than the
exact sum. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::add_rational_prec_round
documentation for information on special cases,
overflow, and underflow.
If you know you’ll be using Nearest
, consider using Float::add_rational_prec_assign
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::add_rational_round_assign
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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "3.4");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.5");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "3.5");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "3.474922");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.474926");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Nearest),
Greater
);
assert_eq!(x.to_string(), "3.474926");
This is mpfr_add_q from gmp_op.c, MPFR 4.2.0.
Sourcepub fn add_rational_prec_round_assign_ref(
&mut self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn add_rational_prec_round_assign_ref( &mut self, other: &Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result to the specified precision
and with the specified rounding mode. The Rational
is taken by reference. An
Ordering
is returned, indicating whether the rounded sum is less than, equal to, or
greater than the exact sum. Although NaN
s are not comparable to any Float
, whenever
this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::add_rational_prec_round
documentation for information on special cases,
overflow, and underflow.
If you know you’ll be using Nearest
, consider using
Float::add_rational_prec_assign_ref
instead. If you know that your target precision is
the precision of the Float
input, consider using
Float::add_rational_round_assign_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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "3.4");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.5");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "3.5");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "3.474922");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.474926");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Nearest),
Greater
);
assert_eq!(x.to_string(), "3.474926");
Sourcepub fn add_rational_prec_assign(
&mut self,
other: Rational,
prec: u64,
) -> Ordering
pub fn add_rational_prec_assign( &mut self, other: Rational, prec: u64, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result to the nearest value of the
specified precision. The Rational
is taken by value. An Ordering
is returned,
indicating whether the rounded sum is less than, equal to, or greater than the exact sum.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::add_rational_prec
documentation for information on special cases,
overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_rational_prec_round_assign
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(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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_assign(Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "4.8");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_assign(Rational::exact_from(1.5), 20),
Greater
);
assert_eq!(x.to_string(), "4.641594");
Sourcepub fn add_rational_prec_assign_ref(
&mut self,
other: &Rational,
prec: u64,
) -> Ordering
pub fn add_rational_prec_assign_ref( &mut self, other: &Rational, prec: u64, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result to the nearest value of the
specified precision. The Rational
is taken by reference. An Ordering
is returned,
indicating whether the rounded sum is less than, equal to, or greater than the exact sum.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to NaN
it also returns Equal
.
If the sum is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::add_rational_prec
documentation for information on special cases,
overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_rational_prec_round_assign_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(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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_assign_ref(&Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "4.8");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_prec_assign_ref(&Rational::exact_from(1.5), 20),
Greater
);
assert_eq!(x.to_string(), "4.641594");
Sourcepub fn add_rational_round_assign(
&mut self,
other: Rational,
rm: RoundingMode,
) -> Ordering
pub fn add_rational_round_assign( &mut self, other: Rational, rm: RoundingMode, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result with the specified rounding
mode. The Rational
is taken by value. An Ordering
is returned, indicating whether
the rounded sum is less than, equal to, or greater than the exact sum. Although NaN
s are
not comparable to any Float
, whenever this function sets the Float
to NaN
it also
returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::add_rational_round
documentation for information on special cases,
overflow, and underflow.
If you want to specify an output precision, consider using
Float::add_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign(Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "3.474925986923125");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign(Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.474925986923129");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign(Rational::from_unsigneds(1u8, 3), Nearest),
Less
);
assert_eq!(x.to_string(), "3.474925986923125");
Sourcepub fn add_rational_round_assign_ref(
&mut self,
other: &Rational,
rm: RoundingMode,
) -> Ordering
pub fn add_rational_round_assign_ref( &mut self, other: &Rational, rm: RoundingMode, ) -> Ordering
Adds a Rational
to a Float
in place, rounding the result with the specified rounding
mode. The Rational
is taken by reference. An Ordering
is returned, indicating
whether the rounded sum is less than, equal to, or greater than the exact sum. Although
NaN
s are not comparable to any Float
, whenever this function sets the Float
to
NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x+y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x+y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::add_rational_round
documentation for information on special cases,
overflow, and underflow.
If you want to specify an output precision, consider using
Float::add_rational_prec_round_assign_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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "3.474925986923125");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "3.474925986923129");
let mut x = Float::from(PI);
assert_eq!(
x.add_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Nearest),
Less
);
assert_eq!(x.to_string(), "3.474925986923125");
Source§impl Float
impl Float
Sourcepub fn div_prec_round(
self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_prec_round( self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s are taken by value. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::div_prec
instead. If you
know that your target precision is the maximum of the precisions of the two inputs, consider
using Float::div_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 \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(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(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(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(Float::from(E), 20, Floor);
assert_eq!(quotient.to_string(), "1.155725");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_prec_round(Float::from(E), 20, Ceiling);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_prec_round(Float::from(E), 20, Nearest);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_round_val_ref(
self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_prec_round_val_ref( self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, rounding the result to the specified precision and with the
specified rounding mode. The first Float
is are taken by value and the second by
reference. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::div_prec_val_ref
instead.
If you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::div_round_val_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_val_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_val_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_val_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_val_ref(&Float::from(E), 20, Floor);
assert_eq!(quotient.to_string(), "1.155725");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_prec_round_val_ref(&Float::from(E), 20, Ceiling);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_prec_round_val_ref(&Float::from(E), 20, Nearest);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_round_ref_val(
&self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_prec_round_ref_val( &self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, 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 NaN
s 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| < 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$
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.155725");
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.155727");
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.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_round_ref_ref(
&self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_prec_round_ref_ref( &self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s 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 NaN
s 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| < 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$
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.155725");
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.155727");
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.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec(self, other: Float, prec: u64) -> (Float, Ordering)
pub fn div_prec(self, other: Float, prec: u64) -> (Float, Ordering)
Divides two Float
s, rounding the result to the nearest value of the specified precision.
Both Float
s are taken by value. An Ordering
is also returned, indicating whether the
rounded quotient is less than, equal to, or greater than the exact quotient. Although NaN
s
are not comparable to any Float
, whenever this function returns a NaN
it also returns
Equal
.
If the quotient is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_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 \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(Float::from(E), 5);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_prec(Float::from(E), 20);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn div_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
Divides two Float
s, rounding the result to the nearest value of the specified precision.
The first Float
is taken by value and the second by reference. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s are not comparable to any Float
, whenever this
function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_round_val_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_val_ref(&Float::from(E), 5);
assert_eq!(quotient.to_string(), "1.12");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_prec_val_ref(&Float::from(E), 20);
assert_eq!(quotient.to_string(), "1.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
pub fn div_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
Divides two Float
s, 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 NaN
s are not comparable to any Float
, whenever this
function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
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.155727");
assert_eq!(o, Greater);
Sourcepub fn div_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn div_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
Divides two Float
s, rounding the result to the nearest value of the specified precision.
Both Float
s 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
NaN
s are not comparable to any Float
, whenever this function returns a NaN
it also
returns Equal
.
If the quotient is equidistant from two Float
s 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$
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.155727");
assert_eq!(o, Greater);
Sourcepub fn div_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
pub fn div_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
Divides two Float
s, rounding the result with the specified rounding mode. Both
Float
s are taken by value. An Ordering
is also returned, indicating whether the
rounded quotient is less than, equal to, or greater than the exact quotient. Although NaN
s
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| < 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$
If you want to specify an output precision, consider using Float::div_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 \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(Float::from(E), Floor);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_round(Float::from(E), Ceiling);
assert_eq!(quotient.to_string(), "1.155727349790922");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_round(Float::from(E), Nearest);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
Sourcepub fn div_round_val_ref(
self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_round_val_ref( self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, rounding the result with the specified rounding mode. The first
Float
is taken by value and the second by reference. An Ordering
is also returned,
indicating whether the rounded quotient is less than, equal to, or greater than the exact
quotient. Although NaN
s 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| < 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$
If you want to specify an output precision, consider using Float::div_prec_round_val_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_val_ref(&Float::from(E), Floor);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_round_val_ref(&Float::from(E), Ceiling);
assert_eq!(quotient.to_string(), "1.155727349790922");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_round_val_ref(&Float::from(E), Nearest);
assert_eq!(quotient.to_string(), "1.1557273497909217");
assert_eq!(o, Less);
Sourcepub fn div_round_ref_val(
&self,
other: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_round_ref_val( &self, other: Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, 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 NaN
s 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| < 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$
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.155727349790922");
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);
Sourcepub fn div_round_ref_ref(
&self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_round_ref_ref( &self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides two Float
s, rounding the result with the specified rounding mode. Both
Float
s 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 NaN
s
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| < 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$
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.155727349790922");
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);
Sourcepub fn div_prec_round_assign(
&mut self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn div_prec_round_assign( &mut self, other: Float, prec: u64, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Float
in place, rounding the result to the specified precision
and with the specified rounding mode. The Float
on the right-hand side is taken by
value. An Ordering
is returned, indicating whether the rounded quotient is less than,
equal to, or greater than the exact quotient. Although NaN
s are not comparable to any
Float
, whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::div_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using Float::div_prec_assign
instead. If
you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::div_round_assign
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 mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 5, Floor),
Less
);
assert_eq!(quotient.to_string(), "1.12");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(quotient.to_string(), "1.19");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 5, Nearest),
Less
);
assert_eq!(quotient.to_string(), "1.12");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 20, Floor),
Less
);
assert_eq!(quotient.to_string(), "1.155725");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(quotient.to_string(), "1.155727");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign(Float::from(E), 20, Nearest),
Greater
);
assert_eq!(quotient.to_string(), "1.155727");
Sourcepub fn div_prec_round_assign_ref(
&mut self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn div_prec_round_assign_ref( &mut self, other: &Float, prec: u64, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Float
in place, rounding the result to the specified precision
and with the specified rounding mode. The Float
on the right-hand side is taken by
reference. An Ordering
is returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s are not comparable to
any Float
, whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::div_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using Float::div_prec_assign_ref
instead. If you know that your target precision is the maximum of the precisions of the two
inputs, consider using Float::div_round_assign_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 mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 5, Floor),
Less
);
assert_eq!(quotient.to_string(), "1.12");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(quotient.to_string(), "1.19");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 5, Nearest),
Less
);
assert_eq!(quotient.to_string(), "1.12");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 20, Floor),
Less
);
assert_eq!(quotient.to_string(), "1.155725");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(quotient.to_string(), "1.155727");
let mut quotient = Float::from(PI);
assert_eq!(
quotient.div_prec_round_assign_ref(&Float::from(E), 20, Nearest),
Greater
);
assert_eq!(quotient.to_string(), "1.155727");
Sourcepub fn div_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
pub fn div_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
Divides a Float
by a Float
in place, rounding the result to the nearest value of the
specified precision. The Float
on the right-hand side is taken by value. An Ordering
is returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::div_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.div_prec_assign(Float::from(E), 5), Less);
assert_eq!(x.to_string(), "1.12");
let mut x = Float::from(PI);
assert_eq!(x.div_prec_assign(Float::from(E), 20), Greater);
assert_eq!(x.to_string(), "1.155727");
Sourcepub fn div_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
pub fn div_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
Divides a Float
by a Float
in place, rounding the result to the nearest value of the
specified precision. The Float
on the right-hand side is taken by reference. An
Ordering
is returned, indicating whether the rounded quotient is less than, equal to, or
greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::div_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_round_assign_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 mut x = Float::from(PI);
assert_eq!(x.div_prec_assign_ref(&Float::from(E), 5), Less);
assert_eq!(x.to_string(), "1.12");
let mut x = Float::from(PI);
assert_eq!(x.div_prec_assign_ref(&Float::from(E), 20), Greater);
assert_eq!(x.to_string(), "1.155727");
Sourcepub fn div_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
pub fn div_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
Divides a Float
by a Float
in place, rounding the result with the specified rounding
mode. The Float
on the right-hand side is taken by value. An Ordering
is returned,
indicating whether the rounded quotient is less than, equal to, or greater than the exact
quotient. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to 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.
$$ x \gets 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| < 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.
See the Float::div_round
documentation for information on special cases.
If you want to specify an output precision, consider using Float::div_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.div_round_assign(Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "1.1557273497909217");
let mut x = Float::from(PI);
assert_eq!(x.div_round_assign(Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "1.155727349790922");
let mut x = Float::from(PI);
assert_eq!(x.div_round_assign(Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "1.1557273497909217");
Sourcepub fn div_round_assign_ref(
&mut self,
other: &Float,
rm: RoundingMode,
) -> Ordering
pub fn div_round_assign_ref( &mut self, other: &Float, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Float
in place, rounding the result with the specified rounding
mode. The Float
on the right-hand side is taken by reference. An Ordering
is
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to 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.
$$ x \gets 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| < 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.
See the Float::div_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::div_prec_round_assign_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 mut x = Float::from(PI);
assert_eq!(x.div_round_assign_ref(&Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "1.1557273497909217");
let mut x = Float::from(PI);
assert_eq!(x.div_round_assign_ref(&Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "1.155727349790922");
let mut x = Float::from(PI);
assert_eq!(x.div_round_assign_ref(&Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "1.1557273497909217");
Sourcepub fn div_rational_prec_round(
self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_prec_round( self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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
value. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::div_rational_prec
instead.
If you know that your target precision is the precision of the Float
input, consider
using Float::div_rational_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 \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(Rational::from_unsigneds(1u8, 3), 5, Floor);
assert_eq!(quotient.to_string(), "9.0");
assert_eq!(o, Less);
let (quotient, o) =
Float::from(PI).div_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Ceiling);
assert_eq!(quotient.to_string(), "9.5");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Nearest);
assert_eq!(quotient.to_string(), "9.5");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Floor);
assert_eq!(quotient.to_string(), "9.42477");
assert_eq!(o, Less);
let (quotient, o) =
Float::from(PI).div_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Ceiling);
assert_eq!(quotient.to_string(), "9.42479");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Nearest);
assert_eq!(quotient.to_string(), "9.42477");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_round_val_ref(
self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_prec_round_val_ref( self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 value and the Rational
by
reference. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::div_rational_prec_val_ref
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::div_rational_round_val_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_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Floor,
);
assert_eq!(quotient.to_string(), "9.0");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Ceiling,
);
assert_eq!(quotient.to_string(), "9.5");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Nearest,
);
assert_eq!(quotient.to_string(), "9.5");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Floor,
);
assert_eq!(quotient.to_string(), "9.42477");
assert_eq!(o, Less);
let (quotient, o) = Float::from(PI).div_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Ceiling,
);
assert_eq!(quotient.to_string(), "9.42479");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Nearest,
);
assert_eq!(quotient.to_string(), "9.42477");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_round_ref_val(
&self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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$
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.0");
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.5");
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.5");
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.42477");
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.42479");
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.42477");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_round_ref_ref(
&self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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$
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.0");
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.5");
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.5");
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.42477");
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.42479");
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.42477");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec(self, other: Rational, prec: u64) -> (Float, Ordering)
pub fn div_rational_prec(self, other: Rational, prec: u64) -> (Float, 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 value. An
Ordering
is also returned, indicating whether the rounded quotient is less than, equal
to, or greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_round
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(Rational::exact_from(1.5), 5);
assert_eq!(quotient.to_string(), "2.1");
assert_eq!(o, Greater);
let (quotient, o) = Float::from(PI).div_rational_prec(Rational::exact_from(1.5), 20);
assert_eq!(quotient.to_string(), "2.094395");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_val_ref(
self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn div_rational_prec_val_ref( self, other: &Rational, prec: u64, ) -> (Float, Ordering)
Divides a Float
by a Rational
, rounding the result to the nearest value of the
specified precision. The Float
is taken by value and the Rational
by reference. An
Ordering
is also returned, indicating whether the rounded quotient is less than, equal
to, or greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_round_val_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_val_ref(&Rational::exact_from(1.5), 5);
assert_eq!(quotient.to_string(), "2.1");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_prec_val_ref(&Rational::exact_from(1.5), 20);
assert_eq!(quotient.to_string(), "2.094395");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_ref_val(
&self,
other: Rational,
prec: u64,
) -> (Float, Ordering)
pub fn div_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
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.1");
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.094395");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_ref_ref(
&self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn div_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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$
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.1");
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.094395");
assert_eq!(o, Less);
Sourcepub fn div_rational_round(
self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_round( self, other: Rational, rm: RoundingMode, ) -> (Float, 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 value. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
If you want to specify an output precision, consider using
Float::div_rational_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 \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(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(quotient.to_string(), "9.42477796076938");
assert_eq!(o, Less);
let (quotient, o) =
Float::from(PI).div_rational_round(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(quotient.to_string(), "9.42477796076939");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_round(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(quotient.to_string(), "9.42477796076938");
assert_eq!(o, Less);
Sourcepub fn div_rational_round_val_ref(
self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_round_val_ref( self, other: &Rational, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Float
by a Rational
, rounding the result with the specified rounding mode.
The Float
is taken by value and the Rational
by reference. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
If you want to specify an output precision, consider using
Float::div_rational_prec_round_val_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_val_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(quotient.to_string(), "9.42477796076938");
assert_eq!(o, Less);
let (quotient, o) =
Float::from(PI).div_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(quotient.to_string(), "9.42477796076939");
assert_eq!(o, Greater);
let (quotient, o) =
Float::from(PI).div_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(quotient.to_string(), "9.42477796076938");
assert_eq!(o, Less);
Sourcepub fn div_rational_round_ref_val(
&self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
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.42477796076938");
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.42477796076939");
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.42477796076938");
assert_eq!(o, Less);
Sourcepub fn div_rational_round_ref_ref(
&self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn div_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
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.42477796076938");
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.42477796076939");
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.42477796076938");
assert_eq!(o, Less);
Sourcepub fn div_rational_prec_round_assign(
&mut self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn div_rational_prec_round_assign( &mut self, other: Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by value. An
Ordering
is returned, indicating whether the rounded quotient is less than, equal to, or
greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::div_rational_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using Float::div_rational_prec_assign
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::div_rational_round_assign
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 mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "9.0");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.5");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "9.5");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "9.42477");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.42479");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "9.42477");
Sourcepub fn div_rational_prec_round_assign_ref(
&mut self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn div_rational_prec_round_assign_ref( &mut self, other: &Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by reference. An
Ordering
is returned, indicating whether the rounded quotient is less than, equal to, or
greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::div_rational_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using
Float::div_rational_prec_assign_ref
instead. If you know that your target precision is
the precision of the Float
input, consider using
Float::div_rational_round_assign_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 mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "9.0");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.5");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "9.5");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "9.42477");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.42479");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "9.42477");
Sourcepub fn div_rational_prec_assign(
&mut self,
other: Rational,
prec: u64,
) -> Ordering
pub fn div_rational_prec_assign( &mut self, other: Rational, prec: u64, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result to the nearest value of
the specified precision. The Rational
is taken by value. An Ordering
is returned,
indicating whether the rounded quotient is less than, equal to, or greater than the exact
quotient. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::div_rational_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_round_assign
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::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_assign(Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "2.1");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_assign(Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "2.094395");
Sourcepub fn div_rational_prec_assign_ref(
&mut self,
other: &Rational,
prec: u64,
) -> Ordering
pub fn div_rational_prec_assign_ref( &mut self, other: &Rational, prec: u64, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result to the nearest value of
the specified precision. The Rational
is taken by reference. An Ordering
is
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::div_rational_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_round_assign
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::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_assign_ref(&Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "2.1");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_prec_assign_ref(&Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "2.094395");
Sourcepub fn div_rational_round_assign(
&mut self,
other: Rational,
rm: RoundingMode,
) -> Ordering
pub fn div_rational_round_assign( &mut self, other: Rational, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result with the specified
rounding mode. The Rational
is taken by value. An Ordering
is returned, indicating
whether the rounded quotient is less than, equal to, or greater than the exact quotient.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::div_rational_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::div_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign(Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "9.42477796076938");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign(Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.42477796076939");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign(Rational::from_unsigneds(1u8, 3), Nearest),
Less
);
assert_eq!(x.to_string(), "9.42477796076938");
Sourcepub fn div_rational_round_assign_ref(
&mut self,
other: &Rational,
rm: RoundingMode,
) -> Ordering
pub fn div_rational_round_assign_ref( &mut self, other: &Rational, rm: RoundingMode, ) -> Ordering
Divides a Float
by a Rational
in place, rounding the result with the specified
rounding mode. The Rational
is taken by reference. An Ordering
is returned,
indicating whether the rounded quotient is less than, equal to, or greater than the exact
quotient. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::div_rational_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::div_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "9.42477796076938");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "9.42477796076939");
let mut x = Float::from(PI);
assert_eq!(
x.div_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Nearest),
Less
);
assert_eq!(x.to_string(), "9.42477796076938");
Sourcepub fn rational_div_float_prec_round(
x: Rational,
y: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_prec_round( x: Rational, y: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the specified precision and
with the specified rounding mode. The Rational
and the Float
are both taken by
value. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
If you know you’ll be using Nearest
, consider using Float::rational_div_float_prec
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::rational_div_float_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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), y.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::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 5, Floor);
assert_eq!(quotient.to_string(), "0.94");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 5, Ceiling);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 5, Nearest);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 20, Floor);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 20, Ceiling);
assert_eq!(quotient.to_string(), "0.95493");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_round(Rational::from(3), Float::from(PI), 20, Nearest);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_round_val_ref(
x: Rational,
y: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_prec_round_val_ref( x: Rational, y: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the specified precision and
with the specified rounding mode. The Rational
is taken by value and the Float
by
reference. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
If you know you’ll be using Nearest
, consider using
Float::rational_div_float_prec_val_ref
instead. If you know that your target precision
is the precision of the Float
input, consider using
Float::rational_div_float_round_val_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(x.significant_bits(), y.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::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
5,
Floor,
);
assert_eq!(quotient.to_string(), "0.94");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
5,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
5,
Nearest,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
20,
Floor,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
20,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.95493");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_val_ref(
Rational::from(3),
&Float::from(PI),
20,
Nearest,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_round_ref_val(
x: &Rational,
y: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_prec_round_ref_val( x: &Rational, y: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the specified precision and
with the specified rounding mode. The Rational
is taken by reference and the Float
by value. An Ordering
is also returned, indicating whether the rounded quotient is less
than, equal to, or greater than the exact quotient. Although NaN
s 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
If you know you’ll be using Nearest
, consider using
Float::rational_div_float_prec_ref_val
instead. If you know that your target precision
is the precision of the Float
input, consider using
Float::rational_div_float_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(x.significant_bits(), y.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::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
5,
Floor,
);
assert_eq!(quotient.to_string(), "0.94");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
5,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
5,
Nearest,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
20,
Floor,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
20,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.95493");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_val(
&Rational::from(3),
Float::from(PI),
20,
Nearest,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_round_ref_ref(
x: &Rational,
y: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_prec_round_ref_ref( x: &Rational, y: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the specified precision and
with the specified rounding mode. The Rational
and the Float
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 NaN
s 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| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$.
If the output has a precision, it is prec
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
If you know you’ll be using Nearest
, consider using
Float::rational_div_float_prec_ref_ref
instead. If you know that your target precision
is the precision of the Float
input, consider using
Float::rational_div_float_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(x.significant_bits(), y.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::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
5,
Floor,
);
assert_eq!(quotient.to_string(), "0.94");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
5,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
5,
Nearest,
);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
20,
Floor,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
let (quotient, o) = Float::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
20,
Ceiling,
);
assert_eq!(quotient.to_string(), "0.95493");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec_round_ref_ref(
&Rational::from(3),
&Float::from(PI),
20,
Nearest,
);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec(
x: Rational,
y: Float,
prec: u64,
) -> (Float, Ordering)
pub fn rational_div_float_prec( x: Rational, y: Float, prec: u64, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the nearest value of the
specified precision. The Rational
and the Float
are both are taken by value. An
Ordering
is also returned, indicating whether the rounded quotient is less than, equal
to, or greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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(x,\text{NaN},p)=f(0,\pm0.0,p)=\text{NaN}$
- $f(x,\infty,x,p)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p)=0.0$ if $x>0$
- $f(0,x,p)=-0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::rational_div_float_prec_round
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(x.significant_bits(), y.significant_bits(), prec)
.
§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (quotient, o) = Float::rational_div_float_prec(Rational::from(3), Float::from(PI), 5);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) = Float::rational_div_float_prec(Rational::from(3), Float::from(PI), 20);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_val_ref(
x: Rational,
y: &Float,
prec: u64,
) -> (Float, Ordering)
pub fn rational_div_float_prec_val_ref( x: Rational, y: &Float, prec: u64, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the nearest value of the
specified precision. The Rational
is taken by value and the Float
by reference. An
Ordering
is also returned, indicating whether the rounded quotient is less than, equal
to, or greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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(x,\text{NaN},p)=f(0,\pm0.0,p)=\text{NaN}$
- $f(x,\infty,x,p)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p)=0.0$ if $x>0$
- $f(0,x,p)=-0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::rational_div_float_prec_round_val_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(x.significant_bits(), y.significant_bits(), prec)
.
§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (quotient, o) =
Float::rational_div_float_prec_val_ref(Rational::from(3), &Float::from(PI), 5);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_val_ref(Rational::from(3), &Float::from(PI), 20);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_ref_val(
x: &Rational,
y: Float,
prec: u64,
) -> (Float, Ordering)
pub fn rational_div_float_prec_ref_val( x: &Rational, y: Float, prec: u64, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the nearest value of the
specified precision. The Rational
is taken by reference and the Float
by value. An
Ordering
is also returned, indicating whether the rounded quotient is less than, equal
to, or greater than the exact quotient. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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(x,\text{NaN},p)=f(0,\pm0.0,p)=\text{NaN}$
- $f(x,\infty,x,p)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p)=0.0$ if $x>0$
- $f(0,x,p)=-0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::rational_div_float_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(x.significant_bits(), y.significant_bits(), prec)
.
§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (quotient, o) =
Float::rational_div_float_prec_ref_val(&Rational::from(3), Float::from(PI), 5);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_ref_val(&Rational::from(3), Float::from(PI), 20);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_prec_ref_ref(
x: &Rational,
y: &Float,
prec: u64,
) -> (Float, Ordering)
pub fn rational_div_float_prec_ref_ref( x: &Rational, y: &Float, prec: u64, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result to the nearest value of the
specified precision. The Rational
and the Float
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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the quotient is equidistant from two Float
s 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(x,\text{NaN},p)=f(0,\pm0.0,p)=\text{NaN}$
- $f(x,\infty,x,p)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p)=0.0$ if $x>0$
- $f(0,x,p)=-0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::rational_div_float_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(x.significant_bits(), y.significant_bits(), prec)
.
§Examples
use core::f64::consts::PI;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (quotient, o) =
Float::rational_div_float_prec_ref_ref(&Rational::from(3), &Float::from(PI), 5);
assert_eq!(quotient.to_string(), "0.97");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_prec_ref_ref(&Rational::from(3), &Float::from(PI), 20);
assert_eq!(quotient.to_string(), "0.954929");
assert_eq!(o, Less);
Sourcepub fn rational_div_float_round(
x: Rational,
y: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_round( x: Rational, y: Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result with the specified rounding mode.
The Rational
and the Float
are both are taken by value. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the Float
input.
Special cases:
- $f(x,\text{NaN},m)=f(0,\pm0.0,m)=\text{NaN}$
- $f(x,\infty,x,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,m)=0.0$ if $x>0$
- $f(0,x,m)=-0.0$ if $x<0$
If you want to specify an output precision, consider using
Float::rational_div_float_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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), y.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::rational_div_float_round(Rational::from(3), Float::from(PI), Floor);
assert_eq!(quotient.to_string(), "0.9549296585513716");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_round(Rational::from(3), Float::from(PI), Ceiling);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_round(Rational::from(3), Float::from(PI), Nearest);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
Sourcepub fn rational_div_float_round_val_ref(
x: Rational,
y: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_round_val_ref( x: Rational, y: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result with the specified rounding mode.
The Rational
is taken by value and the Float
by reference. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the Float
input.
Special cases:
- $f(x,\text{NaN},m)=f(0,\pm0.0,m)=\text{NaN}$
- $f(x,\infty,x,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,m)=0.0$ if $x>0$
- $f(0,x,m)=-0.0$ if $x<0$
If you want to specify an output precision, consider using
Float::rational_div_float_prec_round_val_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(x.significant_bits(), y.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::rational_div_float_round_val_ref(Rational::from(3), &Float::from(PI), Floor);
assert_eq!(quotient.to_string(), "0.9549296585513716");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_round_val_ref(Rational::from(3), &Float::from(PI), Ceiling);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_round_val_ref(Rational::from(3), &Float::from(PI), Nearest);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
Sourcepub fn rational_div_float_round_ref_val(
x: &Rational,
y: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_round_ref_val( x: &Rational, y: Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result with the specified rounding mode.
The Rational
is taken by reference and the Float
by value. An Ordering
is also
returned, indicating whether the rounded quotient is less than, equal to, or greater than
the exact quotient. Although NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the Float
input.
Special cases:
- $f(x,\text{NaN},m)=f(0,\pm0.0,m)=\text{NaN}$
- $f(x,\infty,x,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,m)=0.0$ if $x>0$
- $f(0,x,m)=-0.0$ if $x<0$
If you want to specify an output precision, consider using
Float::rational_div_float_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(x.significant_bits(), y.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::rational_div_float_round_ref_val(&Rational::from(3), Float::from(PI), Floor);
assert_eq!(quotient.to_string(), "0.9549296585513716");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_round_ref_val(&Rational::from(3), Float::from(PI), Ceiling);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_round_ref_val(&Rational::from(3), Float::from(PI), Nearest);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
Sourcepub fn rational_div_float_round_ref_ref(
x: &Rational,
y: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn rational_div_float_round_ref_ref( x: &Rational, y: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Divides a Rational
by a Float
, rounding the result with the specified rounding mode.
The Rational
and the Float
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 NaN
s 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 inputFloat
. - If $x/y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x/y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the Float
input.
Special cases:
- $f(x,\text{NaN},m)=f(0,\pm0.0,m)=\text{NaN}$
- $f(x,\infty,x,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,m)=0.0$ if $x>0$
- $f(0,x,m)=-0.0$ if $x<0$
If you want to specify an output precision, consider using
Float::rational_div_float_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(x.significant_bits(), y.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::rational_div_float_round_ref_ref(&Rational::from(3), &Float::from(PI), Floor);
assert_eq!(quotient.to_string(), "0.9549296585513716");
assert_eq!(o, Less);
let (quotient, o) =
Float::rational_div_float_round_ref_ref(&Rational::from(3), &Float::from(PI), Ceiling);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
let (quotient, o) =
Float::rational_div_float_round_ref_ref(&Rational::from(3), &Float::from(PI), Nearest);
assert_eq!(quotient.to_string(), "0.9549296585513725");
assert_eq!(o, Greater);
Source§impl Float
impl Float
Sourcepub fn mul_prec_round(
self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_prec_round( self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s are taken by value. An Ordering
is also
returned, indicating whether the rounded product is less than, equal to, or greater than the
exact product. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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
instead. If you
know that your target precision is the maximum of the precisions of the two inputs, consider
using Float::mul_round
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(Float::from(E), 5, Floor);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round(Float::from(E), 5, Ceiling);
assert_eq!(product.to_string(), "9.0");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_prec_round(Float::from(E), 5, Nearest);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round(Float::from(E), 20, Floor);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round(Float::from(E), 20, Ceiling);
assert_eq!(product.to_string(), "8.53975");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_prec_round(Float::from(E), 20, Nearest);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_round_val_ref(
self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_prec_round_val_ref( self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the specified precision and with the
specified rounding mode. The first Float
is are taken by value and the second by
reference. An Ordering
is also returned, indicating whether the rounded product is less
than, equal to, or greater than the exact product. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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_val_ref
instead.
If you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::mul_round_val_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_val_ref(&Float::from(E), 5, Floor);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round_val_ref(&Float::from(E), 5, Ceiling);
assert_eq!(product.to_string(), "9.0");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_prec_round_val_ref(&Float::from(E), 5, Nearest);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round_val_ref(&Float::from(E), 20, Floor);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_round_val_ref(&Float::from(E), 20, Ceiling);
assert_eq!(product.to_string(), "8.53975");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_prec_round_val_ref(&Float::from(E), 20, Nearest);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_round_ref_val(
&self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_prec_round_ref_val( &self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.5");
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.0");
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.5");
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.53973");
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.53975");
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.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_round_ref_ref(
&self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_prec_round_ref_ref( &self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.5");
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.0");
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.5");
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.53973");
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.53975");
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.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec(self, other: Float, prec: u64) -> (Float, Ordering)
pub fn mul_prec(self, other: Float, prec: u64) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the nearest value of the specified
precision. Both Float
s are taken by value. An Ordering
is also returned, indicating
whether the rounded product is less than, equal to, or greater than the exact product.
Although NaN
s are not comparable to any Float
, whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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)\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.
- 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
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(Float::from(E), 5);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec(Float::from(E), 20);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn mul_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the nearest value of the specified
precision. The first Float
is taken by value and the second by reference. An
Ordering
is also returned, indicating whether the rounded product is less than, equal
to, or greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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)\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.
- 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_val_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_val_ref(&Float::from(E), 5);
assert_eq!(product.to_string(), "8.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_val_ref(&Float::from(E), 20);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
pub fn mul_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
Multiplies two Float
s, 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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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)\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.
- 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.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_ref_val(Float::from(E), 20);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn mul_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
Multiplies two Float
s, rounding the result to the nearest value of the specified
precision. Both Float
s 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 NaN
s are not comparable to any Float
, whenever this function returns
a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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)\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.
- 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.5");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_prec_ref_ref(&Float::from(E), 20);
assert_eq!(product.to_string(), "8.53973");
assert_eq!(o, Less);
Sourcepub fn mul_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
pub fn mul_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
Multiplies two Float
s, rounding the result with the specified rounding mode. Both
Float
s are taken by value. An Ordering
is also returned, indicating whether the
rounded product is less than, equal to, or greater than the exact product. Although NaN
s
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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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
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(Float::from(E), Floor);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_round(Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.539734222673568");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_round(Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
Sourcepub fn mul_round_val_ref(
self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_round_val_ref( self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, rounding the result with the specified rounding mode. The first
Float
is taken by value and the second by reference. An Ordering
is also returned,
indicating whether the rounded product is less than, equal to, or greater than the exact
product. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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_val_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_val_ref(&Float::from(E), Floor);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_round_val_ref(&Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.539734222673568");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_round_val_ref(&Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
Sourcepub fn mul_round_ref_val(
&self,
other: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_round_ref_val( &self, other: Float, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.539734222673566");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_round_ref_val(Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.539734222673568");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_round_ref_val(Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
Sourcepub fn mul_round_ref_ref(
&self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_round_ref_ref( &self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies two Float
s, rounding the result with the specified rounding mode. Both
Float
s 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 NaN
s
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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.539734222673566");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_round_ref_ref(&Float::from(E), Ceiling);
assert_eq!(product.to_string(), "8.539734222673568");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_round_ref_ref(&Float::from(E), Nearest);
assert_eq!(product.to_string(), "8.539734222673566");
assert_eq!(o, Less);
Sourcepub fn mul_prec_round_assign(
&mut self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn mul_prec_round_assign( &mut self, other: Float, prec: u64, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Float
on the right-hand side is
taken by value. An Ordering
is returned, indicating whether the rounded product is less
than, equal to, or greater than the exact product. Although NaN
s are not comparable to any
Float
, whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::mul_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::mul_prec_assign
instead. If
you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::mul_round_assign
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 mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 5, Floor),
Less
);
assert_eq!(product.to_string(), "8.5");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(product.to_string(), "9.0");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 5, Nearest),
Less
);
assert_eq!(product.to_string(), "8.5");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 20, Floor),
Less
);
assert_eq!(product.to_string(), "8.53973");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(product.to_string(), "8.53975");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign(Float::from(E), 20, Nearest),
Less
);
assert_eq!(product.to_string(), "8.53973");
Sourcepub fn mul_prec_round_assign_ref(
&mut self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn mul_prec_round_assign_ref( &mut self, other: &Float, prec: u64, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Float
on the right-hand side is
taken by reference. An Ordering
is returned, indicating whether the rounded product is
less than, equal to, or greater than the exact product. Although NaN
s are not comparable
to any Float
, whenever this function sets the Float
to NaN
it also returns
Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::mul_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::mul_prec_assign_ref
instead. If you know that your target precision is the maximum of the precisions of the two
inputs, consider using Float::mul_round_assign_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 mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 5, Floor),
Less
);
assert_eq!(product.to_string(), "8.5");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(product.to_string(), "9.0");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 5, Nearest),
Less
);
assert_eq!(product.to_string(), "8.5");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 20, Floor),
Less
);
assert_eq!(product.to_string(), "8.53973");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(product.to_string(), "8.53975");
let mut product = Float::from(PI);
assert_eq!(
product.mul_prec_round_assign_ref(&Float::from(E), 20, Nearest),
Less
);
assert_eq!(product.to_string(), "8.53973");
Sourcepub fn mul_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
pub fn mul_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result to the nearest value of
the specified precision. The Float
on the right-hand side is taken by value. An
Ordering
is returned, indicating whether the rounded product is less than, equal to, or
greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::mul_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.mul_prec_assign(Float::from(E), 5), Less);
assert_eq!(x.to_string(), "8.5");
let mut x = Float::from(PI);
assert_eq!(x.mul_prec_assign(Float::from(E), 20), Less);
assert_eq!(x.to_string(), "8.53973");
Sourcepub fn mul_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
pub fn mul_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result to the nearest value of
the specified precision. The Float
on the right-hand side is taken by reference. An
Ordering
is returned, indicating whether the rounded product is less than, equal to, or
greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::mul_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_prec_round_assign_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 mut x = Float::from(PI);
assert_eq!(x.mul_prec_assign_ref(&Float::from(E), 5), Less);
assert_eq!(x.to_string(), "8.5");
let mut x = Float::from(PI);
assert_eq!(x.mul_prec_assign_ref(&Float::from(E), 20), Less);
assert_eq!(x.to_string(), "8.53973");
Sourcepub fn mul_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
pub fn mul_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result with the specified
rounding mode. The Float
on the right-hand side is taken by value. An Ordering
is
returned, indicating whether the rounded product is less than, equal to, or greater than the
exact product. Although NaN
s are not comparable to any Float
, whenever this function
sets the Float
to 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.
$$ x \gets 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| < 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.
See the Float::mul_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using Float::mul_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.mul_round_assign(Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "8.539734222673566");
let mut x = Float::from(PI);
assert_eq!(x.mul_round_assign(Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "8.539734222673568");
let mut x = Float::from(PI);
assert_eq!(x.mul_round_assign(Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "8.539734222673566");
Sourcepub fn mul_round_assign_ref(
&mut self,
other: &Float,
rm: RoundingMode,
) -> Ordering
pub fn mul_round_assign_ref( &mut self, other: &Float, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Float
in place, rounding the result with the specified
rounding mode. The Float
on the right-hand side is taken by reference. An Ordering
is returned, indicating whether the rounded product is less than, equal to, or greater than
the exact product. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to 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.
$$ x \gets 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| < 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.
See the Float::mul_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using
Float::mul_prec_round_assign_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 mut x = Float::from(PI);
assert_eq!(x.mul_round_assign_ref(&Float::from(E), Floor), Less);
assert_eq!(x.to_string(), "8.539734222673566");
let mut x = Float::from(PI);
assert_eq!(x.mul_round_assign_ref(&Float::from(E), Ceiling), Greater);
assert_eq!(x.to_string(), "8.539734222673568");
let mut x = Float::from(PI);
assert_eq!(x.mul_round_assign_ref(&Float::from(E), Nearest), Less);
assert_eq!(x.to_string(), "8.539734222673566");
Sourcepub fn mul_rational_prec_round(
self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_prec_round( self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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
value. An Ordering
is also returned, indicating whether the rounded product is less
than, equal to, or greater than the exact product. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::mul_rational_prec
instead.
If you know that your target precision is the precision of the Float
input, consider
using Float::mul_rational_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 \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(Rational::from_unsigneds(1u8, 3), 5, Floor);
assert_eq!(product.to_string(), "1.0");
assert_eq!(o, Less);
let (product, o) =
Float::from(PI).mul_rational_prec_round(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(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(Rational::from_unsigneds(1u8, 3), 20, Floor);
assert_eq!(product.to_string(), "1.047197");
assert_eq!(o, Less);
let (product, o) =
Float::from(PI).mul_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Ceiling);
assert_eq!(product.to_string(), "1.047199");
assert_eq!(o, Greater);
let (product, o) =
Float::from(PI).mul_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Nearest);
assert_eq!(product.to_string(), "1.047197");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_round_val_ref(
self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_prec_round_val_ref( self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 value and the Rational
by
reference. An Ordering
is also returned, indicating whether the rounded product is less
than, equal to, or greater than the exact product. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::mul_rational_prec_val_ref
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::mul_rational_round_val_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_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Floor,
);
assert_eq!(product.to_string(), "1.0");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_rational_prec_round_val_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_val_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_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Floor,
);
assert_eq!(product.to_string(), "1.047197");
assert_eq!(o, Less);
let (product, o) = Float::from(PI).mul_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Ceiling,
);
assert_eq!(product.to_string(), "1.047199");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Nearest,
);
assert_eq!(product.to_string(), "1.047197");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_round_ref_val(
&self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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$
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.0");
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.047197");
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.047199");
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.047197");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_round_ref_ref(
&self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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$
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.0");
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.047197");
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.047199");
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.047197");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec(self, other: Rational, prec: u64) -> (Float, Ordering)
pub fn mul_rational_prec(self, other: Rational, prec: u64) -> (Float, 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 value. An
Ordering
is also returned, indicating whether the rounded product is less than, equal
to, or greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_round
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(Rational::exact_from(1.5), 5);
assert_eq!(product.to_string(), "4.8");
assert_eq!(o, Greater);
let (product, o) = Float::from(PI).mul_rational_prec(Rational::exact_from(1.5), 20);
assert_eq!(product.to_string(), "4.712387");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_val_ref(
self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn mul_rational_prec_val_ref( self, other: &Rational, prec: u64, ) -> (Float, Ordering)
Multiplies a Float
by a Rational
, rounding the result to the nearest value of the
specified precision. The Float
is taken by value and the Rational
by reference. An
Ordering
is also returned, indicating whether the rounded product is less than, equal
to, or greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_round_val_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_val_ref(&Rational::exact_from(1.5), 5);
assert_eq!(product.to_string(), "4.8");
assert_eq!(o, Greater);
let (product, o) =
Float::from(PI).mul_rational_prec_val_ref(&Rational::exact_from(1.5), 20);
assert_eq!(product.to_string(), "4.712387");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_ref_val(
&self,
other: Rational,
prec: u64,
) -> (Float, Ordering)
pub fn mul_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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$
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.8");
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.712387");
assert_eq!(o, Less);
Sourcepub fn mul_rational_prec_ref_ref(
&self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn mul_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any Float
,
whenever this function returns a NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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$
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.8");
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.712387");
assert_eq!(o, Less);
Sourcepub fn mul_rational_round(
self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_round( self, other: Rational, rm: RoundingMode, ) -> (Float, 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 value. An Ordering
is
also returned, indicating whether the rounded product is less than, equal to, or greater
than the exact product. Although NaN
s 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
If you want to specify an output precision, consider using
Float::mul_rational_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 \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(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(product.to_string(), "1.047197551196597");
assert_eq!(o, Less);
let (product, o) =
Float::from(PI).mul_rational_round(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(product.to_string(), "1.047197551196598");
assert_eq!(o, Greater);
let (product, o) =
Float::from(PI).mul_rational_round(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(product.to_string(), "1.047197551196598");
assert_eq!(o, Greater);
Sourcepub fn mul_rational_round_val_ref(
self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_round_val_ref( self, other: &Rational, rm: RoundingMode, ) -> (Float, Ordering)
Multiplies a Float
by a Rational
, rounding the result with the specified rounding
mode. The Float
is taken by value and the Rational
by reference. An Ordering
is
also returned, indicating whether the rounded product is less than, equal to, or greater
than the exact product. Although NaN
s 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
If you want to specify an output precision, consider using
Float::mul_rational_prec_round_val_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_val_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(product.to_string(), "1.047197551196597");
assert_eq!(o, Less);
let (product, o) =
Float::from(PI).mul_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(product.to_string(), "1.047197551196598");
assert_eq!(o, Greater);
let (product, o) =
Float::from(PI).mul_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(product.to_string(), "1.047197551196598");
assert_eq!(o, Greater);
Sourcepub fn mul_rational_round_ref_val(
&self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
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.047197551196597");
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.047197551196598");
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.047197551196598");
assert_eq!(o, Greater);
Sourcepub fn mul_rational_round_ref_ref(
&self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn mul_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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$
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.047197551196597");
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.047197551196598");
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.047197551196598");
assert_eq!(o, Greater);
Sourcepub fn mul_rational_prec_round_assign(
&mut self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn mul_rational_prec_round_assign( &mut self, other: Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by value. An
Ordering
is returned, indicating whether the rounded product is less than, equal to, or
greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::mul_rational_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using Float::mul_rational_prec_assign
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::mul_rational_round_assign
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 mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "1.0");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.06");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "1.06");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "1.047197");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.047199");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "1.047197");
Sourcepub fn mul_rational_prec_round_assign_ref(
&mut self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn mul_rational_prec_round_assign_ref( &mut self, other: &Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by reference. An
Ordering
is returned, indicating whether the rounded product is less than, equal to, or
greater than the exact product. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |xy|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::mul_rational_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using
Float::mul_rational_prec_assign_ref
instead. If you know that your target precision is
the precision of the Float
input, consider using
Float::mul_rational_round_assign_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 mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "1.0");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.06");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Nearest),
Greater
);
assert_eq!(x.to_string(), "1.06");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "1.047197");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.047199");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "1.047197");
Sourcepub fn mul_rational_prec_assign(
&mut self,
other: Rational,
prec: u64,
) -> Ordering
pub fn mul_rational_prec_assign( &mut self, other: Rational, prec: u64, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result to the nearest value
of the specified precision. The Rational
is taken by value. An Ordering
is returned,
indicating whether the rounded product is less than, equal to, or greater than the exact
product. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::mul_rational_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_round_assign
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::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_assign(Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "4.8");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_assign(Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "4.712387");
Sourcepub fn mul_rational_prec_assign_ref(
&mut self,
other: &Rational,
prec: u64,
) -> Ordering
pub fn mul_rational_prec_assign_ref( &mut self, other: &Rational, prec: u64, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result to the nearest value
of the specified precision. The Rational
is taken by reference. An Ordering
is
returned, indicating whether the rounded product is less than, equal to, or greater than the
exact product. Although NaN
s are not comparable to any Float
, whenever this function
sets the Float
to NaN
it also returns Equal
.
If the product is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::mul_rational_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_round_assign
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::PI;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_assign_ref(&Rational::exact_from(1.5), 5),
Greater
);
assert_eq!(x.to_string(), "4.8");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_prec_assign_ref(&Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "4.712387");
Sourcepub fn mul_rational_round_assign(
&mut self,
other: Rational,
rm: RoundingMode,
) -> Ordering
pub fn mul_rational_round_assign( &mut self, other: Rational, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result with the specified
rounding mode. The Rational
is taken by value. An Ordering
is returned, indicating
whether the rounded product is less than, equal to, or greater than the exact product.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::mul_rational_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::mul_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign(Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "1.047197551196597");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign(Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.047197551196598");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign(Rational::from_unsigneds(1u8, 3), Nearest),
Greater
);
assert_eq!(x.to_string(), "1.047197551196598");
Sourcepub fn mul_rational_round_assign_ref(
&mut self,
other: &Rational,
rm: RoundingMode,
) -> Ordering
pub fn mul_rational_round_assign_ref( &mut self, other: &Rational, rm: RoundingMode, ) -> Ordering
Multiplies a Float
by a Rational
in place, rounding the result with the specified
rounding mode. The Rational
is taken by reference. An Ordering
is returned,
indicating whether the rounded product is less than, equal to, or greater than the exact
product. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $xy$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |xy|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::mul_rational_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::mul_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "1.047197551196597");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "1.047197551196598");
let mut x = Float::from(PI);
assert_eq!(
x.mul_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Nearest),
Greater
);
assert_eq!(x.to_string(), "1.047197551196598");
Source§impl Float
impl Float
Sourcepub fn power_of_2_prec_round(
pow: i64,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn power_of_2_prec_round( pow: i64, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Raises 2 to an integer power, returning a Float
with the specified precision and with
the specified rounding mode. An Ordering
is also returned, indicating whether the
returned power is less than, equal to, or greater than the exact power. The ordering is
usually Equal
, but is Less
or Greater
if overflow or underflow occurs.
$f(k) = 2^k$, and the result has precision prec
.
- If
pow
is greater than $2^{30}-2$ andrm
isFloor
orDown
, the largest representableFloat
with the given precision is returned. - If
pow
is greater than $2^{30}-2$ andrm
isCeiling
orUp
, orNearest
, $\infty$ is returned. - If
pow
is less than $-2^{30}$ andrm
isFloor
,Down
, orNearest
, positive zero is returned. - If
pow
is less than $-2^{30}$ andrm
isCeiling
orUp
, the smallest positiveFloat
is returned.
If you want the behavior of Nearest
(that is, returning $\infty$ on overflow and positive
zero on underflow), you can use Float::power_of_2_prec
instead.
If you need a Float
with precision 1, then the PowerOf2
implementation may be used
instead.
§Panics
Panics if prec
is zero, or if rm
is exact and pow
is greater than $2^{30}-2$ or less
than $-2^{30}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let (p, o) = Float::power_of_2_prec_round(0, 1, Nearest);
assert_eq!(p.to_string(), "1.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(0, 100, Nearest);
assert_eq!(p.to_string(), "1.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(100, 1, Nearest);
assert_eq!(p.to_string(), "1.0e30");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(100, 100, Nearest);
assert_eq!(p.to_string(), "1267650600228229401496703205376.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(-100, 1, Nearest);
assert_eq!(p.to_string(), "8.0e-31");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(-100, 100, Nearest);
assert_eq!(p.to_string(), "7.88860905221011805411728565283e-31");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec_round(i64::power_of_2(30) - 1, 10, Floor);
assert_eq!(p.to_string(), "too_big");
assert_eq!(o, Less);
let (p, o) = Float::power_of_2_prec_round(i64::power_of_2(30) - 1, 10, Ceiling);
assert_eq!(p.to_string(), "Infinity");
assert_eq!(o, Greater);
let (p, o) = Float::power_of_2_prec_round(-i64::power_of_2(30) - 1, 10, Floor);
assert_eq!(p.to_string(), "0.0");
assert_eq!(o, Less);
let (p, o) = Float::power_of_2_prec_round(-i64::power_of_2(30) - 1, 10, Ceiling);
assert_eq!(p.to_string(), "too_small");
assert_eq!(o, Greater);
Sourcepub fn power_of_2_prec(pow: i64, prec: u64) -> (Float, Ordering)
pub fn power_of_2_prec(pow: i64, prec: u64) -> (Float, Ordering)
Raises 2 to an integer power, returning a Float
with the specified precision. An
Ordering
is also returned, indicating whether the returned power is less than, equal to,
or greater than the exact power. The ordering is usually Equal
, but is Greater
in the
case of overflow and Less
in the case of underflow.
$f(k) = 2^k$, and the result has precision prec
.
If pow
is greater than $2^{30}-2$, $\infty$ is returned. If pow
is less than $-2^{30}$,
positive zero is returned. If you want different overflow and underflow behavior, try using
Float::power_of_2_prec_round
instead.
If you need a Float
with precision 1, then the PowerOf2
implementation may be used
instead.
§Panics
Panics if prec
is zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_float::Float;
use std::cmp::Ordering::*;
let (p, o) = Float::power_of_2_prec(0, 1);
assert_eq!(p.to_string(), "1.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(0, 100);
assert_eq!(p.to_string(), "1.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(100, 1);
assert_eq!(p.to_string(), "1.0e30");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(100, 100);
assert_eq!(p.to_string(), "1267650600228229401496703205376.0");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(-100, 1);
assert_eq!(p.to_string(), "8.0e-31");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(-100, 100);
assert_eq!(p.to_string(), "7.88860905221011805411728565283e-31");
assert_eq!(o, Equal);
let (p, o) = Float::power_of_2_prec(i64::power_of_2(30) - 1, 10);
assert_eq!(p.to_string(), "Infinity");
assert_eq!(o, Greater);
let (p, o) = Float::power_of_2_prec(-i64::power_of_2(30) - 1, 10);
assert_eq!(p.to_string(), "0.0");
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn reciprocal_prec_round(
self,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn reciprocal_prec_round( self, prec: u64, rm: RoundingMode, ) -> (Float, 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 value. An Ordering
is also
returned, indicating whether the rounded reciprocal is less than, equal to, or greater than
the exact reciprocal. Although NaN
s 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| < 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$
If you know you’ll be using Nearest
, consider using Float::reciprocal_prec
instead. If
you know that your target precision is the precision of the input, consider using
Float::reciprocal_round
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(5, Floor);
assert_eq!(reciprocal.to_string(), "0.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round(5, Ceiling);
assert_eq!(reciprocal.to_string(), "0.33");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round(5, Nearest);
assert_eq!(reciprocal.to_string(), "0.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round(20, Floor);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round(20, Ceiling);
assert_eq!(reciprocal.to_string(), "0.3183103");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round(20, Nearest);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
Sourcepub fn reciprocal_prec_round_ref(
&self,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn reciprocal_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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$
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.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(5, Ceiling);
assert_eq!(reciprocal.to_string(), "0.33");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(5, Nearest);
assert_eq!(reciprocal.to_string(), "0.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Floor);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Ceiling);
assert_eq!(reciprocal.to_string(), "0.3183103");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_round_ref(20, Nearest);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
Sourcepub fn reciprocal_prec(self, prec: u64) -> (Float, Ordering)
pub fn reciprocal_prec(self, prec: u64) -> (Float, Ordering)
Takes the reciprocal of a Float
, rounding the result to the nearest value of the
specified precision. The Float
is taken by value. An Ordering
is also returned,
indicating whether the rounded reciprocal is less than, equal to, or greater than the exact
reciprocal. Although NaN
s are not comparable to any Float
, whenever this function
returns a NaN
it also returns Equal
.
If the reciprocal is equidistant from two Float
s 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$
If you want to use a rounding mode other than Nearest
, consider using
Float::reciprocal_prec_round
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(5);
assert_eq!(reciprocal.to_string(), "0.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec(20);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
Sourcepub fn reciprocal_prec_ref(&self, prec: u64) -> (Float, Ordering)
pub fn reciprocal_prec_ref(&self, prec: u64) -> (Float, 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 NaN
s are not comparable to any Float
, whenever this function
returns a NaN
it also returns Equal
.
If the reciprocal is equidistant from two Float
s 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$
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.31");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_prec_ref(20);
assert_eq!(reciprocal.to_string(), "0.3183098");
assert_eq!(o, Less);
Sourcepub fn reciprocal_round(self, rm: RoundingMode) -> (Float, Ordering)
pub fn reciprocal_round(self, rm: RoundingMode) -> (Float, Ordering)
Takes the reciprocal of a Float
, rounding the result with the specified rounding mode.
The Float
is taken by value. An Ordering
is also returned, indicating whether the
rounded reciprocal is less than, equal to, or greater than the exact reciprocal. Although
NaN
s 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| < 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$
If you want to specify an output precision, consider using Float::reciprocal_prec_round
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(Floor);
assert_eq!(reciprocal.to_string(), "0.3183098861837905");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_round(Ceiling);
assert_eq!(reciprocal.to_string(), "0.318309886183791");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_round(Nearest);
assert_eq!(reciprocal.to_string(), "0.3183098861837905");
assert_eq!(o, Less);
Sourcepub fn reciprocal_round_ref(&self, rm: RoundingMode) -> (Float, Ordering)
pub fn reciprocal_round_ref(&self, rm: RoundingMode) -> (Float, 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 NaN
s 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| < 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$
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.3183098861837905");
assert_eq!(o, Less);
let (reciprocal, o) = Float::from(PI).reciprocal_round_ref(Ceiling);
assert_eq!(reciprocal.to_string(), "0.318309886183791");
assert_eq!(o, Greater);
let (reciprocal, o) = Float::from(PI).reciprocal_round_ref(Nearest);
assert_eq!(reciprocal.to_string(), "0.3183098861837905");
assert_eq!(o, Less);
Sourcepub fn reciprocal_prec_round_assign(
&mut self,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn reciprocal_prec_round_assign( &mut self, prec: u64, rm: RoundingMode, ) -> Ordering
Takes the reciprocal of a Float
in place, rounding the result to the specified precision
and with the specified rounding mode. An Ordering
is returned, indicating whether the
rounded reciprocal is less than, equal to, or greater than the exact reciprocal. Although
NaN
s are not comparable to any Float
, whenever this function sets the Float
to
NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 |xy|\rfloor-p+1}$. - If $1/x$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |1/x|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::reciprocal_prec_round
documentation for information on special cases.
If you know you’ll be using Nearest
, consider using Float::reciprocal_prec_assign
instead. If you know that your target precision is the precision of the input, consider
using Float::reciprocal_round_assign
instead. If both of these things are true, consider
using Float::reciprocal_assign
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 mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(5, Floor), Less);
assert_eq!(x.to_string(), "0.31");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(5, Ceiling), Greater);
assert_eq!(x.to_string(), "0.33");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(5, Nearest), Less);
assert_eq!(x.to_string(), "0.31");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(20, Floor), Less);
assert_eq!(x.to_string(), "0.3183098");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(20, Ceiling), Greater);
assert_eq!(x.to_string(), "0.3183103");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_round_assign(20, Nearest), Less);
assert_eq!(x.to_string(), "0.3183098");
Sourcepub fn reciprocal_prec_assign(&mut self, prec: u64) -> Ordering
pub fn reciprocal_prec_assign(&mut self, prec: u64) -> Ordering
Takes the reciprocal of a Float
in place, rounding the result to the nearest value of
the specified precision. An Ordering
is returned, indicating whether the rounded
reciprocal is less than, equal to, or greater than the exact reciprocal. Although NaN
s are
not comparable to any Float
, whenever this function sets the Float
to NaN
it also
returns Equal
.
If the reciprocal is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::reciprocal_prec
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::reciprocal_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_assign(5), Less);
assert_eq!(x.to_string(), "0.31");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_prec_assign(20), Less);
assert_eq!(x.to_string(), "0.3183098");
Sourcepub fn reciprocal_round_assign(&mut self, rm: RoundingMode) -> Ordering
pub fn reciprocal_round_assign(&mut self, rm: RoundingMode) -> Ordering
Takes the reciprocal of a Float
in place, rounding the result with the specified
rounding mode. An Ordering
is returned, indicating whether the rounded reciprocal is
less than, equal to, or greater than the exact reciprocal. Although NaN
s are not
comparable to any Float
, whenever this function sets the Float
to 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.
$$ x \gets 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 maximum precision of the inputs. - If $1/x$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |1/x|\rfloor-p}$, where $p$ is the maximum precision of the inputs.
If the output has a precision, it is the precision of the input.
See the Float::reciprocal_round
documentation for information on special cases.
If you want to specify an output precision, consider using
Float::reciprocal_prec_round_assign
instead. If you know you’ll be using the Nearest
rounding mode, consider using Float::reciprocal_assign
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 mut x = Float::from(PI);
assert_eq!(x.reciprocal_round_assign(Floor), Less);
assert_eq!(x.to_string(), "0.3183098861837905");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_round_assign(Ceiling), Greater);
assert_eq!(x.to_string(), "0.318309886183791");
let mut x = Float::from(PI);
assert_eq!(x.reciprocal_round_assign(Nearest), Less);
assert_eq!(x.to_string(), "0.3183098861837905");
Source§impl Float
impl Float
Sourcepub fn square_prec_round(self, prec: u64, rm: RoundingMode) -> (Float, Ordering)
pub fn square_prec_round(self, prec: u64, rm: RoundingMode) -> (Float, Ordering)
Squares a Float
, rounding the result to the specified precision and with the specified
rounding mode. The Float
is taken by value. An Ordering
is also returned, indicating
whether the rounded square is less than, equal to, or greater than the exact square.
Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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,y,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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is
Floor
orUp
, $-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.
If you know you’ll be using Nearest
, consider using Float::square_prec
instead. If you
know that your target precision is the precision of the input, consider using
Float::square_round
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(5, Floor);
assert_eq!(square.to_string(), "9.5");
assert_eq!(o, Less);
let (square, o) = Float::from(PI).square_prec_round(5, Ceiling);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_prec_round(5, Nearest);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_prec_round(20, Floor);
assert_eq!(square.to_string(), "9.8696");
assert_eq!(o, Less);
let (square, o) = Float::from(PI).square_prec_round(20, Ceiling);
assert_eq!(square.to_string(), "9.86961");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_prec_round(20, Nearest);
assert_eq!(square.to_string(), "9.8696");
assert_eq!(o, Less);
Sourcepub fn square_prec_round_ref(
&self,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn square_prec_round_ref( &self, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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,y,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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,p,m)<0$, and $m$ is
Floor
orUp
, $-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.
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.5");
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.8696");
assert_eq!(o, Less);
let (square, o) = Float::from(PI).square_prec_round_ref(20, Ceiling);
assert_eq!(square.to_string(), "9.86961");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_prec_round_ref(20, Nearest);
assert_eq!(square.to_string(), "9.8696");
assert_eq!(o, Less);
Sourcepub fn square_prec(self, prec: u64) -> (Float, Ordering)
pub fn square_prec(self, prec: u64) -> (Float, Ordering)
Squares a Float
, rounding the result to the nearest value of the specified precision.
The Float
is taken by value. An Ordering
is also returned, indicating whether the
rounded square is less than, equal to, or greater than the exact square. Although NaN
s are
not comparable to any Float
, whenever this function returns a NaN
it also returns
Equal
.
If the square is equidistant from two Float
s 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 $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.
- 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.
If you want to use a rounding mode other than Nearest
, consider using
Float::square_prec_round
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(5);
assert_eq!(square.to_string(), "10.0");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_prec(20);
assert_eq!(square.to_string(), "9.8696");
assert_eq!(o, Less);
Sourcepub fn square_prec_ref(&self, prec: u64) -> (Float, Ordering)
pub fn square_prec_ref(&self, prec: u64) -> (Float, 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 NaN
s
are not comparable to any Float
, whenever this function returns a NaN
it also returns
Equal
.
If the square is equidistant from two Float
s 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 $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.
- 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.
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.8696");
assert_eq!(o, Less);
Sourcepub fn square_round(self, rm: RoundingMode) -> (Float, Ordering)
pub fn square_round(self, rm: RoundingMode) -> (Float, Ordering)
Squares a Float
, rounding the result with the specified rounding mode. The Float
is
taken by value. An Ordering
is also returned, indicating whether the rounded square is
less than, equal to, or greater than the exact square. Although NaN
s 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) = 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is
Floor
orUp
, $-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.
If you want to specify an output precision, consider using Float::square_prec_round
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(Floor);
assert_eq!(square.to_string(), "9.86960440108935");
assert_eq!(o, Less);
let (square, o) = Float::from(PI).square_round(Ceiling);
assert_eq!(square.to_string(), "9.86960440108936");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_round(Nearest);
assert_eq!(square.to_string(), "9.86960440108936");
assert_eq!(o, Greater);
Sourcepub fn square_round_ref(&self, rm: RoundingMode) -> (Float, Ordering)
pub fn square_round_ref(&self, rm: RoundingMode) -> (Float, 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 NaN
s 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) = 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,m)<0$, and $m$ is
Floor
orUp
, $-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.
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.86960440108935");
assert_eq!(o, Less);
let (square, o) = Float::from(PI).square_round_ref(Ceiling);
assert_eq!(square.to_string(), "9.86960440108936");
assert_eq!(o, Greater);
let (square, o) = Float::from(PI).square_round_ref(Nearest);
assert_eq!(square.to_string(), "9.86960440108936");
assert_eq!(o, Greater);
Sourcepub fn square_prec_round_assign(
&mut self,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn square_prec_round_assign( &mut self, prec: u64, rm: RoundingMode, ) -> Ordering
Squares a Float
in place, rounding the result to the specified precision and with the
specified rounding mode. An Ordering
is returned, indicating whether the rounded square
is less than, equal to, or greater than the exact square. Although NaN
s are not comparable
to any Float
, whenever this function sets the Float
to NaN
it also returns
Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 |xy|\rfloor-p+1}$. - If $x^2$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x^2|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::square_prec_round
documentation for information on special cases,
overflow, and underflow.
If you know you’ll be using Nearest
, consider using Float::square_prec_assign
instead.
If you know that your target precision is the precision of the input, consider using
Float::square_round_assign
instead. If both of these things are true, consider using
Float::square_assign
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 mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(5, Floor), Less);
assert_eq!(x.to_string(), "9.5");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(5, Ceiling), Greater);
assert_eq!(x.to_string(), "10.0");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(5, Nearest), Greater);
assert_eq!(x.to_string(), "10.0");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(20, Floor), Less);
assert_eq!(x.to_string(), "9.8696");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(20, Ceiling), Greater);
assert_eq!(x.to_string(), "9.86961");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_round_assign(20, Nearest), Less);
assert_eq!(x.to_string(), "9.8696");
Sourcepub fn square_prec_assign(&mut self, prec: u64) -> Ordering
pub fn square_prec_assign(&mut self, prec: u64) -> Ordering
Squares a Float
in place, rounding the result to the nearest value of the specified
precision. An Ordering
is returned, indicating whether the rounded square is less than,
equal to, or greater than the exact square. Although NaN
s are not comparable to any
Float
, whenever this function sets the Float
to NaN
it also returns Equal
.
If the square is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::square_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::square_prec_round_assign
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 mut x = Float::from(PI);
assert_eq!(x.square_prec_assign(5), Greater);
assert_eq!(x.to_string(), "10.0");
let mut x = Float::from(PI);
assert_eq!(x.square_prec_assign(20), Less);
assert_eq!(x.to_string(), "9.8696");
Sourcepub fn square_round_assign(&mut self, rm: RoundingMode) -> Ordering
pub fn square_round_assign(&mut self, rm: RoundingMode) -> Ordering
Squares a Float
in place, rounding the result with the specified rounding mode. An
Ordering
is returned, indicating whether the rounded square is less than, equal to, or
greater than the exact square. Although NaN
s are not comparable to any Float
, whenever
this function sets the Float
to 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.
$$ x \gets 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 maximum precision of the inputs. - If $x^2$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x^2|\rfloor-p}$, where $p$ is the maximum precision of the inputs.
If the output has a precision, it is the precision of the input.
See the Float::square_round
documentation for information on special cases, overflow,
and underflow.
If you want to specify an output precision, consider using
Float::square_prec_round_assign
instead. If you know you’ll be using the Nearest
rounding mode, consider using Float::square_assign
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 mut x = Float::from(PI);
assert_eq!(x.square_round_assign(Floor), Less);
assert_eq!(x.to_string(), "9.86960440108935");
let mut x = Float::from(PI);
assert_eq!(x.square_round_assign(Ceiling), Greater);
assert_eq!(x.to_string(), "9.86960440108936");
let mut x = Float::from(PI);
assert_eq!(x.square_round_assign(Nearest), Greater);
assert_eq!(x.to_string(), "9.86960440108936");
Source§impl Float
impl Float
Sourcepub fn sub_prec_round(
self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_prec_round( self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s are taken by value. An Ordering
is also
returned, indicating whether the rounded difference is less than, equal to, or greater than
the exact difference. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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
instead. If you
know that your target precision is the maximum of the precisions of the two inputs, consider
using Float::sub_round
instead. If both of these things are true, 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 prec
.
§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(Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round(Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "0.44");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_prec_round(Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round(Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round(Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "0.4233112");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_prec_round(Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_round_val_ref(
self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_prec_round_val_ref( self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the specified precision and with the
specified rounding mode. The first Float
is taken by value and the second by reference.
An Ordering
is also returned, indicating whether the rounded difference is less than,
equal to, or greater than the exact difference. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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_val_ref
instead.
If you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::sub_round_val_ref
instead. If both of these things are true,
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 prec
.
§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_val_ref(&Float::from(E), 5, Floor);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round_val_ref(&Float::from(E), 5, Ceiling);
assert_eq!(sum.to_string(), "0.44");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_prec_round_val_ref(&Float::from(E), 5, Nearest);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round_val_ref(&Float::from(E), 20, Floor);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_round_val_ref(&Float::from(E), 20, Ceiling);
assert_eq!(sum.to_string(), "0.4233112");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_prec_round_val_ref(&Float::from(E), 20, Nearest);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_round_ref_val(
&self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_prec_round_ref_val( &self, other: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.42");
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.44");
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.42");
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.4233108");
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.4233112");
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.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_round_ref_ref(
&self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_prec_round_ref_ref( &self, other: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the specified precision and with the
specified rounding mode. Both Float
s 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.42");
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.44");
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.42");
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.4233108");
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.4233112");
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.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec(self, other: Float, prec: u64) -> (Float, Ordering)
pub fn sub_prec(self, other: Float, prec: u64) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the nearest value of the specified
precision. Both Float
s are taken by value. An Ordering
is also returned, indicating
whether the rounded difference is less than, equal to, or greater than the exact difference.
Although NaN
s are not comparable to any Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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
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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let (sum, o) = Float::from(PI).sub_prec(Float::from(E), 5);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec(Float::from(E), 20);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn sub_prec_val_ref(self, other: &Float, prec: u64) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the nearest value of the specified
precision. The first Float
is taken by value and the second by reference. An
Ordering
is also returned, indicating whether the rounded difference is less than, equal
to, or greater than the exact difference. Although NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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_val_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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let (sum, o) = Float::from(PI).sub_prec_val_ref(&Float::from(E), 5);
assert_eq!(sum.to_string(), "0.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_val_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
pub fn sub_prec_ref_val(&self, other: Float, prec: u64) -> (Float, Ordering)
Subtracts two Float
s, 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 NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_ref_val(Float::from(E), 20);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
pub fn sub_prec_ref_ref(&self, other: &Float, prec: u64) -> (Float, Ordering)
Subtracts two Float
s, rounding the result to the nearest value of the specified
precision. Both Float
s 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 NaN
s are not comparable to any Float
, whenever this function
returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§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.42");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_prec_ref_ref(&Float::from(E), 20);
assert_eq!(sum.to_string(), "0.4233108");
assert_eq!(o, Less);
Sourcepub fn sub_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
pub fn sub_round(self, other: Float, rm: RoundingMode) -> (Float, Ordering)
Subtracts two Float
s, rounding the result with the specified rounding mode. Both
Float
s are taken by value. An Ordering
is also returned, indicating whether the
rounded difference is less than, equal to, or greater than the exact difference. Although
NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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
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(1)$
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(Float::from(-E), Floor);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_round(Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_round(Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn sub_round_val_ref(
self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_round_val_ref( self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, rounding the result with the specified rounding mode. The
Float
is taken by value and the Rational
by reference. An Ordering
is also
returned, indicating whether the rounded difference is less than, equal to, or greater than
the exact difference. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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_val_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(m)$
where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits())
, and $m$ is 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_val_ref(&Float::from(-E), Floor);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_round_val_ref(&Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_round_val_ref(&Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn sub_round_ref_val(
&self,
other: Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_round_ref_val( &self, other: Float, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_round_ref_val(Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_round_ref_val(Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn sub_round_ref_ref(
&self,
other: &Float,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_round_ref_ref( &self, other: &Float, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts two Float
s, rounding the result with the specified rounding mode. Both
Float
s 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
NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.859874482048838");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_round_ref_ref(&Float::from(-E), Ceiling);
assert_eq!(sum.to_string(), "5.859874482048839");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_round_ref_ref(&Float::from(-E), Nearest);
assert_eq!(sum.to_string(), "5.859874482048838");
assert_eq!(o, Less);
Sourcepub fn sub_prec_round_assign(
&mut self,
other: Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn sub_prec_round_assign( &mut self, other: Float, prec: u64, rm: RoundingMode, ) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Float
on the right-hand side is
taken by value. An Ordering
is returned, indicating whether the rounded difference is
less than, equal to, or greater than the exact difference. Although NaN
s are not
comparable to any Float
, whenever this function sets the Float
to NaN
it also
returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::sub_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::sub_prec_assign
instead. If
you know that your target precision is the maximum of the precisions of the two inputs,
consider using Float::sub_round_assign
instead. If both of these things are true,
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 prec
.
§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 mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign(Float::from(E), 5, Floor), Less);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign(Float::from(E), 5, Ceiling), Greater);
assert_eq!(x.to_string(), "0.44");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign(Float::from(E), 5, Nearest), Less);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign(Float::from(E), 20, Floor), Less);
assert_eq!(x.to_string(), "0.4233108");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign(Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "0.4233112");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign(Float::from(E), 20, Nearest), Less);
assert_eq!(x.to_string(), "0.4233108");
Sourcepub fn sub_prec_round_assign_ref(
&mut self,
other: &Float,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn sub_prec_round_assign_ref( &mut self, other: &Float, prec: u64, rm: RoundingMode, ) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Float
on the right-hand side is
taken by reference. An Ordering
is returned, indicating whether the rounded difference
is less than, equal to, or greater than the exact difference. Although NaN
s are not
comparable to any Float
, whenever this function sets the Float
to NaN
it also
returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::sub_prec_round
documentation for information on special cases, overflow,
and underflow.
If you know you’ll be using Nearest
, consider using Float::sub_prec_assign_ref
instead. If you know that your target precision is the maximum of the precisions of the two
inputs, consider using Float::sub_round_assign
instead. If both of these things are
true, 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 prec
.
§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 mut x = Float::from(PI);
assert_eq!(x.sub_prec_round_assign_ref(&Float::from(E), 5, Floor), Less);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign_ref(&Float::from(E), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "0.44");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign_ref(&Float::from(E), 5, Nearest),
Less
);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign_ref(&Float::from(E), 20, Floor),
Less
);
assert_eq!(x.to_string(), "0.4233108");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign_ref(&Float::from(E), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "0.4233112");
let mut x = Float::from(PI);
assert_eq!(
x.sub_prec_round_assign_ref(&Float::from(E), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "0.4233108");
Sourcepub fn sub_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
pub fn sub_prec_assign(&mut self, other: Float, prec: u64) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result to the nearest value of
the specified precision. The Float
on the right-hand side is taken by value. An
Ordering
is returned, indicating whether the rounded difference is less than, equal to,
or greater than the exact difference. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::sub_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_prec_round_assign
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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_assign(Float::from(E), 5), Less);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_assign(Float::from(E), 20), Less);
assert_eq!(x.to_string(), "0.4233108");
Sourcepub fn sub_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
pub fn sub_prec_assign_ref(&mut self, other: &Float, prec: u64) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result to the nearest value of
the specified precision. The Float
on the right-hand side is taken by reference. An
Ordering
is returned, indicating whether the rounded difference is less than, equal to,
or greater than the exact difference. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::sub_prec
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_prec_round_assign_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)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use core::f64::consts::{E, PI};
use malachite_float::Float;
use std::cmp::Ordering::*;
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_assign_ref(&Float::from(E), 5), Less);
assert_eq!(x.to_string(), "0.42");
let mut x = Float::from(PI);
assert_eq!(x.sub_prec_assign_ref(&Float::from(E), 20), Less);
assert_eq!(x.to_string(), "0.4233108");
Sourcepub fn sub_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
pub fn sub_round_assign(&mut self, other: Float, rm: RoundingMode) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result with the specified
rounding mode. The Float
on the right-hand side is taken by value. An Ordering
is
returned, indicating whether the rounded difference is less than, equal to, or greater than
the exact difference. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to 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.
$$ x \gets 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| < 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.
See the Float::sub_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using Float::sub_prec_round_assign
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(1)$
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 mut x = Float::from(PI);
assert_eq!(x.sub_round_assign(Float::from(-E), Floor), Less);
assert_eq!(x.to_string(), "5.859874482048838");
let mut x = Float::from(PI);
assert_eq!(x.sub_round_assign(Float::from(-E), Ceiling), Greater);
assert_eq!(x.to_string(), "5.859874482048839");
let mut x = Float::from(PI);
assert_eq!(x.sub_round_assign(Float::from(-E), Nearest), Less);
assert_eq!(x.to_string(), "5.859874482048838");
Sourcepub fn sub_round_assign_ref(
&mut self,
other: &Float,
rm: RoundingMode,
) -> Ordering
pub fn sub_round_assign_ref( &mut self, other: &Float, rm: RoundingMode, ) -> Ordering
Subtracts a Float
by a Float
in place, rounding the result with the specified
rounding mode. The Float
on the right-hand side is taken by reference. An Ordering
is returned, indicating whether the rounded difference is less than, equal to, or greater
than the exact difference. Although NaN
s are not comparable to any Float
, whenever
this function sets the Float
to 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.
$$ x \gets 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| < 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.
See the Float::sub_round
documentation for information on special cases, overflow, and
underflow.
If you want to specify an output precision, consider using
Float::sub_prec_round_assign_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(m)$
where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits())
, and $m$ is 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 mut x = Float::from(PI);
assert_eq!(x.sub_round_assign_ref(&Float::from(-E), Floor), Less);
assert_eq!(x.to_string(), "5.859874482048838");
let mut x = Float::from(PI);
assert_eq!(x.sub_round_assign_ref(&Float::from(-E), Ceiling), Greater);
assert_eq!(x.to_string(), "5.859874482048839");
let mut x = Float::from(PI);
assert_eq!(x.sub_round_assign_ref(&Float::from(-E), Nearest), Less);
assert_eq!(x.to_string(), "5.859874482048838");
Sourcepub fn sub_rational_prec_round(
self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_prec_round( self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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
value. An Ordering
is also returned, indicating whether the rounded difference is less
than, equal to, or greater than the exact difference. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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
instead.
If you know that your target precision is the precision of the Float
input, consider
using Float::sub_rational_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 \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(Rational::from_unsigneds(1u8, 3), 5, Floor);
assert_eq!(sum.to_string(), "2.8");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).sub_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Ceiling);
assert_eq!(sum.to_string(), "2.9");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).sub_rational_prec_round(Rational::from_unsigneds(1u8, 3), 5, Nearest);
assert_eq!(sum.to_string(), "2.8");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).sub_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Floor);
assert_eq!(sum.to_string(), "2.808258");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).sub_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Ceiling);
assert_eq!(sum.to_string(), "2.808262");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).sub_rational_prec_round(Rational::from_unsigneds(1u8, 3), 20, Nearest);
assert_eq!(sum.to_string(), "2.808258");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_round_val_ref(
self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_prec_round_val_ref( self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 value and the Rational
by
reference. An Ordering
is also returned, indicating whether the rounded difference is
less than, equal to, or greater than the exact difference. Although NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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_val_ref
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::sub_rational_round_val_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_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Floor,
);
assert_eq!(sum.to_string(), "2.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Ceiling,
);
assert_eq!(sum.to_string(), "2.9");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
5,
Nearest,
);
assert_eq!(sum.to_string(), "2.8");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Floor,
);
assert_eq!(sum.to_string(), "2.808258");
assert_eq!(o, Less);
let (sum, o) = Float::from(PI).sub_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Ceiling,
);
assert_eq!(sum.to_string(), "2.808262");
assert_eq!(o, Greater);
let (sum, o) = Float::from(PI).sub_rational_prec_round_val_ref(
&Rational::from_unsigneds(1u8, 3),
20,
Nearest,
);
assert_eq!(sum.to_string(), "2.808258");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_round_ref_val(
&self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_prec_round_ref_val( &self, other: Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.8");
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.9");
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.8");
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.808258");
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.808262");
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.808258");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_round_ref_ref(
&self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_prec_round_ref_ref( &self, other: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, 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 NaN
s 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| < 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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,p,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,p,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,p,m)<0$, and $m$ is
Floor
orUp
, $-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.8");
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.9");
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.8");
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.808258");
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.808262");
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.808258");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec(self, other: Rational, prec: u64) -> (Float, Ordering)
pub fn sub_rational_prec(self, other: Rational, prec: u64) -> (Float, 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 value. An
Ordering
is also returned, indicating whether the rounded difference is less than, equal
to, or greater than the exact difference. Although NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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
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(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(Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "1.641592");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_val_ref(
self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn sub_rational_prec_val_ref( self, other: &Rational, prec: u64, ) -> (Float, Ordering)
Subtracts a Float
by a Rational
, rounding the result to the nearest value of the
specified precision. The Float
is taken by value and the Rational
by reference. An
Ordering
is also returned, indicating whether the rounded difference is less than, equal
to, or greater than the exact difference. Although NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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_val_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_val_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_val_ref(&Rational::exact_from(1.5), 20);
assert_eq!(sum.to_string(), "1.641592");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_ref_val(
&self,
other: Rational,
prec: u64,
) -> (Float, Ordering)
pub fn sub_rational_prec_ref_val( &self, other: Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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.641592");
assert_eq!(o, Less);
Sourcepub fn sub_rational_prec_ref_ref(
&self,
other: &Rational,
prec: u64,
) -> (Float, Ordering)
pub fn sub_rational_prec_ref_ref( &self, other: &Rational, prec: u64, ) -> (Float, 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 NaN
s are not comparable to any
Float
, whenever this function returns a NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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)\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.
- 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.641592");
assert_eq!(o, Less);
Sourcepub fn sub_rational_round(
self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_round( self, other: Rational, rm: RoundingMode, ) -> (Float, 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 value. An Ordering
is
also returned, indicating whether the rounded difference is less than, equal to, or greater
than the exact difference. Although NaN
s 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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
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(Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "2.808259320256457");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).sub_rational_round(Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "2.808259320256461");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).sub_rational_round(Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "2.808259320256461");
assert_eq!(o, Greater);
Sourcepub fn sub_rational_round_val_ref(
self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_round_val_ref( self, other: &Rational, rm: RoundingMode, ) -> (Float, Ordering)
Subtracts a Float
by a Rational
, rounding the result with the specified rounding
mode. The Float
is taken by value and the Rational
by reference. An Ordering
is
also returned, indicating whether the rounded difference is less than, equal to, or greater
than the exact difference. Although NaN
s 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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_val_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_val_ref(&Rational::from_unsigneds(1u8, 3), Floor);
assert_eq!(sum.to_string(), "2.808259320256457");
assert_eq!(o, Less);
let (sum, o) =
Float::from(PI).sub_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Ceiling);
assert_eq!(sum.to_string(), "2.808259320256461");
assert_eq!(o, Greater);
let (sum, o) =
Float::from(PI).sub_rational_round_val_ref(&Rational::from_unsigneds(1u8, 3), Nearest);
assert_eq!(sum.to_string(), "2.808259320256461");
assert_eq!(o, Greater);
Sourcepub fn sub_rational_round_ref_val(
&self,
other: Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_round_ref_val( &self, other: Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.808259320256457");
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.808259320256461");
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.808259320256461");
assert_eq!(o, Greater);
Sourcepub fn sub_rational_round_ref_ref(
&self,
other: &Rational,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn sub_rational_round_ref_ref( &self, other: &Rational, rm: RoundingMode, ) -> (Float, 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 NaN
s 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
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
, orNearest
, $\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,y,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,y,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $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
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,y,m)<0$, and $m$ is
Floor
orUp
, $-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.808259320256457");
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.808259320256461");
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.808259320256461");
assert_eq!(o, Greater);
Sourcepub fn sub_rational_prec_round_assign(
&mut self,
other: Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn sub_rational_prec_round_assign( &mut self, other: Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by value. An
Ordering
is returned, indicating whether the rounded difference is less than, equal to,
or greater than the exact difference. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::sub_rational_prec_round
documentation for information on special cases,
overflow, and underflow.
If you know you’ll be using Nearest
, consider using Float::sub_rational_prec_assign
instead. If you know that your target precision is the precision of the Float
input,
consider using Float::sub_rational_round_assign
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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "2.8");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.9");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 5, Nearest),
Less
);
assert_eq!(x.to_string(), "2.8");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "2.808258");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.808262");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign(Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "2.808258");
This is mpfr_sub_q from gmp_op.c, MPFR 4.2.0.
Sourcepub fn sub_rational_prec_round_assign_ref(
&mut self,
other: &Rational,
prec: u64,
rm: RoundingMode,
) -> Ordering
pub fn sub_rational_prec_round_assign_ref( &mut self, other: &Rational, prec: u64, rm: RoundingMode, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result to the specified
precision and with the specified rounding mode. The Rational
is taken by reference. An
Ordering
is returned, indicating whether the rounded difference is less than, equal to,
or greater than the exact difference. Although NaN
s are not comparable to any Float
,
whenever this function sets the Float
to NaN
it also returns Equal
.
See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$.
If the output has a precision, it is prec
.
See the Float::sub_rational_prec_round
documentation for information on special cases,
overflow, and underflow.
If you know you’ll be using Nearest
, consider using
Float::sub_rational_prec_assign_ref
instead. If you know that your target precision is
the precision of the Float
input, consider using
Float::sub_rational_round_assign_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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Floor),
Less
);
assert_eq!(x.to_string(), "2.8");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.9");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 5, Nearest),
Less
);
assert_eq!(x.to_string(), "2.8");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Floor),
Less
);
assert_eq!(x.to_string(), "2.808258");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.808262");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_round_assign_ref(&Rational::from_unsigneds(1u8, 3), 20, Nearest),
Less
);
assert_eq!(x.to_string(), "2.808258");
Sourcepub fn sub_rational_prec_assign(
&mut self,
other: Rational,
prec: u64,
) -> Ordering
pub fn sub_rational_prec_assign( &mut self, other: Rational, prec: u64, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result to the nearest value
of the specified precision. The Rational
is taken by value. An Ordering
is returned,
indicating whether the rounded difference is less than, equal to, or greater than the exact
difference. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::sub_rational_prec
documentation for information on special cases,
overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_rational_prec_round_assign
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(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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_assign(Rational::exact_from(1.5), 5),
Less
);
assert_eq!(x.to_string(), "1.62");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_assign(Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "1.641592");
Sourcepub fn sub_rational_prec_assign_ref(
&mut self,
other: &Rational,
prec: u64,
) -> Ordering
pub fn sub_rational_prec_assign_ref( &mut self, other: &Rational, prec: u64, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result to the nearest value
of the specified precision. The Rational
is taken by reference. An Ordering
is
returned, indicating whether the rounded difference is less than, equal to, or greater than
the exact difference. Although NaN
s are not comparable to any Float
, whenever this
function sets the Float
to NaN
it also returns Equal
.
If the difference is equidistant from two Float
s 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.
$$ x \gets 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
.
See the Float::sub_rational_prec_val_ref
documentation for information on special cases,
overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_rational_prec_round_assign_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(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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_assign_ref(&Rational::exact_from(1.5), 5),
Less
);
assert_eq!(x.to_string(), "1.62");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_prec_assign_ref(&Rational::exact_from(1.5), 20),
Less
);
assert_eq!(x.to_string(), "1.641592");
Sourcepub fn sub_rational_round_assign(
&mut self,
other: Rational,
rm: RoundingMode,
) -> Ordering
pub fn sub_rational_round_assign( &mut self, other: Rational, rm: RoundingMode, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result with the specified
rounding mode. The Rational
is taken by value. An Ordering
is returned, indicating
whether the rounded difference is less than, equal to, or greater than the exact difference.
Although NaN
s are not comparable to any Float
, whenever this function sets the
Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::sub_rational_round
documentation for information on special cases,
overflow, and underflow.
If you want to specify an output precision, consider using
Float::sub_rational_prec_round_assign
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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign(Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "2.808259320256457");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign(Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.808259320256461");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign(Rational::from_unsigneds(1u8, 3), Nearest),
Greater
);
assert_eq!(x.to_string(), "2.808259320256461");
Sourcepub fn sub_rational_round_assign_ref(
&mut self,
other: &Rational,
rm: RoundingMode,
) -> Ordering
pub fn sub_rational_round_assign_ref( &mut self, other: &Rational, rm: RoundingMode, ) -> Ordering
Subtracts a Rational
by a Float
in place, rounding the result with the specified
rounding mode. The Rational
is taken by reference. An Ordering
is returned,
indicating whether the rounded difference is less than, equal to, or greater than the exact
difference. Although NaN
s are not comparable to any Float
, whenever this function sets
the Float
to NaN
it also returns Equal
.
The precision of the output is the precision of the input Float
. See RoundingMode
for a description of the possible rounding modes.
$$ x \gets 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 inputFloat
. - If $x-y$ is finite and nonzero, and $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 |x-y|\rfloor-p}$, where $p$ is the precision of the inputFloat
.
If the output has a precision, it is the precision of the input Float
.
See the Float::sub_rational_round_val_ref
documentation for information on special
cases, overflow, and underflow.
If you want to specify an output precision, consider using
Float::sub_rational_prec_round_assign_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 input Float
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 mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Floor),
Less
);
assert_eq!(x.to_string(), "2.808259320256457");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Ceiling),
Greater
);
assert_eq!(x.to_string(), "2.808259320256461");
let mut x = Float::from(PI);
assert_eq!(
x.sub_rational_round_assign_ref(&Rational::from_unsigneds(1u8, 3), Nearest),
Greater
);
assert_eq!(x.to_string(), "2.808259320256461");
Source§impl Float
impl Float
Sourcepub const fn is_finite(&self) -> bool
pub const fn is_finite(&self) -> bool
Determines whether a Float
is finite.
NaN is not finite.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, One};
use malachite_float::Float;
assert_eq!(Float::NAN.is_finite(), false);
assert_eq!(Float::INFINITY.is_finite(), false);
assert_eq!(Float::ONE.is_finite(), true);
Sourcepub const fn is_infinite(&self) -> bool
pub const fn is_infinite(&self) -> bool
Determines whether a Float
is infinite.
NaN is not infinite.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, One};
use malachite_float::Float;
assert_eq!(Float::NAN.is_infinite(), false);
assert_eq!(Float::INFINITY.is_infinite(), true);
assert_eq!(Float::ONE.is_infinite(), false);
Sourcepub const fn is_positive_zero(&self) -> bool
pub const fn is_positive_zero(&self) -> bool
Determines whether a Float
is positive zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.is_positive_zero(), false);
assert_eq!(Float::INFINITY.is_positive_zero(), false);
assert_eq!(Float::ONE.is_positive_zero(), false);
assert_eq!(Float::ZERO.is_positive_zero(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_positive_zero(), false);
Sourcepub const fn is_negative_zero(&self) -> bool
pub const fn is_negative_zero(&self) -> bool
Determines whether a Float
is negative zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.is_negative_zero(), false);
assert_eq!(Float::INFINITY.is_negative_zero(), false);
assert_eq!(Float::ONE.is_negative_zero(), false);
assert_eq!(Float::ZERO.is_negative_zero(), false);
assert_eq!(Float::NEGATIVE_ZERO.is_negative_zero(), true);
Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Determines whether a Float
is zero (positive or negative).
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.is_zero(), false);
assert_eq!(Float::INFINITY.is_zero(), false);
assert_eq!(Float::ONE.is_zero(), false);
assert_eq!(Float::ZERO.is_zero(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_zero(), true);
Sourcepub const fn is_normal(&self) -> bool
pub const fn is_normal(&self) -> bool
Determines whether a Float
is normal, that is, finite and nonzero.
There is no notion of subnormal Float
s.
§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);
Sourcepub const fn is_sign_positive(&self) -> bool
pub const fn is_sign_positive(&self) -> bool
Determines whether a Float
’s sign is positive.
A NaN has no sign, so this function returns false when given a NaN.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::Float;
assert_eq!(Float::NAN.is_sign_positive(), false);
assert_eq!(Float::INFINITY.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_INFINITY.is_sign_positive(), false);
assert_eq!(Float::ZERO.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_ZERO.is_sign_positive(), false);
assert_eq!(Float::ONE.is_sign_positive(), true);
assert_eq!(Float::NEGATIVE_ONE.is_sign_positive(), false);
Sourcepub const fn is_sign_negative(&self) -> bool
pub const fn is_sign_negative(&self) -> bool
Determines whether a Float
’s sign is negative.
A NaN has no sign, so this function returns false when given a NaN.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::Float;
assert_eq!(Float::NAN.is_sign_negative(), false);
assert_eq!(Float::INFINITY.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_INFINITY.is_sign_negative(), true);
assert_eq!(Float::ZERO.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_ZERO.is_sign_negative(), true);
assert_eq!(Float::ONE.is_sign_negative(), false);
assert_eq!(Float::NEGATIVE_ONE.is_sign_negative(), true);
Sourcepub const fn classify(&self) -> FpCategory
pub const fn classify(&self) -> FpCategory
Classifies a Float
into one of several categories.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::Float;
use std::num::FpCategory;
assert_eq!(Float::NAN.classify(), FpCategory::Nan);
assert_eq!(Float::INFINITY.classify(), FpCategory::Infinite);
assert_eq!(Float::NEGATIVE_INFINITY.classify(), FpCategory::Infinite);
assert_eq!(Float::ZERO.classify(), FpCategory::Zero);
assert_eq!(Float::NEGATIVE_ZERO.classify(), FpCategory::Zero);
assert_eq!(Float::ONE.classify(), FpCategory::Normal);
assert_eq!(Float::NEGATIVE_ONE.classify(), FpCategory::Normal);
Sourcepub fn into_non_nan(self) -> Option<Float>
pub fn into_non_nan(self) -> Option<Float>
Turns a NaN into a None
and wraps any non-NaN Float
with a Some
. The Float
is
taken by value.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.into_non_nan(), None);
assert_eq!(Float::INFINITY.into_non_nan(), Some(Float::INFINITY));
assert_eq!(Float::ZERO.into_non_nan(), Some(Float::ZERO));
assert_eq!(
Float::NEGATIVE_ZERO.into_non_nan(),
Some(Float::NEGATIVE_ZERO)
);
assert_eq!(Float::ONE.into_non_nan(), Some(Float::ONE));
Sourcepub fn to_non_nan(&self) -> Option<Float>
pub fn to_non_nan(&self) -> Option<Float>
Turns a NaN into a None
and wraps any non-NaN Float
with a Some
. The Float
is
taken by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.to_non_nan(), None);
assert_eq!(Float::INFINITY.to_non_nan(), Some(Float::INFINITY));
assert_eq!(Float::ZERO.to_non_nan(), Some(Float::ZERO));
assert_eq!(
Float::NEGATIVE_ZERO.to_non_nan(),
Some(Float::NEGATIVE_ZERO)
);
assert_eq!(Float::ONE.to_non_nan(), Some(Float::ONE));
Sourcepub fn into_finite(self) -> Option<Float>
pub fn into_finite(self) -> Option<Float>
Turns any Float
that’s NaN or infinite into a None
and wraps any finite Float
with
a Some
. The Float
is taken by value.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.into_finite(), None);
assert_eq!(Float::INFINITY.into_finite(), None);
assert_eq!(Float::ZERO.into_finite(), Some(Float::ZERO));
assert_eq!(
Float::NEGATIVE_ZERO.into_finite(),
Some(Float::NEGATIVE_ZERO)
);
assert_eq!(Float::ONE.into_finite(), Some(Float::ONE));
Sourcepub fn to_finite(&self) -> Option<Float>
pub fn to_finite(&self) -> Option<Float>
Turns any Float
that’s NaN or infinite into a None
and wraps any finite Float
with
a Some
. The Float
is taken by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeZero, One, Zero};
use malachite_float::Float;
assert_eq!(Float::NAN.to_finite(), None);
assert_eq!(Float::INFINITY.to_finite(), None);
assert_eq!(Float::ZERO.to_finite(), Some(Float::ZERO));
assert_eq!(Float::NEGATIVE_ZERO.to_finite(), Some(Float::NEGATIVE_ZERO));
assert_eq!(Float::ONE.to_finite(), Some(Float::ONE));
Source§impl Float
impl Float
Sourcepub fn complexity(&self) -> u64
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§impl Float
impl Float
Sourcepub const MIN_POSITIVE: Float
pub const MIN_POSITIVE: Float
The minimum representable positive value, or $2^{-2^{30}}$, with precision 1.
Sourcepub fn min_positive_value_prec(prec: u64) -> Float
pub fn min_positive_value_prec(prec: u64) -> Float
Returns the minimum representable positive value, or $2^{-2^{30}}$, with the given precision.
$$ f(p) = 2^{-2^{30}}, $$
and the output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::min_positive_value_prec(1).to_string(), "too_small");
assert_eq!(Float::min_positive_value_prec(10).to_string(), "too_small");
assert_eq!(Float::min_positive_value_prec(100).to_string(), "too_small");
assert_eq!(Float::min_positive_value_prec(1).get_prec(), Some(1));
assert_eq!(Float::min_positive_value_prec(10).get_prec(), Some(10));
assert_eq!(Float::min_positive_value_prec(100).get_prec(), Some(100));
Sourcepub fn max_finite_value_with_prec(prec: u64) -> Float
pub fn max_finite_value_with_prec(prec: u64) -> Float
There is no maximum finite Float
, but there is one for any given precision. This
function returns that Float
.
$$
f(p) = (1-(1/2)^p)2^{2^{30}-1},
$$
where $p$ is the prec
. The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::max_finite_value_with_prec(1).to_string(), "too_big");
assert_eq!(Float::max_finite_value_with_prec(10).to_string(), "too_big");
assert_eq!(
Float::max_finite_value_with_prec(100).to_string(),
"too_big"
);
assert_eq!(Float::max_finite_value_with_prec(1).get_prec(), Some(1));
assert_eq!(Float::max_finite_value_with_prec(10).get_prec(), Some(10));
assert_eq!(Float::max_finite_value_with_prec(100).get_prec(), Some(100));
Sourcepub fn one_prec(prec: u64) -> Float
pub fn one_prec(prec: u64) -> Float
Returns the number 1, with the given precision.
$$ f(p) = 1, $$
and the output has precision $p$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::one_prec(1), 1);
assert_eq!(Float::one_prec(10), 1);
assert_eq!(Float::one_prec(100), 1);
assert_eq!(Float::one_prec(1).get_prec(), Some(1));
assert_eq!(Float::one_prec(10).get_prec(), Some(10));
assert_eq!(Float::one_prec(100).get_prec(), Some(100));
Sourcepub fn two_prec(prec: u64) -> Float
pub fn two_prec(prec: u64) -> Float
Returns the number 2, with the given precision.
$$ f(p) = 2, $$
and the output has precision $p$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::two_prec(1), 2);
assert_eq!(Float::two_prec(10), 2);
assert_eq!(Float::two_prec(100), 2);
assert_eq!(Float::two_prec(1).get_prec(), Some(1));
assert_eq!(Float::two_prec(10).get_prec(), Some(10));
assert_eq!(Float::two_prec(100).get_prec(), Some(100));
Sourcepub fn negative_one_prec(prec: u64) -> Float
pub fn negative_one_prec(prec: u64) -> Float
Returns the number $-1$, with the given precision.
$$ f(p) = -1, $$
and the output has precision $p$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::negative_one_prec(1), -1);
assert_eq!(Float::negative_one_prec(10), -1);
assert_eq!(Float::negative_one_prec(100), -1);
assert_eq!(Float::negative_one_prec(1).get_prec(), Some(1));
assert_eq!(Float::negative_one_prec(10).get_prec(), Some(10));
assert_eq!(Float::negative_one_prec(100).get_prec(), Some(100));
Sourcepub fn one_half_prec(prec: u64) -> Float
pub fn one_half_prec(prec: u64) -> Float
Returns the number 0.5, with the given precision.
$$ f(p) = 0.5, $$
and the output has precision $p$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
assert_eq!(Float::one_half_prec(1), 0.5);
assert_eq!(Float::one_half_prec(10), 0.5);
assert_eq!(Float::one_half_prec(100), 0.5);
assert_eq!(Float::one_half_prec(1).get_prec(), Some(1));
assert_eq!(Float::one_half_prec(10).get_prec(), Some(10));
assert_eq!(Float::one_half_prec(100).get_prec(), Some(100));
Source§impl Float
impl Float
Sourcepub fn to_significand(&self) -> Option<Natural>
pub fn to_significand(&self) -> Option<Natural>
Gets the significand of a Float
, taking the Float
by value.
The significand is the smallest positive integer which is some power of 2 times the
Float
, and whose number of significant bits is a multiple of the limb width. If the
Float
is NaN, infinite, or zero, then None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
#[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
);
}
Sourcepub fn into_significand(self) -> Option<Natural>
pub fn into_significand(self) -> Option<Natural>
Gets the significand of a Float
, taking the Float
by reference.
The significand is the smallest positive integer which is some power of 2 times the
Float
, and whose number of significant bits is a multiple of the limb width. If the
Float
is NaN, infinite, or zero, then None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
#[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.into_significand(), None);
assert_eq!(Float::INFINITY.into_significand(), None);
assert_eq!(Float::ZERO.into_significand(), None);
#[cfg(not(feature = "32_bit_limbs"))]
{
assert_eq!(Float::ONE.into_significand(), Some(Natural::power_of_2(63)));
assert_eq!(
Float::from(std::f64::consts::PI)
.into_significand()
.unwrap(),
14488038916154245120u64
);
}
Sourcepub const fn significand_ref(&self) -> Option<&Natural>
pub const fn significand_ref(&self) -> Option<&Natural>
Returns a reference to the significand of a Float
.
The significand is the smallest positive integer which is some power of 2 times the
Float
, and whose number of significant bits is a multiple of the limb width. If the
Float
is NaN, infinite, or zero, then None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
#[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
);
}
Sourcepub const fn get_exponent(&self) -> Option<i32>
pub const 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));
Sourcepub const fn get_prec(&self) -> Option<u64>
pub const fn get_prec(&self) -> Option<u64>
Returns a Float
’s precision. The precision is a positive integer denoting how many of
the Float
’s bits are significant.
Only Float
s that are finite and nonzero have a precision. For other Float
s, 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));
Sourcepub fn get_min_prec(&self) -> Option<u64>
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 Float
s that are finite and nonzero have a minimum precision. For other Float
s,
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_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));
Sourcepub fn set_prec_round(&mut self, prec: u64, rm: RoundingMode) -> Ordering
pub fn set_prec_round(&mut self, prec: u64, rm: RoundingMode) -> Ordering
Changes a Float
’s precision. If the precision decreases, rounding may be necessary, and
will use the provided RoundingMode
.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the Float
originally had the maximum exponent, it is possible for this function to
overflow. This is even possible if rm
is Nearest
, even though infinity is never nearer
to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or if rm
is Exact
but setting the desired precision requires
rounding.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let mut x = original_x.clone();
assert_eq!(x.set_prec_round(100, Exact), Equal);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
let mut x = original_x.clone();
assert_eq!(x.set_prec_round(10, Floor), Less);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
let mut x = original_x.clone();
assert_eq!(x.set_prec_round(10, Ceiling), Greater);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
Sourcepub fn set_prec(&mut self, p: u64) -> Ordering
pub fn set_prec(&mut self, p: u64) -> Ordering
Changes a Float
’s precision. If the precision decreases, rounding may be necessary, and
Nearest
will be used.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the Float
originally had the maximum exponent, it is possible for this function to
overflow, even though infinity is never nearer to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
To use a different rounding mode, try Float::set_prec_round
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let mut x = original_x.clone();
assert_eq!(x.set_prec(100), Equal);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
let mut x = original_x.clone();
assert_eq!(x.set_prec(10), Greater);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
Sourcepub fn from_float_prec_round(
x: Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_float_prec_round( x: Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Creates a Float
from another Float
, possibly with a different precision. If the
precision decreases, rounding may be necessary, and will use the provided RoundingMode
.
The input Float
is taken by value.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the input Float
has the maximum exponent, it is possible for this function to
overflow. This is even possible if rm
is Nearest
, even though infinity is never nearer
to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or if rm
is Exact
but setting the desired precision requires
rounding.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let (x, o) = Float::from_float_prec_round(original_x.clone(), 100, Exact);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Equal);
let (x, o) = Float::from_float_prec_round(original_x.clone(), 10, Floor);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_float_prec_round(original_x.clone(), 10, Ceiling);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
Sourcepub fn from_float_prec_round_ref(
x: &Float,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_float_prec_round_ref( x: &Float, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Creates a Float
from another Float
, possibly with a different precision. If the
precision decreases, rounding may be necessary, and will use the provided RoundingMode
.
The input Float
is taken by reference.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the input Float
has the maximum exponent, it is possible for this function to
overflow. This is even possible if rm
is Nearest
, even though infinity is never nearer
to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or if rm
is Exact
but setting the desired precision requires
rounding.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let (x, o) = Float::from_float_prec_round_ref(&original_x, 100, Exact);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Equal);
let (x, o) = Float::from_float_prec_round_ref(&original_x, 10, Floor);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_float_prec_round_ref(&original_x, 10, Ceiling);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
Sourcepub fn from_float_prec(x: Float, prec: u64) -> (Float, Ordering)
pub fn from_float_prec(x: Float, prec: u64) -> (Float, Ordering)
Creates a Float
from another Float
, possibly with a different precision. If the
precision decreases, rounding may be necessary, and will use Nearest
. The input
Float
is taken by value.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the Float
originally had the maximum exponent, it is possible for this function to
overflow, even though infinity is never nearer to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
To use a different rounding mode, try Float::from_float_prec_round
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let (x, o) = Float::from_float_prec(original_x.clone(), 100);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Equal);
let (x, o) = Float::from_float_prec(original_x.clone(), 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
Sourcepub fn from_float_prec_ref(x: &Float, prec: u64) -> (Float, Ordering)
pub fn from_float_prec_ref(x: &Float, prec: u64) -> (Float, Ordering)
Creates a Float
from another Float
, possibly with a different precision. If the
precision decreases, rounding may be necessary, and will use Nearest
. The input
Float
is taken by reference.
Returns an Ordering
, indicating whether the final value is less than, greater than, or
equal to the original value.
If the Float
originally had the maximum exponent, it is possible for this function to
overflow, even though infinity is never nearer to the exact result than any finite Float
is. This is to match the behavior of MPFR.
This function never underflows.
To use a different rounding mode, try Float::from_float_prec_round_ref
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
let original_x = Float::from(1.0f64 / 3.0);
assert_eq!(original_x.to_string(), "0.33333333333333331");
assert_eq!(original_x.get_prec(), Some(53));
let (x, o) = Float::from_float_prec_ref(&original_x, 100);
assert_eq!(x.to_string(), "0.3333333333333333148296162562474");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Equal);
let (x, o) = Float::from_float_prec_ref(&original_x, 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
Source§impl Float
impl Float
Sourcepub fn ulp(&self) -> Option<Float>
pub fn ulp(&self) -> Option<Float>
Gets a Float
’s ulp (unit in last place, or unit of least precision).
If the Float
is positive, its ulp is the distance to the next-largest Float
with the
same precision; if it is negative, the next-smallest. (This definition works even if the
Float
is the largest in its binade. If the Float
is 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("2.0e-30"));
let s = Float::from(std::f64::consts::PI)
.ulp()
.map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("4.0e-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.0e30"));
let s = Float::power_of_2(-100i64).ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("8.0e-31"));
let s = Float::NEGATIVE_ONE.ulp().map(|x| x.to_string());
assert_eq!(s.as_ref().map(|s| s.as_str()), Some("1.0"));
Sourcepub fn increment(&mut self)
pub fn increment(&mut self)
Increments a Float
by its ulp. See Float::ulp
for details.
If the Float
is positive and is the largest Float
in its binade with its precision,
then
- If its exponent is not the maximum exponent, it will become the smallest
Float
in the next-higher binade, and its precision will increase by 1 (so that its ulp remains the same); - If its exponent is the maximum exponent, it will become $\infty$.
If the Float
is negative and is closer to zero than any other Float
in its binade
with its precision, then
- If its precision is 1, it will become negative zero.
- If its precision is greater than 1 and its exponent is not the minimum exponent, it will
become the farthest-from-zero
Float
in the next-lower binade, and its precision will decrease by 1 (so that its ulp remains the same). - If its precision is greater than 1 and its exponent is the minimum exponent, it will become negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is NaN, infinite, or zero.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{NegativeOne, One};
use malachite_float::Float;
let mut x = Float::ONE;
assert_eq!(x.to_string(), "1.0");
x.increment();
assert_eq!(x.to_string(), "2.0");
let mut x = Float::one_prec(100);
assert_eq!(x.to_string(), "1.0");
x.increment();
assert_eq!(x.to_string(), "1.000000000000000000000000000002");
let mut x = Float::from(std::f64::consts::PI);
assert_eq!(x.to_string(), "3.141592653589793");
x.increment();
assert_eq!(x.to_string(), "3.141592653589797");
let mut x = Float::power_of_2(100u64);
assert_eq!(x.to_string(), "1.0e30");
x.increment();
assert_eq!(x.to_string(), "3.0e30");
let mut x = Float::power_of_2(-100i64);
assert_eq!(x.to_string(), "8.0e-31");
x.increment();
assert_eq!(x.to_string(), "1.6e-30");
let mut x = Float::NEGATIVE_ONE;
assert_eq!(x.to_string(), "-1.0");
x.increment();
assert_eq!(x.to_string(), "-0.0");
Sourcepub fn decrement(&mut self)
pub fn decrement(&mut self)
Decrements a Float
by its ulp. See Float::ulp
for details.
If the Float
is negative and is the largest Float
in its binade with its precision,
then
- If its exponent is not the maximum exponent, it will become the closest-to-zero
Float
in the next-higher binade, and its precision will increase by 1 (so that its ulp remains the same); - If its exponent is the maximum exponent, it will become $-\infty$.
If the Float
is positive and is smaller than any other Float
in its binade with its
precision, then
- If its precision is 1, it will become positive zero.
- If its precision is greater than 1 and its exponent is not the minimum exponent, it will
become the largest
Float
in the next-lower binade, and its precision will decrease by 1 (so that its ulp remains the same). - If its precision is greater than 1 and its exponent is the minimum exponent, it will become positive zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is NaN, infinite, or zero.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{NegativeOne, One};
use malachite_float::Float;
let mut x = Float::ONE;
assert_eq!(x.to_string(), "1.0");
x.decrement();
assert_eq!(x.to_string(), "0.0");
let mut x = Float::one_prec(100);
assert_eq!(x.to_string(), "1.0");
x.decrement();
assert_eq!(x.to_string(), "0.999999999999999999999999999998");
let mut x = Float::from(std::f64::consts::PI);
assert_eq!(x.to_string(), "3.141592653589793");
x.decrement();
assert_eq!(x.to_string(), "3.14159265358979");
let mut x = Float::power_of_2(100u64);
assert_eq!(x.to_string(), "1.0e30");
x.decrement();
assert_eq!(x.to_string(), "0.0");
let mut x = Float::power_of_2(-100i64);
assert_eq!(x.to_string(), "8.0e-31");
x.decrement();
assert_eq!(x.to_string(), "0.0");
let mut x = Float::NEGATIVE_ONE;
assert_eq!(x.to_string(), "-1.0");
x.decrement();
assert_eq!(x.to_string(), "-2.0");
Source§impl Float
impl Float
Sourcepub fn prime_constant_prec_round(
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn prime_constant_prec_round( prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Returns an approximation to the prime constant, with the given precision and rounded using
the given RoundingMode
. An Ordering
is also returned, indicating whether the rounded
value is less than or greater than the exact value of the constant. (Since the constant is
irrational, the rounded value is never equal to the exact value.)
The prime constant is the real number whose $n$th bit is prime if and only if $n$ is prime. That is, $$ P = \sum_{p\ text{prime}}2^{-p}. $$
The constant is irrational.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or if rm
is Exact
.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let (pc, o) = Float::prime_constant_prec_round(100, Floor);
assert_eq!(pc.to_string(), "0.4146825098511116602481096221542");
assert_eq!(o, Less);
let (pc, o) = Float::prime_constant_prec_round(100, Ceiling);
assert_eq!(pc.to_string(), "0.4146825098511116602481096221546");
assert_eq!(o, Greater);
Sourcepub fn prime_constant_prec(prec: u64) -> (Float, Ordering)
pub fn prime_constant_prec(prec: u64) -> (Float, Ordering)
Returns an approximation to the prime constant, with the given precision and rounded to the
nearest Float
of that precision. An Ordering
is also returned, indicating whether
the rounded value is less than or greater than the exact value of the constant. (Since the
constant is irrational, the rounded value is never equal to the exact value.)
The prime constant is the real number whose $n$th bit is prime if and only if $n$ is prime. That is, $$ P = \sum_{p\ text{prime}}2^{-p}. $$
The constant is irrational.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
let (pc, o) = Float::prime_constant_prec(1);
assert_eq!(pc.to_string(), "0.5");
assert_eq!(o, Greater);
let (pc, o) = Float::prime_constant_prec(10);
assert_eq!(pc.to_string(), "0.4146");
assert_eq!(o, Less);
let (pc, o) = Float::prime_constant_prec(100);
assert_eq!(pc.to_string(), "0.4146825098511116602481096221542");
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn thue_morse_constant_prec_round(
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn thue_morse_constant_prec_round( prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Returns an approximation to the Thue-Morse constant, with the given precision and rounded
using the given RoundingMode
. An Ordering
is also returned, indicating whether the
rounded value is less than or greater than the exact value of the constant. (Since the
constant is irrational, the rounded value is never equal to the exact value.)
The Thue-Morse constant is the real number whose bits are the Thue-Morse sequence. That is, $$ \tau = \sum_{k=0}^\infty\frac{t_n}{2^{n+1}}, $$ where $t_n$ is the Thue-Morse sequence.
An alternative expression, from https://mathworld.wolfram.com/Thue-MorseConstant.html, is $$ \tau = \frac{1}{4}\left[2-\prod_{k=0}^\infty\left(1-\frac{1}{2^{2^k}}\right)\right]. $$
The constant is irrational and transcendental.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or if rm
is Exact
.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
let (tmc, o) = Float::thue_morse_constant_prec_round(100, Floor);
assert_eq!(tmc.to_string(), "0.4124540336401075977833613682584");
assert_eq!(o, Less);
let (tmc, o) = Float::thue_morse_constant_prec_round(100, Ceiling);
assert_eq!(tmc.to_string(), "0.4124540336401075977833613682588");
assert_eq!(o, Greater);
Sourcepub fn thue_morse_constant_prec(prec: u64) -> (Float, Ordering)
pub fn thue_morse_constant_prec(prec: u64) -> (Float, Ordering)
Returns an approximation to the Thue-Morse constant, with the given precision and rounded to
the nearest Float
of that precision. An Ordering
is also returned, indicating
whether the rounded value is less than or greater than the exact value of the constant.
(Since the constant is irrational, the rounded value is never equal to the exact value.)
The Thue-Morse constant is the real number whose bits are the Thue-Morse sequence. That is, $$ \tau = \sum_{k=0}^\infty\frac{t_n}{2^{n+1}}, $$ where $t_n$ is the Thue-Morse sequence.
An alternative expression, from https://mathworld.wolfram.com/Thue-MorseConstant.html, is $$ \tau = \frac{1}{4}\left[2-\prod_{k=0}^\infty\left(1-\frac{1}{2^{2^k}}\right)\right]. $$
The constant is irrational and transcendental.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
let (tmc, o) = Float::thue_morse_constant_prec(1);
assert_eq!(tmc.to_string(), "0.5");
assert_eq!(o, Greater);
let (tmc, o) = Float::thue_morse_constant_prec(10);
assert_eq!(tmc.to_string(), "0.4126");
assert_eq!(o, Greater);
let (tmc, o) = Float::thue_morse_constant_prec(100);
assert_eq!(tmc.to_string(), "0.4124540336401075977833613682584");
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn non_dyadic_from_bits_prec_round<I: Iterator<Item = bool>>(
bits: I,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn non_dyadic_from_bits_prec_round<I: Iterator<Item = bool>>( bits: I, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Returns an approximation of a real number, given the number’s bits. To avoid troublesome
edge cases, the number should not be a dyadic rational (and the iterator of bits should
therefore be infinite, and not eventually 0 or 1). Given this assumption, the rounding mode
Exact
should never be passed.
The approximation has precision prec
and is rounded according to the provided rounding
mode.
This function reads prec + z
bits, or prec + z + 1
bits if rm
is Nearest
, where z
is the number of leading false bits in bits
.
This function always produces a value in the interval $[1/2,1]$. In particular, it never overflows or underflows.
$$ f((x_k),p,m) = C+\varepsilon, $$ where $$ C=\sum_{k=0}^\infty x_k 2^{-(k+1)}. $$
- If $m$ is not
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 C\rfloor-p+1}$. - If $m$ is
Nearest
, then $|\varepsilon| < 2^{\lfloor\log_2 C\rfloor-p}$.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero or rm
is Exact
.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use std::cmp::Ordering::*;
// Produces 10100100010000100000...
struct Bits {
b: bool,
k: usize,
j: usize,
}
impl Iterator for Bits {
type Item = bool;
fn next(&mut self) -> Option<bool> {
Some(if self.b {
self.b = false;
self.j = self.k;
true
} else {
self.j -= 1;
if self.j == 0 {
self.k += 1;
self.b = true;
}
false
})
}
}
impl Bits {
fn new() -> Bits {
Bits {
b: true,
k: 1,
j: 1,
}
}
}
let (c, o) = Float::non_dyadic_from_bits_prec_round(Bits::new(), 100, Floor);
assert_eq!(c.to_string(), "0.6416325606551538662938427702254");
assert_eq!(o, Less);
let (c, o) = Float::non_dyadic_from_bits_prec_round(Bits::new(), 100, Ceiling);
assert_eq!(c.to_string(), "0.641632560655153866293842770226");
assert_eq!(o, Greater);
Sourcepub fn non_dyadic_from_bits_prec<I: Iterator<Item = bool>>(
bits: I,
prec: u64,
) -> (Float, Ordering)
pub fn non_dyadic_from_bits_prec<I: Iterator<Item = bool>>( bits: I, prec: u64, ) -> (Float, Ordering)
Returns an approximation of a real number, given the number’s bits. To avoid troublesome edge cases, the number should not be a dyadic rational (and the iterator of bits should therefore be infinite, and not eventually 0 or 1).
The approximation has precision prec
and is rounded according to the Nearest
rounding
mode.
This function reads prec + z + 1
bits, where z
is the number of leading false bits in
bits
.
This function always produces a value in the interval $[1/2,1]$. In particular, it never overflows or underflows.
$$ f((x_k),p,m) = C+\varepsilon, $$ where $$ C=\sum_{k=0}^\infty x_k 2^{-(k+1)} $$ and $|\varepsilon| < 2^{\lfloor\log_2 C\rfloor-p}$.
The output has precision prec
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_float::Float;
use std::cmp::Ordering::*;
// Produces 10100100010000100000...
struct Bits {
b: bool,
k: usize,
j: usize,
}
impl Iterator for Bits {
type Item = bool;
fn next(&mut self) -> Option<bool> {
Some(if self.b {
self.b = false;
self.j = self.k;
true
} else {
self.j -= 1;
if self.j == 0 {
self.k += 1;
self.b = true;
}
false
})
}
}
impl Bits {
fn new() -> Bits {
Bits {
b: true,
k: 1,
j: 1,
}
}
}
let (c, o) = Float::non_dyadic_from_bits_prec(Bits::new(), 1);
assert_eq!(c.to_string(), "0.5");
assert_eq!(o, Less);
let (c, o) = Float::non_dyadic_from_bits_prec(Bits::new(), 10);
assert_eq!(c.to_string(), "0.642");
assert_eq!(o, Less);
let (c, o) = Float::non_dyadic_from_bits_prec(Bits::new(), 100);
assert_eq!(c.to_string(), "0.6416325606551538662938427702254");
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn from_integer_prec_round(
x: Integer,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_integer_prec_round( x: Integer, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts an Integer
to a Float
, taking the Integer
by value. If the Float
is
nonzero, it has the specified precision. If rounding is needed, the specified rounding mode
is used. An Ordering
is also returned, indicating whether the returned value is less
than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_integer_prec
instead.
- If the
Integer
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Integer
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds up to $-(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Integer
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;
let (x, o) = Float::from_integer_prec_round(Integer::ZERO, 10, Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round(Integer::from(123), 20, Exact);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round(Integer::from(123), 4, Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec_round(Integer::from(123), 4, Ceiling);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
let (x, o) = Float::from_integer_prec_round(Integer::from(-123), 20, Exact);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round(Integer::from(-123), 4, Floor);
assert_eq!(x.to_string(), "-1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec_round(Integer::from(-123), 4, Ceiling);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Sourcepub fn from_integer_prec_round_ref(
x: &Integer,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_integer_prec_round_ref( x: &Integer, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts an Integer
to a Float
, taking the Integer
by reference. If the
Float
is nonzero, it has the specified precision. If rounding is needed, the specified
rounding mode is used. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_integer_prec_ref
instead.
- If the
Integer
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Integer
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds up to $-(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Integer
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;
let (x, o) = Float::from_integer_prec_round_ref(&Integer::ZERO, 10, Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(123), 20, Exact);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(123), 4, Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(123), 4, Ceiling);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(-123), 20, Exact);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(-123), 4, Floor);
assert_eq!(x.to_string(), "-1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec_round_ref(&Integer::from(-123), 4, Ceiling);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Sourcepub fn from_integer_prec(x: Integer, prec: u64) -> (Float, Ordering)
pub fn from_integer_prec(x: Integer, prec: u64) -> (Float, Ordering)
Converts an Integer
to a Float
, taking the Integer
by value. If the Float
is
nonzero, it has the specified precision. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
If you want the Float
’s precision to be equal to the Integer
’s number of significant
bits, try just using Float::try_from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_integer_prec_round
.
- If the
Integer
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$. - If the
Integer
rounds to a value less than or equal to -$2^{2^{30}-1}$), this function overflows to $\infty$.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;
let (x, o) = Float::from_integer_prec(Integer::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec(Integer::from(123), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec(Integer::from(123), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec(Integer::from(-123), 20);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec(Integer::from(-123), 4);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Sourcepub fn from_integer_prec_ref(x: &Integer, prec: u64) -> (Float, Ordering)
pub fn from_integer_prec_ref(x: &Integer, prec: u64) -> (Float, Ordering)
Converts an Integer
to a Float
, taking the Integer
by reference. If the
Float
is nonzero, it has the specified precision. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the original
value.
If you want the Float
’s precision to be equal to the Integer
’s number of significant
bits, try just using Float::try_from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_integer_prec_round_ref
.
- If the
Integer
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$. - If the
Integer
rounds to a value less than or equal to -$2^{2^{30}-1}$), this function overflows to $\infty$.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
use std::cmp::Ordering::*;
let (x, o) = Float::from_integer_prec_ref(&Integer::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_ref(&Integer::from(123), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_ref(&Integer::from(123), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_integer_prec_ref(&Integer::from(-123), 20);
assert_eq!(x.to_string(), "-123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_integer_prec_ref(&Integer::from(-123), 4);
assert_eq!(x.to_string(), "-1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Source§impl Float
impl Float
Sourcepub fn from_natural_prec_round(
x: Natural,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_natural_prec_round( x: Natural, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a Natural
to a Float
, taking the Natural
by value. If the Float
is
nonzero, it has the specified precision. If rounding is needed, the specified rounding mode
is used. An Ordering
is also returned, indicating whether the returned value is less
than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_natural_prec
instead.
- If the
Natural
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Natural
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering::*;
let (x, o) = Float::from_natural_prec_round(Natural::ZERO, 10, Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_round(Natural::from(123u32), 20, Exact);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_round(Natural::from(123u32), 4, Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_natural_prec_round(Natural::from(123u32), 4, Ceiling);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Sourcepub fn from_natural_prec_round_ref(
x: &Natural,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_natural_prec_round_ref( x: &Natural, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a Natural
to a Float
, taking the Natural
by reference. If the Float
is nonzero, it has the specified precision. If rounding is needed, the specified rounding
mode is used. An Ordering
is also returned, indicating whether the returned value is
less than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_natural_prec_ref
instead.
- If the
Natural
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Natural
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering::*;
let (x, o) = Float::from_natural_prec_round_ref(&Natural::ZERO, 10, Exact);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_round_ref(&Natural::from(123u32), 20, Exact);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_round_ref(&Natural::from(123u32), 4, Floor);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
let (x, o) = Float::from_natural_prec_round_ref(&Natural::from(123u32), 4, Ceiling);
assert_eq!(x.to_string(), "1.3e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Greater);
Sourcepub fn from_natural_prec(x: Natural, prec: u64) -> (Float, Ordering)
pub fn from_natural_prec(x: Natural, prec: u64) -> (Float, Ordering)
Converts a Natural
to a Float
, taking the Natural
by value. If the Float
is
nonzero, it has the specified precision. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
If you want the Float
’s precision to be equal to the Natural
’s number of significant
bits, try just using Float::try_from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_natural_prec_round
.
- If the
Natural
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering::*;
let (x, o) = Float::from_natural_prec(Natural::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec(Natural::from(123u32), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec(Natural::from(123u32), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
Sourcepub fn from_natural_prec_ref(x: &Natural, prec: u64) -> (Float, Ordering)
pub fn from_natural_prec_ref(x: &Natural, prec: u64) -> (Float, Ordering)
Converts a Natural
to a Float
, taking the Natural
by reference. If the Float
is nonzero, it has the specified precision. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
If you want the Float
’s precision to be equal to the Natural
’s number of significant
bits, try just using Float::try_from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_natural_prec_round_ref
.
- If the
Natural
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$.
§Worst-case complexity
$T(m,n) = O(\max(m,n))$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $m$ is n.significant_bits()
, and $n$ is
prec
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use std::cmp::Ordering::*;
let (x, o) = Float::from_natural_prec_ref(&Natural::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_ref(&Natural::from(123u32), 20);
assert_eq!(x.to_string(), "123.0");
assert_eq!(x.get_prec(), Some(20));
assert_eq!(o, Equal);
let (x, o) = Float::from_natural_prec_ref(&Natural::from(123u32), 4);
assert_eq!(x.to_string(), "1.2e2");
assert_eq!(x.get_prec(), Some(4));
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn from_primitive_float_prec_round<T: PrimitiveFloat>(
x: T,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_primitive_float_prec_round<T: PrimitiveFloat>( x: T, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a primitive float to a Float
. If the Float
is nonzero and finite, it has
the specified precision. If rounding is needed, the specified rounding mode is used. An
Ordering
is also returned, indicating whether the returned value is less than, equal to,
or greater than the original value. (Although a NaN is not comparable to any Float
,
converting a NaN to a NaN will also return Equal
, indicating an exact conversion.)
If you’re only using Nearest
, try using Float::from_primitive_float_prec
instead.
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 max(prec, x.sci_exponent().abs())
.
§Panics
Panics if prec
is zero, or if rm
is exact and the primitive float cannot be exactly
represented with the specified precision.
§Examples
See here.
Sourcepub fn from_primitive_float_prec<T: PrimitiveFloat>(
x: T,
prec: u64,
) -> (Float, Ordering)
pub fn from_primitive_float_prec<T: PrimitiveFloat>( x: T, prec: u64, ) -> (Float, Ordering)
Converts a primitive float to a Float
. If the Float
is nonzero and finite, it has
the specified precision. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value. (Although a NaN is not
comparable to any Float
, converting a NaN to a NaN will also return Equal
, indicating
an exact conversion.)
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_primitive_float_prec_round
.
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 max(prec, x.sci_exponent().abs())
.
§Panics
Panics if prec
is zero.
§Examples
See here.
Source§impl Float
impl Float
Sourcepub const fn const_from_unsigned_times_power_of_2(x: Limb, pow: i32) -> Float
pub const fn const_from_unsigned_times_power_of_2(x: Limb, pow: i32) -> Float
Converts an unsigned primitive integer to a Float
, after multiplying it by the specified
power of 2.
The type of the integer is u64
, unless the 32_bit_limbs
feature is set, in which case
the type is u32
.
If the integer is nonzero, the precision of the Float
is the minimum possible precision
to represent the integer exactly.
If you don’t need to use this function in a const context, try just using from
instead,
followed by >>
or <<
.
$$ f(x,k) = x2^k. $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result is too large or too small to be represented by a Float
.
§Examples
use malachite_float::Float;
assert_eq!(
Float::const_from_unsigned_times_power_of_2(0, 0).to_string(),
"0.0"
);
assert_eq!(
Float::const_from_unsigned_times_power_of_2(123, 0).to_string(),
"123.0"
);
assert_eq!(
Float::const_from_unsigned_times_power_of_2(123, 1).to_string(),
"246.0"
);
assert_eq!(
Float::const_from_unsigned_times_power_of_2(123, -1).to_string(),
"61.5"
);
#[cfg(not(feature = "32_bit_limbs"))]
{
assert_eq!(
Float::const_from_unsigned_times_power_of_2(884279719003555, -48).to_string(),
"3.141592653589793"
);
}
Sourcepub const fn const_from_unsigned(x: Limb) -> Float
pub const fn const_from_unsigned(x: Limb) -> Float
Converts an unsigned primitive integer to a Float
.
The type of the integer is u64
, unless the 32_bit_limbs
feature is set, in which case
the type is u32
.
If the integer is nonzero, the precision of the Float
is the minimum possible precision
to represent the integer exactly.
If you don’t need to use this function in a const context, try just using from
instead; it
will probably be slightly faster.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_float::Float;
assert_eq!(Float::const_from_unsigned(0).to_string(), "0.0");
assert_eq!(Float::const_from_unsigned(123).to_string(), "123.0");
Sourcepub const fn const_from_signed_times_power_of_2(
x: SignedLimb,
pow: i32,
) -> Float
pub const fn const_from_signed_times_power_of_2( x: SignedLimb, pow: i32, ) -> Float
Converts a signed primitive integer to a Float
, after multiplying it by the specified
power of 2.
The type of the integer is i64
, unless the 32_bit_limbs
feature is set, in which case
the type is i32
.
If the integer is nonzero, the precision of the Float
is the minimum possible precision
to represent the integer exactly.
If you don’t need to use this function in a const context, try just using from
instead,
followed by >>
or <<
.
$$ f(x,k) = x2^k. $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result is too large or too small to be represented by a Float
.
§Examples
use malachite_float::Float;
assert_eq!(
Float::const_from_signed_times_power_of_2(0, 0).to_string(),
"0.0"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(123, 0).to_string(),
"123.0"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(123, 1).to_string(),
"246.0"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(123, -1).to_string(),
"61.5"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(-123, 0).to_string(),
"-123.0"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(-123, 1).to_string(),
"-246.0"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(-123, -1).to_string(),
"-61.5"
);
#[cfg(not(feature = "32_bit_limbs"))]
{
assert_eq!(
Float::const_from_signed_times_power_of_2(884279719003555, -48).to_string(),
"3.141592653589793"
);
assert_eq!(
Float::const_from_signed_times_power_of_2(-884279719003555, -48).to_string(),
"-3.141592653589793"
);
}
Sourcepub const fn const_from_signed(x: SignedLimb) -> Float
pub const fn const_from_signed(x: SignedLimb) -> Float
Converts a signed primitive integer to a Float
.
The type of the integer is i64
, unless the 32_bit_limbs
feature is set, in which case
the type is i32
.
If the integer is nonzero, the precision of the Float
is the minimum possible precision
to represent the integer exactly.
If you don’t need to use this function in a const context, try just using from
instead; it
will probably be slightly faster.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_float::Float;
assert_eq!(Float::const_from_signed(0).to_string(), "0.0");
assert_eq!(Float::const_from_signed(123).to_string(), "123.0");
assert_eq!(Float::const_from_signed(-123).to_string(), "-123.0");
Sourcepub fn from_unsigned_prec_round<T: PrimitiveUnsigned>(
x: T,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_unsigned_prec_round<T: PrimitiveUnsigned>( x: T, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a primitive unsigned integer to a Float
. If the Float
is nonzero, it has
the specified precision. If rounding is needed, the specified rounding mode is used. An
Ordering
is also returned, indicating whether the returned value is less than, equal to,
or greater than the original value.
If you’re only using Nearest
, try using Float::from_unsigned_prec
instead.
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 prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the primitive integer cannot be exactly
represented with the specified precision.
§Examples
See here.
Sourcepub fn from_unsigned_prec<T: PrimitiveUnsigned>(
x: T,
prec: u64,
) -> (Float, Ordering)
pub fn from_unsigned_prec<T: PrimitiveUnsigned>( x: T, prec: u64, ) -> (Float, Ordering)
Converts an unsigned primitive integer to a Float
. If the Float
is nonzero, it has
the specified precision. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
If you want the Float
’s precision to be equal to the integer’s number of significant
bits, try just using Float::from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_unsigned_prec_round
.
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 prec
.
§Panics
Panics if prec
is zero.
§Examples
See here.
Sourcepub fn from_signed_prec_round<T: PrimitiveSigned>(
x: T,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_signed_prec_round<T: PrimitiveSigned>( x: T, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a primitive signed integer to a Float
. If the Float
is nonzero, it has the
specified precision. If rounding is needed, the specified rounding mode is used. An
Ordering
is also returned, indicating whether the returned value is less than, equal to,
or greater than the original value.
If you’re only using Nearest
, try using Float::from_signed_prec
instead.
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 prec
.
§Panics
Panics if prec
is zero, or if rm
is exact and the primitive integer cannot be exactly
represented with the specified precision.
§Examples
See here.
Sourcepub fn from_signed_prec<T: PrimitiveSigned>(
x: T,
prec: u64,
) -> (Float, Ordering)
pub fn from_signed_prec<T: PrimitiveSigned>( x: T, prec: u64, ) -> (Float, Ordering)
Converts a signed primitive integer to a Float
. If the Float
is nonzero, it has the
specified precision. An Ordering
is also returned, indicating whether the returned value
is less than, equal to, or greater than the original value.
If you want the Float
’s precision to be equal to the integer’s number of significant
bits, try just using Float::from
instead.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_signed_prec_round
.
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 prec
.
§Panics
Panics if prec
is zero.
§Examples
See here.
Source§impl Float
impl Float
Sourcepub fn from_rational_prec_round(
x: Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_rational_prec_round( x: Rational, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a Rational
to a Float
, taking the Rational
by value. If the Float
is nonzero, it has the specified precision. If rounding is needed, the specified rounding
mode is used. An Ordering
is also returned, indicating whether the returned value is
less than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_rational_prec
instead.
- If the
Rational
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Rational
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$ ifrm
isFloor
,Up
, orNearest
, and rounds up to $-(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Rational
rounds to a positive value less than $2^{-2^{30}}$), this function underflows to positive zero ifrm
isFloor
orDown
, rounds up to $2^{-2^{30}}$ ifrm
isCeiling
orUp
, underflows to positive zero ifrm
isNearest
and theRational
rounds to a value less than or equal to $2^{-2^{30}-1}$, and rounds up to $2^{-2^{30}}$ ifrm
isNearest
and theRational
rounds to a value greater than $2^{-2^{30}-1}$. - If the
Rational
rounds to a negative value greater than $-2^{-2^{30}}$), this function underflows to negative zero ifrm
isCeiling
orDown
, rounds down to $-2^{-2^{30}}$ ifrm
isFloor
orUp
, underflows to negative zero ifrm
isNearest
and theRational
rounds to a value greater than or equal to $-2^{-2^{30}-1}$, and rounds down to $-2^{-2^{30}}$ ifrm
isNearest
and theRational
rounds to a value less than $-2^{-2^{30}-1}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(n.significant_bits(), prec)
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Rational
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(1, 3), 10, Floor);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(1, 3), 10, Ceiling);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(1, 3), 10, Nearest);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(-1, 3), 10, Floor);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(-1, 3), 10, Ceiling);
assert_eq!(x.to_string(), "-0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_round(Rational::from_signeds(-1, 3), 10, Nearest);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
Sourcepub fn from_rational_prec(x: Rational, prec: u64) -> (Float, Ordering)
pub fn from_rational_prec(x: Rational, prec: u64) -> (Float, Ordering)
Converts a Rational
to a Float
, taking the Rational
by value. If the Float
is nonzero, it has the specified precision. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
If the Rational
is dyadic (its denominator is a power of 2), then you can convert it to
a Float
using try_from
instead. The precision of the resulting Float
will be the
number of significant bits of the Rational
’s numerator.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_rational_prec_round
.
- If the
Rational
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$. - If the
Rational
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$. - If the
Rational
rounds to a positive value less than $2^{-2^{30}}$), this function underflows to positive zero if theRational
rounds to a value less than or equal to $2^{-2^{30}-1}$ and rounds up to $2^{-2^{30}}$ if theRational
rounds to a value greater than $2^{-2^{30}-1}$. - If the
Rational
rounds to a negative value greater than $2^{-2^{30}}$), this function underflows to negative zero if theRational
rounds to a value greater than or equal to $-2^{-2^{30}-1}$ and rounds down to $-2^{-2^{30}}$ if theRational
rounds to a value less than $-2^{-2^{30}-1}$.
§Panics
Panics if prec
is zero.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), prec)
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (x, o) = Float::from_rational_prec(Rational::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_rational_prec(Rational::from_signeds(1, 3), 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec(Rational::from_signeds(1, 3), 100);
assert_eq!(x.to_string(), "0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec(Rational::from_signeds(-1, 3), 10);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_rational_prec(Rational::from_signeds(-1, 3), 100);
assert_eq!(x.to_string(), "-0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Less);
Sourcepub fn from_rational_prec_round_ref(
x: &Rational,
prec: u64,
rm: RoundingMode,
) -> (Float, Ordering)
pub fn from_rational_prec_round_ref( x: &Rational, prec: u64, rm: RoundingMode, ) -> (Float, Ordering)
Converts a Rational
to a Float
, taking the Rational
by reference. If the
Float
is nonzero, it has the specified precision. If rounding is needed, the specified
rounding mode is used. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
If you’re only using Nearest
, try using Float::from_rational_prec_ref
instead.
- If the
Rational
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$ ifrm
isCeiling
,Up
, orNearest
, and rounds down to $(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Rational
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$ ifrm
isFloor
,Up
, orNearest
, and rounds up to $-(1-(1/2)^p)2^{2^{30}-1}$ otherwise, where $p$ isprec
. - If the
Rational
rounds to a positive value less than $2^{-2^{30}}$), this function underflows to positive zero ifrm
isFloor
orDown
, rounds up to $2^{-2^{30}}$ ifrm
isCeiling
orUp
, underflows to positive zero ifrm
isNearest
and theRational
rounds to a value less than or equal to $2^{-2^{30}-1}$, and rounds up to $2^{-2^{30}}$ ifrm
isNearest
and theRational
rounds to a value greater than $2^{-2^{30}-1}$. - If the
Rational
rounds to a negative value greater than $-2^{-2^{30}}$), this function underflows to negative zero ifrm
isCeiling
orDown
, rounds down to $-2^{-2^{30}}$ ifrm
isFloor
orUp
, underflows to negative zero ifrm
isNearest
and theRational
rounds to a value greater than or equal to $-2^{-2^{30}-1}$, and rounds down to $-2^{-2^{30}}$ ifrm
isNearest
and theRational
rounds to a value less than $-2^{-2^{30}-1}$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), prec)
.
§Panics
Panics if prec
is zero, or if rm
is exact and the Rational
cannot be exactly
represented with the specified precision.
§Examples
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (x, o) = Float::from_rational_prec_round_ref(&Rational::from_signeds(1, 3), 10, Floor);
assert_eq!(x.to_string(), "0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) =
Float::from_rational_prec_round_ref(&Rational::from_signeds(1, 3), 10, Ceiling);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) =
Float::from_rational_prec_round_ref(&Rational::from_signeds(1, 3), 10, Nearest);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_round_ref(&Rational::from_signeds(-1, 3), 10, Floor);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) =
Float::from_rational_prec_round_ref(&Rational::from_signeds(-1, 3), 10, Ceiling);
assert_eq!(x.to_string(), "-0.333");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) =
Float::from_rational_prec_round_ref(&Rational::from_signeds(-1, 3), 10, Nearest);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
Sourcepub fn from_rational_prec_ref(x: &Rational, prec: u64) -> (Float, Ordering)
pub fn from_rational_prec_ref(x: &Rational, prec: u64) -> (Float, Ordering)
Converts a Rational
to a Float
, taking the Rational
by reference. If the
Float
is nonzero, it has the specified precision. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the original
value.
If the Rational
is dyadic (its denominator is a power of 2), then you can convert it to
a Float
using try_from
instead. The precision of the resulting Float
will be the
number of significant bits of the Rational
’s numerator.
Rounding may occur, in which case Nearest
is used by default. To specify a rounding mode
as well as a precision, try Float::from_rational_prec_round_ref
.
- If the
Rational
rounds to a value greater than or equal to $2^{2^{30}-1}$), this function overflows to $\infty$. - If the
Rational
rounds to a value less than or equal to $-2^{2^{30}-1}$), this function overflows to $-\infty$. - If the
Rational
rounds to a positive value less than $2^{-2^{30}}$), this function underflows to positive zero if theRational
rounds to a value less than or equal to $2^{-2^{30}-1}$ and rounds up to $2^{-2^{30}}$ if theRational
rounds to a value greater than $2^{-2^{30}-1}$. - If the
Rational
rounds to a negative value greater than $2^{-2^{30}}$), this function underflows to negative zero if theRational
rounds to a value greater than or equal to $-2^{-2^{30}-1}$ and rounds down to $-2^{-2^{30}}$ if theRational
rounds to a value less than $-2^{-2^{30}-1}$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(x.significant_bits(), prec)
.
§Panics
Panics if prec
is zero.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::Rational;
use std::cmp::Ordering::*;
let (x, o) = Float::from_rational_prec_ref(&Rational::ZERO, 10);
assert_eq!(x.to_string(), "0.0");
assert_eq!(o, Equal);
let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(1, 3), 10);
assert_eq!(x.to_string(), "0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(1, 3), 100);
assert_eq!(x.to_string(), "0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Greater);
let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(-1, 3), 10);
assert_eq!(x.to_string(), "-0.3335");
assert_eq!(x.get_prec(), Some(10));
assert_eq!(o, Less);
let (x, o) = Float::from_rational_prec_ref(&Rational::from_signeds(-1, 3), 100);
assert_eq!(x.to_string(), "-0.3333333333333333333333333333335");
assert_eq!(x.get_prec(), Some(100));
assert_eq!(o, Less);
Source§impl Float
impl Float
Sourcepub fn sci_mantissa_and_exponent_round<T: PrimitiveFloat>(
&self,
rm: RoundingMode,
) -> Option<(T, i32, Ordering)>
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§impl Float
impl Float
Sourcepub const MAX_EXPONENT: i32 = 1_073_741_823i32
pub const MAX_EXPONENT: i32 = 1_073_741_823i32
The maximum raw exponent of any Float
, equal to $2^{30}-1$, or $1,073,741,823$. This is
one more than the maximum scientific exponent. If we write a Float
as $\pm m2^e$, with
$1\leq m<2$ and $e$ an integer, we must have $e\leq 2^{30}-2$. If the result of a
calculation would produce a Float
with an exponent larger than this, $\pm\infty$ is
returned instead.
Sourcepub const MIN_EXPONENT: i32 = -1_073_741_823i32
pub const MIN_EXPONENT: i32 = -1_073_741_823i32
The minimum raw exponent of any Float
, equal to $-(2^{30}-1)$, or $-1,073,741,823$. This
is one more than the minimum scientific exponent. If we write a Float
as $\pm m2^e$,
with $1\leq m<2$ and $e$ an integer, we must have $e\geq -2^{30}$. If the result of a
calculation would produce a Float
with an exponent smaller than this, $\pm0.0$ is
returned instead.
Trait Implementations§
Source§impl Abs for &Float
impl Abs for &Float
Source§fn abs(self) -> Float
fn abs(self) -> Float
Takes the absolute value of a Float
, taking the Float
by reference.
$$ f(x) = |x|. $$
Special cases:
- $f(\text{NaN}) = \text{NaN}$
- $f(\infty) = f(-\infty) = \infty$
- $f(0.0) = f(-0.0) = 0.0$
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::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
assert_eq!(
ComparableFloat((&Float::NAN).abs()),
ComparableFloat(Float::NAN)
);
assert_eq!((&Float::INFINITY).abs(), Float::INFINITY);
assert_eq!((&Float::NEGATIVE_INFINITY).abs(), Float::INFINITY);
assert_eq!(
ComparableFloat((&Float::ZERO).abs()),
ComparableFloat(Float::ZERO)
);
assert_eq!(
ComparableFloat((&Float::NEGATIVE_ZERO).abs()),
ComparableFloat(Float::ZERO)
);
assert_eq!((&Float::ONE).abs(), Float::ONE);
assert_eq!((&Float::NEGATIVE_ONE).abs(), Float::ONE);
type Output = Float
Source§impl Abs for Float
impl Abs for Float
Source§fn abs(self) -> Float
fn abs(self) -> Float
Takes the absolute value of a Float
, taking the Float
by value.
$$ f(x) = |x|. $$
Special cases:
- $f(\text{NaN}) = \text{NaN}$
- $f(\infty) = f(-\infty) = \infty$
- $f(0.0) = f(-0.0) = 0.0$
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
assert_eq!(
ComparableFloat(Float::NAN.abs()),
ComparableFloat(Float::NAN)
);
assert_eq!(Float::INFINITY.abs(), Float::INFINITY);
assert_eq!(Float::NEGATIVE_INFINITY.abs(), Float::INFINITY);
assert_eq!(
ComparableFloat(Float::ZERO.abs()),
ComparableFloat(Float::ZERO)
);
assert_eq!(
ComparableFloat(Float::NEGATIVE_ZERO.abs()),
ComparableFloat(Float::ZERO)
);
assert_eq!(Float::ONE.abs(), Float::ONE);
assert_eq!(Float::NEGATIVE_ONE.abs(), Float::ONE);
type Output = Float
Source§impl AbsAssign for Float
impl AbsAssign for Float
Source§fn abs_assign(&mut self)
fn abs_assign(&mut self)
Replaces a Float
with its absolute value.
$$ x \gets |x|. $$
Special cases:
- $\text{NaN} \gets \text{NaN}$
- $\infty \gets \infty$
- $-\infty \gets \infty$
- $0.0 \gets 0.0$
- $-0.0 \gets 0.0$
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::AbsAssign;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
let mut x = Float::NAN;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));
let mut x = Float::INFINITY;
x.abs_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x.abs_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::ZERO;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));
let mut x = Float::NEGATIVE_ZERO;
x.abs_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));
let mut x = Float::ONE;
x.abs_assign();
assert_eq!(x, Float::ONE);
let mut x = Float::NEGATIVE_ONE;
x.abs_assign();
assert_eq!(x, Float::ONE);
Source§impl Add<&Float> for &Float
impl Add<&Float> for &Float
Source§fn add(self, other: &Float) -> Float
fn add(self, other: &Float) -> Float
Adds two Float
s, taking both by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,-\infty)=f(-\infty,\infty)=\text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,0.0)=0.0$
- $f(-0.0,-0.0)=-0.0$
- $f(0.0,-0.0)=f(-0.0,0.0)=0.0$
- $f(0.0,x)=f(x,0.0)=f(-0.0,x)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,-x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_ref
instead. If you want to specify the output precision, consider
using Float::add_round_ref_ref
. If you want both of these things, consider using
Float::add_prec_round_ref_ref
.
§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 malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::from(1.5) + &Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) + &Float::INFINITY, Float::INFINITY);
assert_eq!(
&Float::from(1.5) + &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert!((&Float::INFINITY + &Float::NEGATIVE_INFINITY).is_nan());
assert_eq!(&Float::from(1.5) + &Float::from(2.5), 4.0);
assert_eq!(&Float::from(1.5) + &Float::from(-2.5), -1.0);
assert_eq!(&Float::from(-1.5) + &Float::from(2.5), 1.0);
assert_eq!(&Float::from(-1.5) + &Float::from(-2.5), -4.0);
Source§impl Add<&Float> for &Rational
impl Add<&Float> for &Rational
Source§fn add(self, other: &Float) -> Float
fn add(self, other: &Float) -> Float
Adds a Rational
and a Float
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=\infty$
- $f(x,-\infty)=-\infty$
- $f(0,0.0)=0.0$
- $f(0,-0.0)=-0.0$
- $f(x,0.0)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) + &Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) + &Float::INFINITY,
Float::INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) + &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(&Rational::exact_from(1.5) + &Float::from(2.5), 4.0);
assert_eq!(&Rational::exact_from(1.5) + &Float::from(-2.5), -1.0);
assert_eq!(&Rational::exact_from(-1.5) + &Float::from(2.5), 1.0);
assert_eq!(&Rational::exact_from(-1.5) + &Float::from(-2.5), -4.0);
Source§impl Add<&Float> for Float
impl Add<&Float> for Float
Source§fn add(self, other: &Float) -> Float
fn add(self, other: &Float) -> Float
Adds two Float
s, taking the first by value and the second by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,-\infty)=f(-\infty,\infty)=\text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,0.0)=0.0$
- $f(-0.0,-0.0)=-0.0$
- $f(0.0,-0.0)=f(-0.0,0.0)=0.0$
- $f(0.0,x)=f(x,0.0)=f(-0.0,x)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,-x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_val_ref
instead. If you want to specify the output precision, consider
using Float::add_round_val_ref
. If you want both of these things, consider using
Float::add_prec_round_val_ref
.
§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 other.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((Float::from(1.5) + &Float::NAN).is_nan());
assert_eq!(Float::from(1.5) + &Float::INFINITY, Float::INFINITY);
assert_eq!(
Float::from(1.5) + &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert!((Float::INFINITY + &Float::NEGATIVE_INFINITY).is_nan());
assert_eq!(Float::from(1.5) + &Float::from(2.5), 4.0);
assert_eq!(Float::from(1.5) + &Float::from(-2.5), -1.0);
assert_eq!(Float::from(-1.5) + &Float::from(2.5), 1.0);
assert_eq!(Float::from(-1.5) + &Float::from(-2.5), -4.0);
Source§impl Add<&Float> for Rational
impl Add<&Float> for Rational
Source§fn add(self, other: &Float) -> Float
fn add(self, other: &Float) -> Float
Adds a Rational
and a Float
, taking the Rational
by value and the Float
by
reference.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=\infty$
- $f(x,-\infty)=-\infty$
- $f(0,0.0)=0.0$
- $f(0,-0.0)=-0.0$
- $f(x,0.0)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) + &Float::NAN).is_nan());
assert_eq!(
Rational::exact_from(1.5) + &Float::INFINITY,
Float::INFINITY
);
assert_eq!(
Rational::exact_from(1.5) + &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(Rational::exact_from(1.5) + &Float::from(2.5), 4.0);
assert_eq!(Rational::exact_from(1.5) + &Float::from(-2.5), -1.0);
assert_eq!(Rational::exact_from(-1.5) + &Float::from(2.5), 1.0);
assert_eq!(Rational::exact_from(-1.5) + &Float::from(-2.5), -4.0);
Source§impl Add<&Rational> for &Float
impl Add<&Rational> for &Float
Source§fn add(self, other: &Rational) -> Float
fn add(self, other: &Rational) -> Float
Adds a Float
and a Rational
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(0.0,x)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_ref
instead. If you want to specify the output precision,
consider using Float::add_rational_round_ref_ref
. If you want both of these things,
consider using Float::add_rational_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN + &Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY + &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY + &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(2.5) + &Rational::exact_from(1.5), 4.0);
assert_eq!(&Float::from(2.5) + &Rational::exact_from(-1.5), 1.0);
assert_eq!(&Float::from(-2.5) + &Rational::exact_from(1.5), -1.0);
assert_eq!(&Float::from(-2.5) + &Rational::exact_from(-1.5), -4.0);
Source§impl Add<&Rational> for Float
impl Add<&Rational> for Float
Source§fn add(self, other: &Rational) -> Float
fn add(self, other: &Rational) -> Float
Adds a Float
and a Rational
, taking the Float
by value and the Rational
by
reference.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(0.0,x)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_val_ref
instead. If you want to specify the output precision,
consider using Float::add_rational_round_val_ref
. If you want both of these things,
consider using Float::add_rational_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN + &Rational::exact_from(1.5)).is_nan());
assert_eq!(
Float::INFINITY + &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY + &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(2.5) + &Rational::exact_from(1.5), 4.0);
assert_eq!(Float::from(2.5) + &Rational::exact_from(-1.5), 1.0);
assert_eq!(Float::from(-2.5) + &Rational::exact_from(1.5), -1.0);
assert_eq!(Float::from(-2.5) + &Rational::exact_from(-1.5), -4.0);
Source§impl Add<Float> for &Float
impl Add<Float> for &Float
Source§fn add(self, other: Float) -> Float
fn add(self, other: Float) -> Float
Adds two Float
s, taking the first by reference and the second by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,-\infty)=f(-\infty,\infty)=\text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,0.0)=0.0$
- $f(-0.0,-0.0)=-0.0$
- $f(0.0,-0.0)=f(-0.0,0.0)=0.0$
- $f(0.0,x)=f(x,0.0)=f(-0.0,x)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,-x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_val
instead. If you want to specify the output precision, consider
using Float::add_round_ref_val
. If you want both of these things, consider using
Float::add_prec_round_ref_val
.
§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()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::from(1.5) + Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) + Float::INFINITY, Float::INFINITY);
assert_eq!(
&Float::from(1.5) + Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert!((&Float::INFINITY + Float::NEGATIVE_INFINITY).is_nan());
assert_eq!(&Float::from(1.5) + Float::from(2.5), 4.0);
assert_eq!(&Float::from(1.5) + Float::from(-2.5), -1.0);
assert_eq!(&Float::from(-1.5) + Float::from(2.5), 1.0);
assert_eq!(&Float::from(-1.5) + Float::from(-2.5), -4.0);
Source§impl Add<Float> for &Rational
impl Add<Float> for &Rational
Source§fn add(self, other: Float) -> Float
fn add(self, other: Float) -> Float
Adds a Rational
and a Float
, taking the Rational
by reference and the Float
by value.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=\infty$
- $f(x,-\infty)=-\infty$
- $f(0,0.0)=0.0$
- $f(0,-0.0)=-0.0$
- $f(x,0.0)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) + Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) + Float::INFINITY,
Float::INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) + Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(&Rational::exact_from(1.5) + Float::from(2.5), 4.0);
assert_eq!(&Rational::exact_from(1.5) + Float::from(-2.5), -1.0);
assert_eq!(&Rational::exact_from(-1.5) + Float::from(2.5), 1.0);
assert_eq!(&Rational::exact_from(-1.5) + Float::from(-2.5), -4.0);
Source§impl Add<Float> for Rational
impl Add<Float> for Rational
Source§fn add(self, other: Float) -> Float
fn add(self, other: Float) -> Float
Adds a Rational
and a Float
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=\infty$
- $f(x,-\infty)=-\infty$
- $f(0,0.0)=0.0$
- $f(0,-0.0)=-0.0$
- $f(x,0.0)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) + Float::NAN).is_nan());
assert_eq!(Rational::exact_from(1.5) + Float::INFINITY, Float::INFINITY);
assert_eq!(
Rational::exact_from(1.5) + Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(Rational::exact_from(1.5) + Float::from(2.5), 4.0);
assert_eq!(Rational::exact_from(1.5) + Float::from(-2.5), -1.0);
assert_eq!(Rational::exact_from(-1.5) + Float::from(2.5), 1.0);
assert_eq!(Rational::exact_from(-1.5) + Float::from(-2.5), -4.0);
Source§impl Add<Rational> for &Float
impl Add<Rational> for &Float
Source§fn add(self, other: Rational) -> Float
fn add(self, other: Rational) -> Float
Adds a Float
and a Rational
, taking the Float
by reference and the Rational
by value.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(0.0,x)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_val
instead. If you want to specify the output precision,
consider using Float::add_rational_round_ref_val
. If you want both of these things,
consider using Float::add_rational_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN + Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY + Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY + Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(2.5) + Rational::exact_from(1.5), 4.0);
assert_eq!(&Float::from(2.5) + Rational::exact_from(-1.5), 1.0);
assert_eq!(&Float::from(-2.5) + Rational::exact_from(1.5), -1.0);
assert_eq!(&Float::from(-2.5) + Rational::exact_from(-1.5), -4.0);
Source§impl Add<Rational> for Float
impl Add<Rational> for Float
Source§fn add(self, other: Rational) -> Float
fn add(self, other: Rational) -> Float
Adds a Float
and a Rational
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(0.0,x)=f(x,0)=f(-0.0,x)=x$
- $f(x,-x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider
using Float::add_rational_round
. If you want both of these things, consider using
Float::add_rational_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN + Rational::exact_from(1.5)).is_nan());
assert_eq!(Float::INFINITY + Rational::exact_from(1.5), Float::INFINITY);
assert_eq!(
Float::NEGATIVE_INFINITY + Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(2.5) + Rational::exact_from(1.5), 4.0);
assert_eq!(Float::from(2.5) + Rational::exact_from(-1.5), 1.0);
assert_eq!(Float::from(-2.5) + Rational::exact_from(1.5), -1.0);
assert_eq!(Float::from(-2.5) + Rational::exact_from(-1.5), -4.0);
Source§impl Add for Float
impl Add for Float
Source§fn add(self, other: Float) -> Float
fn add(self, other: Float) -> Float
Adds two Float
s, taking both by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,-\infty)=f(-\infty,\infty)=\text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,0.0)=0.0$
- $f(-0.0,-0.0)=-0.0$
- $f(0.0,-0.0)=f(-0.0,0.0)=0.0$
- $f(0.0,x)=f(x,0.0)=f(-0.0,x)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,-x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider using Float::add_round
.
If you want both of these things, consider using Float::add_prec_round
.
§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};
use malachite_float::Float;
assert!((Float::from(1.5) + Float::NAN).is_nan());
assert_eq!(Float::from(1.5) + Float::INFINITY, Float::INFINITY);
assert_eq!(
Float::from(1.5) + Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert!((Float::INFINITY + Float::NEGATIVE_INFINITY).is_nan());
assert_eq!(Float::from(1.5) + Float::from(2.5), 4.0);
assert_eq!(Float::from(1.5) + Float::from(-2.5), -1.0);
assert_eq!(Float::from(-1.5) + Float::from(2.5), 1.0);
assert_eq!(Float::from(-1.5) + Float::from(-2.5), -4.0);
Source§impl AddAssign<&Float> for Float
impl AddAssign<&Float> for Float
Source§fn add_assign(&mut self, other: &Float)
fn add_assign(&mut self, other: &Float)
Adds a Float
to a Float
in place, taking the Float
on the right-hand side by
reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the +
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_prec_assign_ref
instead. If you want to specify the output precision,
consider using Float::add_round_assign_ref
. If you want both of these things, consider
using Float::add_prec_round_assign_ref
.
§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 other.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
let mut x = Float::from(1.5);
x += &Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x += &Float::INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x += &Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x += &Float::NEGATIVE_INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x += &Float::from(2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(1.5);
x += &Float::from(-2.5);
assert_eq!(x, -1.0);
let mut x = Float::from(-1.5);
x += &Float::from(2.5);
assert_eq!(x, 1.0);
let mut x = Float::from(-1.5);
x += &Float::from(-2.5);
assert_eq!(x, -4.0);
Source§impl AddAssign<&Rational> for Float
impl AddAssign<&Rational> for Float
Source§fn add_assign(&mut self, other: &Rational)
fn add_assign(&mut self, other: &Rational)
Adds a Rational
to a Float
in place, taking the Rational
by reference.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the +
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_rational_prec_assign
instead. If you want to specify the output precision,
consider using Float::add_rational_round_assign
. If you want both of these things,
consider using Float::add_rational_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x += &Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x += &Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x += &Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(2.5);
x += &Rational::exact_from(1.5);
assert_eq!(x, 4.0);
let mut x = Float::from(2.5);
x += &Rational::exact_from(-1.5);
assert_eq!(x, 1.0);
let mut x = Float::from(-2.5);
x += &Rational::exact_from(1.5);
assert_eq!(x, -1.0);
let mut x = Float::from(-2.5);
x += &Rational::exact_from(-1.5);
assert_eq!(x, -4.0);
Source§impl AddAssign<Rational> for Float
impl AddAssign<Rational> for Float
Source§fn add_assign(&mut self, other: Rational)
fn add_assign(&mut self, other: Rational)
Adds a Rational
to a Float
in place, taking the Rational
by value.
If the output has a precision, it is the precision of the input Float
. If the sum is
equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the +
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_rational_prec_assign
instead. If you want to specify the output precision,
consider using Float::add_rational_round_assign
. If you want both of these things,
consider using Float::add_rational_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x += Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x += Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x += Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(2.5);
x += Rational::exact_from(1.5);
assert_eq!(x, 4.0);
let mut x = Float::from(2.5);
x += Rational::exact_from(-1.5);
assert_eq!(x, 1.0);
let mut x = Float::from(-2.5);
x += Rational::exact_from(1.5);
assert_eq!(x, -1.0);
let mut x = Float::from(-2.5);
x += Rational::exact_from(-1.5);
assert_eq!(x, -4.0);
Source§impl AddAssign for Float
impl AddAssign for Float
Source§fn add_assign(&mut self, other: Float)
fn add_assign(&mut self, other: Float)
Adds a Float
to a Float
in place, taking the Float
on the right-hand side by
value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the sum
is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the +
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::add_prec_assign
instead. If you want to specify the output precision, consider
using Float::add_round_assign
. If you want both of these things, consider using
Float::add_prec_round_assign
.
§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};
use malachite_float::Float;
let mut x = Float::from(1.5);
x += Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x += Float::INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x += Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x += Float::NEGATIVE_INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x += Float::from(2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(1.5);
x += Float::from(-2.5);
assert_eq!(x, -1.0);
let mut x = Float::from(-1.5);
x += Float::from(2.5);
assert_eq!(x, 1.0);
let mut x = Float::from(-1.5);
x += Float::from(-2.5);
assert_eq!(x, -4.0);
Source§impl ConvertibleFrom<&Float> for Integer
impl ConvertibleFrom<&Float> for Integer
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an Integer
, taking the Float
by
reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Integer::convertible_from(&Float::ZERO), true);
assert_eq!(Integer::convertible_from(&Float::from(123.0)), true);
assert_eq!(Integer::convertible_from(&Float::from(-123.0)), true);
assert_eq!(Integer::convertible_from(&Float::from(1.5)), false);
assert_eq!(Integer::convertible_from(&Float::INFINITY), false);
assert_eq!(Integer::convertible_from(&Float::NAN), false);
Source§impl ConvertibleFrom<&Float> for Natural
impl ConvertibleFrom<&Float> for Natural
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to a Natural
(when the Float
is
non-negative and an integer), taking the Float
by reference.
Both positive and negative zero are convertible to a Natural
. (Although negative zero is
nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Natural::convertible_from(&Float::ZERO), true);
assert_eq!(Natural::convertible_from(&Float::from(123.0)), true);
assert_eq!(Natural::convertible_from(&Float::from(-123.0)), false);
assert_eq!(Natural::convertible_from(&Float::from(1.5)), false);
assert_eq!(Natural::convertible_from(&Float::INFINITY), false);
assert_eq!(Natural::convertible_from(&Float::NAN), false);
Source§impl ConvertibleFrom<&Float> for Rational
impl ConvertibleFrom<&Float> for Rational
Source§fn convertible_from(x: &Float) -> bool
fn convertible_from(x: &Float) -> bool
Determines whether a Float
can be converted to a Rational
(which is when the
Float
is finite), taking the Float
by reference.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert_eq!(Rational::convertible_from(&Float::ZERO), true);
assert_eq!(Rational::convertible_from(&Float::from(123.0)), true);
assert_eq!(Rational::convertible_from(&Float::from(-123.0)), true);
assert_eq!(Rational::convertible_from(&Float::from(1.5)), true);
assert_eq!(Rational::convertible_from(&Float::INFINITY), false);
assert_eq!(Rational::convertible_from(&Float::NAN), false);
Source§impl ConvertibleFrom<&Float> for f32
impl ConvertibleFrom<&Float> for f32
Source§impl ConvertibleFrom<&Float> for f64
impl ConvertibleFrom<&Float> for f64
Source§impl ConvertibleFrom<&Float> for i128
impl ConvertibleFrom<&Float> for i128
Source§impl ConvertibleFrom<&Float> for i16
impl ConvertibleFrom<&Float> for i16
Source§impl ConvertibleFrom<&Float> for i32
impl ConvertibleFrom<&Float> for i32
Source§impl ConvertibleFrom<&Float> for i64
impl ConvertibleFrom<&Float> for i64
Source§impl ConvertibleFrom<&Float> for i8
impl ConvertibleFrom<&Float> for i8
Source§impl ConvertibleFrom<&Float> for isize
impl ConvertibleFrom<&Float> for isize
Source§impl ConvertibleFrom<&Float> for u128
impl ConvertibleFrom<&Float> for u128
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Float> for u16
impl ConvertibleFrom<&Float> for u16
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Float> for u32
impl ConvertibleFrom<&Float> for u32
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Float> for u64
impl ConvertibleFrom<&Float> for u64
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Float> for u8
impl ConvertibleFrom<&Float> for u8
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Float> for usize
impl ConvertibleFrom<&Float> for usize
Source§fn convertible_from(f: &Float) -> bool
fn convertible_from(f: &Float) -> bool
Determines whether a Float
can be converted to an unsigned primitive integer,
taking the Float
by reference.
Both positive and negative zero are convertible to any unsigned primitive integer. (Although negative zero is nominally negative, the real number it represents is zero, which is not negative.)
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl ConvertibleFrom<&Integer> for Float
impl ConvertibleFrom<&Integer> for Float
Source§fn convertible_from(x: &Integer) -> bool
fn convertible_from(x: &Integer) -> bool
Determines whether an Integer
can be converted to an Float
, taking the Integer
by reference.
The Integer
s that are convertible to Float
s are those whose that would not overflow:
that is, those whose absolute values are less than $2^{2^{30}-1}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Float::convertible_from(&Integer::ZERO), true);
assert_eq!(Float::convertible_from(&Integer::from(3u8)), true);
Source§impl ConvertibleFrom<&Natural> for Float
impl ConvertibleFrom<&Natural> for Float
Source§fn convertible_from(x: &Natural) -> bool
fn convertible_from(x: &Natural) -> bool
Determines whether a Natural
can be converted to an Float
, taking the Natural
by
reference.
The Natural
s that are convertible to Float
s are those whose that would not overflow:
that is, those that are less than $2^{2^{30}-1}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Float::convertible_from(&Natural::ZERO), true);
assert_eq!(Float::convertible_from(&Natural::from(3u8)), true);
Source§impl ConvertibleFrom<&Rational> for Float
impl ConvertibleFrom<&Rational> for Float
Source§fn convertible_from(x: &Rational) -> bool
fn convertible_from(x: &Rational) -> bool
Determines whether a Rational
can be converted to an Float
, taking the Rational
by reference.
The Rational
s that are convertible to Float
s are precisely those whose denominators
are powers of two, and would not overflow or underflow.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert_eq!(Float::convertible_from(&Rational::ZERO), true);
assert_eq!(Float::convertible_from(&Rational::from_signeds(3, 8)), true);
assert_eq!(
Float::convertible_from(&Rational::from_signeds(-3, 8)),
true
);
assert_eq!(
Float::convertible_from(&Rational::from_signeds(1, 3)),
false
);
assert_eq!(
Float::convertible_from(&Rational::from_signeds(-1, 3)),
false
);
Source§impl Div<&Float> for &Float
impl Div<&Float> for &Float
Source§fn div(self, other: &Float) -> Float
fn div(self, other: &Float) -> Float
Divides two Float
s, taking both by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm\infty)=f(\pm0.0,\pm0.0) = \text{NaN}$
- $f(\infty,x)=\infty$ if $0.0<x<\infty$
- $f(\infty,x)=-\infty$ if $-\infty<x<0.0$
- $f(x,0.0)=\infty$ if $x>0.0$
- $f(x,0.0)=-\infty$ if $x<0.0$
- $f(-\infty,x)=-\infty$ if $0.0<x<\infty$
- $f(-\infty,x)=\infty$ if $-\infty<x<0.0$
- $f(x,-0.0)=-\infty$ if $x>0.0$
- $f(x,-0.0)=\infty$ if $x<0.0$
- $f(0.0,x)=0.0$ if $x$ is not NaN and $x>0.0$
- $f(0.0,x)=-0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=-0.0$ if $x$ is not NaN and $x>0.0$
- $f(-0.0,x)=0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,-\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,-\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_ref_ref
instead. If you want to specify the output precision, consider
using Float::div_round_ref_ref
. If you want both of these things, consider using
Float::div_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
assert!((&Float::from(1.5) / &Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) / &Float::ZERO, Float::INFINITY);
assert_eq!(
&Float::from(1.5) / &Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(-1.5) / &Float::ZERO, Float::NEGATIVE_INFINITY);
assert_eq!(&Float::from(-1.5) / &Float::NEGATIVE_ZERO, Float::INFINITY);
assert!((&Float::ZERO / &Float::ZERO).is_nan());
assert_eq!((&Float::from(1.5) / &Float::from(2.5)).to_string(), "0.6");
assert_eq!((&Float::from(1.5) / &Float::from(-2.5)).to_string(), "-0.6");
assert_eq!((&Float::from(-1.5) / &Float::from(2.5)).to_string(), "-0.6");
assert_eq!((&Float::from(-1.5) / &Float::from(-2.5)).to_string(), "0.6");
Source§impl Div<&Float> for &Rational
impl Div<&Float> for &Rational
Source§fn div(self, other: &Float) -> Float
fn div(self, other: &Float) -> Float
Divides a Rational
by a Float
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) / &Float::NAN).is_nan());
assert_eq!(&Rational::exact_from(1.5) / &Float::ZERO, Float::INFINITY);
assert_eq!(
&Rational::exact_from(1.5) / &Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) / &Float::ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) / &Float::NEGATIVE_ZERO,
Float::INFINITY
);
assert_eq!(
(&Rational::exact_from(1.5) / &Float::from(2.5)).to_string(),
"0.6"
);
assert_eq!(
(&Rational::exact_from(-1.5) / &Float::from(2.5)).to_string(),
"-0.6"
);
assert_eq!(
(&Rational::exact_from(1.5) / &Float::from(-2.5)).to_string(),
"-0.6"
);
assert_eq!(
(&Rational::exact_from(-1.5) / &Float::from(-2.5)).to_string(),
"0.6"
);
Source§impl Div<&Float> for Float
impl Div<&Float> for Float
Source§fn div(self, other: &Float) -> Float
fn div(self, other: &Float) -> Float
Divides two Float
s, taking the first by value and the second by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm\infty)=f(\pm0.0,\pm0.0) = \text{NaN}$
- $f(\infty,x)=\infty$ if $0.0<x<\infty$
- $f(\infty,x)=-\infty$ if $-\infty<x<0.0$
- $f(x,0.0)=\infty$ if $x>0.0$
- $f(x,0.0)=-\infty$ if $x<0.0$
- $f(-\infty,x)=-\infty$ if $0.0<x<\infty$
- $f(-\infty,x)=\infty$ if $-\infty<x<0.0$
- $f(x,-0.0)=-\infty$ if $x>0.0$
- $f(x,-0.0)=\infty$ if $x<0.0$
- $f(0.0,x)=0.0$ if $x$ is not NaN and $x>0.0$
- $f(0.0,x)=-0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=-0.0$ if $x$ is not NaN and $x>0.0$
- $f(-0.0,x)=0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,-\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,-\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_val_ref
instead. If you want to specify the output precision, consider
using Float::div_round_val_ref
. If you want both of these things, consider using
Float::div_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
assert!((Float::from(1.5) / &Float::NAN).is_nan());
assert_eq!(Float::from(1.5) / &Float::ZERO, Float::INFINITY);
assert_eq!(
Float::from(1.5) / &Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(-1.5) / &Float::ZERO, Float::NEGATIVE_INFINITY);
assert_eq!(Float::from(-1.5) / &Float::NEGATIVE_ZERO, Float::INFINITY);
assert!((Float::ZERO / &Float::ZERO).is_nan());
assert_eq!((Float::from(1.5) / &Float::from(2.5)).to_string(), "0.6");
assert_eq!((Float::from(1.5) / &Float::from(-2.5)).to_string(), "-0.6");
assert_eq!((Float::from(-1.5) / &Float::from(2.5)).to_string(), "-0.6");
assert_eq!((Float::from(-1.5) / &Float::from(-2.5)).to_string(), "0.6");
Source§impl Div<&Float> for Rational
impl Div<&Float> for Rational
Source§fn div(self, other: &Float) -> Float
fn div(self, other: &Float) -> Float
Divides a Rational
by a Float
, taking the Rational
by value and the Float
by
reference.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) / &Float::NAN).is_nan());
assert_eq!(Rational::exact_from(1.5) / &Float::ZERO, Float::INFINITY);
assert_eq!(
Rational::exact_from(1.5) / &Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) / &Float::ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) / &Float::NEGATIVE_ZERO,
Float::INFINITY
);
assert_eq!(
(Rational::exact_from(1.5) / &Float::from(2.5)).to_string(),
"0.6"
);
assert_eq!(
(Rational::exact_from(-1.5) / &Float::from(2.5)).to_string(),
"-0.6"
);
assert_eq!(
(Rational::exact_from(1.5) / &Float::from(-2.5)).to_string(),
"-0.6"
);
assert_eq!(
(Rational::exact_from(-1.5) / &Float::from(-2.5)).to_string(),
"0.6"
);
Source§impl Div<&Rational> for &Float
impl Div<&Rational> for &Float
Source§fn div(self, other: &Rational) -> Float
fn div(self, other: &Rational) -> Float
Divides a Float
by a Rational
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=f(\pm0.0,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x\geq 0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x\geq 0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x>0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x>0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_ref_ref
instead. If you want to specify the output precision,
consider using Float::div_rational_round_ref_ref
. If you want both of these things,
consider using Float::div_rational_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN / &Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY / &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY / &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::INFINITY / &Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY / &Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(
(&Float::from(2.5) / &Rational::exact_from(1.5)).to_string(),
"1.8"
);
assert_eq!(
(&Float::from(2.5) / &Rational::exact_from(-1.5)).to_string(),
"-1.8"
);
assert_eq!(
(&Float::from(-2.5) / &Rational::exact_from(1.5)).to_string(),
"-1.8"
);
assert_eq!(
(&Float::from(-2.5) / &Rational::exact_from(-1.5)).to_string(),
"1.8"
);
Source§impl Div<&Rational> for Float
impl Div<&Rational> for Float
Source§fn div(self, other: &Rational) -> Float
fn div(self, other: &Rational) -> Float
Divides a Float
by a Rational
, taking the first by value and the second by
reference.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=f(\pm0.0,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x\geq 0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x\geq 0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x>0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x>0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_val_ref
instead. If you want to specify the output precision,
consider using Float::div_rational_round_val_ref
. If you want both of these things,
consider using Float::div_rational_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN / &Rational::exact_from(1.5)).is_nan());
assert_eq!(
Float::INFINITY / &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY / &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::INFINITY / &Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY / &Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(
(Float::from(2.5) / &Rational::exact_from(1.5)).to_string(),
"1.8"
);
assert_eq!(
(Float::from(2.5) / &Rational::exact_from(-1.5)).to_string(),
"-1.8"
);
assert_eq!(
(Float::from(-2.5) / &Rational::exact_from(1.5)).to_string(),
"-1.8"
);
assert_eq!(
(Float::from(-2.5) / &Rational::exact_from(-1.5)).to_string(),
"1.8"
);
Source§impl Div<Float> for &Float
impl Div<Float> for &Float
Source§fn div(self, other: Float) -> Float
fn div(self, other: Float) -> Float
Divides two Float
s, taking the first by reference and the second by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm\infty)=f(\pm0.0,\pm0.0) = \text{NaN}$
- $f(\infty,x)=\infty$ if $0.0<x<\infty$
- $f(\infty,x)=-\infty$ if $-\infty<x<0.0$
- $f(x,0.0)=\infty$ if $x>0.0$
- $f(x,0.0)=-\infty$ if $x<0.0$
- $f(-\infty,x)=-\infty$ if $0.0<x<\infty$
- $f(-\infty,x)=\infty$ if $-\infty<x<0.0$
- $f(x,-0.0)=-\infty$ if $x>0.0$
- $f(x,-0.0)=\infty$ if $x<0.0$
- $f(0.0,x)=0.0$ if $x$ is not NaN and $x>0.0$
- $f(0.0,x)=-0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=-0.0$ if $x$ is not NaN and $x>0.0$
- $f(-0.0,x)=0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,-\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,-\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_ref_val
instead. If you want to specify the output precision, consider
using Float::div_round_ref_val
. If you want both of these things, consider using
Float::div_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
assert!((&Float::from(1.5) / Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) / Float::ZERO, Float::INFINITY);
assert_eq!(
&Float::from(1.5) / Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(-1.5) / Float::ZERO, Float::NEGATIVE_INFINITY);
assert_eq!(&Float::from(-1.5) / Float::NEGATIVE_ZERO, Float::INFINITY);
assert!((&Float::ZERO / Float::ZERO).is_nan());
assert_eq!((&Float::from(1.5) / Float::from(2.5)).to_string(), "0.6");
assert_eq!((&Float::from(1.5) / Float::from(-2.5)).to_string(), "-0.6");
assert_eq!((&Float::from(-1.5) / Float::from(2.5)).to_string(), "-0.6");
assert_eq!((&Float::from(-1.5) / Float::from(-2.5)).to_string(), "0.6");
Source§impl Div<Float> for &Rational
impl Div<Float> for &Rational
Source§fn div(self, other: Float) -> Float
fn div(self, other: Float) -> Float
Divides a Rational
by a Float
, taking the Rational
by reference and the
Float
by value.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) / Float::NAN).is_nan());
assert_eq!(&Rational::exact_from(1.5) / Float::ZERO, Float::INFINITY);
assert_eq!(
&Rational::exact_from(1.5) / Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) / Float::ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) / Float::NEGATIVE_ZERO,
Float::INFINITY
);
assert_eq!(
(&Rational::exact_from(1.5) / Float::from(2.5)).to_string(),
"0.6"
);
assert_eq!(
(&Rational::exact_from(-1.5) / Float::from(2.5)).to_string(),
"-0.6"
);
assert_eq!(
(&Rational::exact_from(1.5) / Float::from(-2.5)).to_string(),
"-0.6"
);
assert_eq!(
(&Rational::exact_from(-1.5) / Float::from(-2.5)).to_string(),
"0.6"
);
Source§impl Div<Float> for Rational
impl Div<Float> for Rational
Source§fn div(self, other: Float) -> Float
fn div(self, other: Float) -> Float
Divides a Rational
by a Float
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN},p,m)=f(0,\pm0.0,p,m)=\text{NaN}$
- $f(x,\infty,x,p,m)=0.0$ if $x>0.0$ or $x=0.0$
- $f(x,\infty,x,p,m)=-0.0$ if $x<0.0$ or #x=-0.0$
- $f(x,-\infty,x,p,m)=-0.0$ if $x>0.0$ or $x=0.0$
- $f(x,-\infty,x,p,m)=0.0$ if $x<0.0$ or #x=-0.0$
- $f(0,x,p,m)=0.0$ if $x>0$
- $f(0,x,p,m)=-0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) / Float::NAN).is_nan());
assert_eq!(Rational::exact_from(1.5) / Float::ZERO, Float::INFINITY);
assert_eq!(
Rational::exact_from(1.5) / Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) / Float::ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) / Float::NEGATIVE_ZERO,
Float::INFINITY
);
assert_eq!(
(Rational::exact_from(1.5) / Float::from(2.5)).to_string(),
"0.6"
);
assert_eq!(
(Rational::exact_from(-1.5) / Float::from(2.5)).to_string(),
"-0.6"
);
assert_eq!(
(Rational::exact_from(1.5) / Float::from(-2.5)).to_string(),
"-0.6"
);
assert_eq!(
(Rational::exact_from(-1.5) / Float::from(-2.5)).to_string(),
"0.6"
);
Source§impl Div<Rational> for &Float
impl Div<Rational> for &Float
Source§fn div(self, other: Rational) -> Float
fn div(self, other: Rational) -> Float
Divides a Float
by a Rational
, taking the first by reference and the second by
value.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=f(\pm0.0,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x\geq 0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x\geq 0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x>0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x>0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_ref_val
instead. If you want to specify the output precision,
consider using Float::div_rational_round_ref_val
. If you want both of these things,
consider using Float::div_rational_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN / Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY / Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY / Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::INFINITY / Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY / Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(
(&Float::from(2.5) / Rational::exact_from(1.5)).to_string(),
"1.8"
);
assert_eq!(
(&Float::from(2.5) / Rational::exact_from(-1.5)).to_string(),
"-1.8"
);
assert_eq!(
(&Float::from(-2.5) / Rational::exact_from(1.5)).to_string(),
"-1.8"
);
assert_eq!(
(&Float::from(-2.5) / Rational::exact_from(-1.5)).to_string(),
"1.8"
);
Source§impl Div<Rational> for Float
impl Div<Rational> for Float
Source§fn div(self, other: Rational) -> Float
fn div(self, other: Rational) -> Float
Divides a Float
by a Rational
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=f(\pm0.0,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x\geq 0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x\geq 0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x>0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x>0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec
instead. If you want to specify the output precision, consider
using Float::div_rational_round
. If you want both of these things, consider using
Float::div_rational_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN / Rational::exact_from(1.5)).is_nan());
assert_eq!(Float::INFINITY / Rational::exact_from(1.5), Float::INFINITY);
assert_eq!(
Float::NEGATIVE_INFINITY / Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::INFINITY / Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY / Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(
(Float::from(2.5) / Rational::exact_from(1.5)).to_string(),
"1.8"
);
assert_eq!(
(Float::from(2.5) / Rational::exact_from(-1.5)).to_string(),
"-1.8"
);
assert_eq!(
(Float::from(-2.5) / Rational::exact_from(1.5)).to_string(),
"-1.8"
);
assert_eq!(
(Float::from(-2.5) / Rational::exact_from(-1.5)).to_string(),
"1.8"
);
Source§impl Div for Float
impl Div for Float
Source§fn div(self, other: Float) -> Float
fn div(self, other: Float) -> Float
Divides two Float
s, taking both by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm\infty)=f(\pm0.0,\pm0.0) = \text{NaN}$
- $f(\infty,x)=\infty$ if $0.0<x<\infty$
- $f(\infty,x)=-\infty$ if $-\infty<x<0.0$
- $f(x,0.0)=\infty$ if $x>0.0$
- $f(x,0.0)=-\infty$ if $x<0.0$
- $f(-\infty,x)=-\infty$ if $0.0<x<\infty$
- $f(-\infty,x)=\infty$ if $-\infty<x<0.0$
- $f(x,-0.0)=-\infty$ if $x>0.0$
- $f(x,-0.0)=\infty$ if $x<0.0$
- $f(0.0,x)=0.0$ if $x$ is not NaN and $x>0.0$
- $f(0.0,x)=-0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=-0.0$ if $x$ is not NaN and $x>0.0$
- $f(-0.0,x)=0.0$ if $x$ is not NaN and $x<0.0$
- $f(x,-\infty)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(x,-\infty)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
If you want to use a rounding mode other than Nearest
, consider using Float::div_prec
instead. If you want to specify the output precision, consider using Float::div_round
.
If you want both of these things, consider using Float::div_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
assert!((Float::from(1.5) / Float::NAN).is_nan());
assert_eq!(Float::from(1.5) / Float::ZERO, Float::INFINITY);
assert_eq!(
Float::from(1.5) / Float::NEGATIVE_ZERO,
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(-1.5) / Float::ZERO, Float::NEGATIVE_INFINITY);
assert_eq!(Float::from(-1.5) / Float::NEGATIVE_ZERO, Float::INFINITY);
assert!((Float::ZERO / Float::ZERO).is_nan());
assert_eq!((Float::from(1.5) / Float::from(2.5)).to_string(), "0.6");
assert_eq!((Float::from(1.5) / Float::from(-2.5)).to_string(), "-0.6");
assert_eq!((Float::from(-1.5) / Float::from(2.5)).to_string(), "-0.6");
assert_eq!((Float::from(-1.5) / Float::from(-2.5)).to_string(), "0.6");
Source§impl DivAssign<&Float> for Float
impl DivAssign<&Float> for Float
Source§fn div_assign(&mut self, other: &Float)
fn div_assign(&mut self, other: &Float)
Divides a Float
by a Float
in place, taking the Float
on the right-hand side by
reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the /
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_assign
instead. If you want to specify the output precision, consider
using Float::div_round_assign
. If you want both of these things, consider using
Float::div_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
let mut x = Float::from(1.5);
x /= &Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x /= &Float::ZERO;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x /= &Float::NEGATIVE_ZERO;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x /= &Float::ZERO;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x /= &Float::NEGATIVE_ZERO;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x /= &Float::INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x /= &Float::from(2.5);
assert_eq!(x.to_string(), "0.6");
let mut x = Float::from(1.5);
x /= &Float::from(-2.5);
assert_eq!(x.to_string(), "-0.6");
let mut x = Float::from(-1.5);
x /= &Float::from(2.5);
assert_eq!(x.to_string(), "-0.6");
let mut x = Float::from(-1.5);
x /= &Float::from(-2.5);
assert_eq!(x.to_string(), "0.6");
Source§impl DivAssign<&Rational> for Float
impl DivAssign<&Rational> for Float
Source§fn div_assign(&mut self, other: &Rational)
fn div_assign(&mut self, other: &Rational)
Divides a Float
by a Rational
in place, taking the Rational
by reference.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the /
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_assign_ref
instead. If you want to specify the output
precision, consider using Float::div_rational_round_assign_ref
. If you want both of
these things, consider using Float::div_rational_prec_round_assign_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x /= &Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x /= &Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x /= &Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x /= &Rational::exact_from(-1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x /= &Rational::exact_from(-1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(2.5);
x /= &Rational::exact_from(1.5);
assert_eq!(x.to_string(), "1.8");
Source§impl DivAssign<Rational> for Float
impl DivAssign<Rational> for Float
Source§fn div_assign(&mut self, other: Rational)
fn div_assign(&mut self, other: Rational)
Divides a Float
by a Rational
in place, taking the Rational
by value.
If the output has a precision, it is the precision of the input Float
. If the quotient
is equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the /
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_rational_prec_assign
instead. If you want to specify the output precision,
consider using Float::div_rational_round_assign
. If you want both of these things,
consider using Float::div_rational_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x /= Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x /= Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x /= Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x /= Rational::exact_from(-1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x /= Rational::exact_from(-1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(2.5);
x /= Rational::exact_from(1.5);
assert_eq!(x.to_string(), "1.8");
Source§impl DivAssign for Float
impl DivAssign for Float
Source§fn div_assign(&mut self, other: Float)
fn div_assign(&mut self, other: Float)
Divides a Float
by a Float
in place, taking the Float
on the right-hand side by
value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
quotient is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the /
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::div_prec_assign
instead. If you want to specify the output precision, consider
using Float::div_round_assign
. If you want both of these things, consider using
Float::div_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, Zero,
};
use malachite_float::Float;
let mut x = Float::from(1.5);
x /= Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x /= Float::ZERO;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x /= Float::NEGATIVE_ZERO;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x /= Float::ZERO;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x /= Float::NEGATIVE_ZERO;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x /= Float::INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x /= Float::from(2.5);
assert_eq!(x.to_string(), "0.6");
let mut x = Float::from(1.5);
x /= Float::from(-2.5);
assert_eq!(x.to_string(), "-0.6");
let mut x = Float::from(-1.5);
x /= Float::from(2.5);
assert_eq!(x.to_string(), "-0.6");
let mut x = Float::from(-1.5);
x /= Float::from(-2.5);
assert_eq!(x.to_string(), "0.6");
Source§impl From<f32> for Float
impl From<f32> for Float
Source§fn from(x: f32) -> Float
fn from(x: f32) -> Float
Converts a primitive float to a Float
.
If the primitive float is finite and nonzero, the precision of the Float
is the
minimum possible precision to represent the primitive float exactly. If you want to
specify a different precision, try Float::from_primitive_float_prec
. This may
require rounding, which uses Nearest
by default. To specify a rounding mode as
well as a precision, try Float::from_primitive_float_prec_round
.
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 x.sci_exponent().abs()
.
§Examples
See here.
Source§impl From<f64> for Float
impl From<f64> for Float
Source§fn from(x: f64) -> Float
fn from(x: f64) -> Float
Converts a primitive float to a Float
.
If the primitive float is finite and nonzero, the precision of the Float
is the
minimum possible precision to represent the primitive float exactly. If you want to
specify a different precision, try Float::from_primitive_float_prec
. This may
require rounding, which uses Nearest
by default. To specify a rounding mode as
well as a precision, try Float::from_primitive_float_prec_round
.
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 x.sci_exponent().abs()
.
§Examples
See here.
Source§impl From<i128> for Float
impl From<i128> for Float
Source§fn from(i: i128) -> Float
fn from(i: i128) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<i16> for Float
impl From<i16> for Float
Source§fn from(i: i16) -> Float
fn from(i: i16) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<i32> for Float
impl From<i32> for Float
Source§fn from(i: i32) -> Float
fn from(i: i32) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<i64> for Float
impl From<i64> for Float
Source§fn from(i: i64) -> Float
fn from(i: i64) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<i8> for Float
impl From<i8> for Float
Source§fn from(i: i8) -> Float
fn from(i: i8) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<isize> for Float
impl From<isize> for Float
Source§fn from(i: isize) -> Float
fn from(i: isize) -> Float
Converts a signed primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_signed_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_signed_prec_round
.
If you want to create a Float
from an signed primitive integer in a const
context, try Float::const_from_signed
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<u128> for Float
impl From<u128> for Float
Source§fn from(u: u128) -> Float
fn from(u: u128) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<u16> for Float
impl From<u16> for Float
Source§fn from(u: u16) -> Float
fn from(u: u16) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<u32> for Float
impl From<u32> for Float
Source§fn from(u: u32) -> Float
fn from(u: u32) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<u64> for Float
impl From<u64> for Float
Source§fn from(u: u64) -> Float
fn from(u: u64) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<u8> for Float
impl From<u8> for Float
Source§fn from(u: u8) -> Float
fn from(u: u8) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl From<usize> for Float
impl From<usize> for Float
Source§fn from(u: usize) -> Float
fn from(u: usize) -> Float
Converts an unsigned primitive integer to a Float
.
If the integer is nonzero, the precision of the Float
is equal to the integer’s
number of significant bits. If you want to specify a different precision, try
Float::from_unsigned_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_unsigned_prec_round
.
If you want to create a Float
from an unsigned primitive integer in a const
context, try Float::const_from_unsigned
instead.
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl FromStringBase for Float
impl FromStringBase for Float
Source§impl IntegerMantissaAndExponent<Natural, i64> for Float
impl IntegerMantissaAndExponent<Natural, i64> for Float
Source§fn integer_mantissa_and_exponent(self) -> (Natural, i64)
fn integer_mantissa_and_exponent(self) -> (Natural, i64)
Returns a Float
’s integer mantissa and exponent, taking the Float
by value.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = (\frac{|x|}{2^{e_i}}, e_i), $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
The inverse operation is
from_integer_mantissa_and_exponent
.
The integer exponent is less than or equal to $2^{30}-2$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, IntegerMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;
assert_eq!(
Float::ONE.integer_mantissa_and_exponent(),
(Natural::ONE, 0)
);
assert_eq!(
Float::from(std::f64::consts::PI).integer_mantissa_and_exponent(),
(Natural::from(884279719003555u64), -48)
);
assert_eq!(
Float::exact_from(Natural::from(3u32).pow(50u64)).integer_mantissa_and_exponent(),
(Natural::from_str("717897987691852588770249").unwrap(), 0)
);
assert_eq!(
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.integer_mantissa_and_exponent(),
(
Natural::from_str("1067349099133908271875104088939").unwrap(),
-179
)
);
Source§fn integer_exponent(self) -> i64
fn integer_exponent(self) -> i64
Returns a Float
’s integer exponent, taking the Float
by value.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = e_i, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
The integer exponent is less than or equal to $2^{30}-2$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, IntegerMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(Float::ONE.integer_exponent(), 0);
assert_eq!(Float::from(std::f64::consts::PI).integer_exponent(), -48);
assert_eq!(
Float::exact_from(Natural::from(3u32).pow(50u64)).integer_exponent(),
0
);
assert_eq!(
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.integer_exponent(),
-179
);
Source§fn from_integer_mantissa_and_exponent(
integer_mantissa: Natural,
integer_exponent: i64,
) -> Option<Float>
fn from_integer_mantissa_and_exponent( integer_mantissa: Natural, integer_exponent: i64, ) -> Option<Float>
Constructs a Float
from its integer mantissa and exponent.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer.
$$ f(x) = 2^{e_i}m_i. $$
The input does not have to be reduced; that is, the mantissa does not have to be odd. If the
inputs correspond to a number too large in absolute value or too close to zero to be
represented by a Float
, 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
integer_mantissa.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;
assert_eq!(
Float::from_integer_mantissa_and_exponent(Natural::ONE, 0).unwrap(),
1
);
assert_eq!(
Float::from_integer_mantissa_and_exponent(Natural::from(884279719003555u64), -48)
.unwrap(),
std::f64::consts::PI
);
assert_eq!(
Float::from_integer_mantissa_and_exponent(
Natural::from_str("717897987691852588770249").unwrap(),
0
)
.unwrap(),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
Float::from_integer_mantissa_and_exponent(
Natural::from_str("1067349099133908271875104088939").unwrap(),
-179
)
.unwrap(),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
Source§fn integer_mantissa(self) -> M
fn integer_mantissa(self) -> M
Source§impl IntegerMantissaAndExponent<Natural, i64, Float> for &Float
impl IntegerMantissaAndExponent<Natural, i64, Float> for &Float
Source§fn integer_mantissa_and_exponent(self) -> (Natural, i64)
fn integer_mantissa_and_exponent(self) -> (Natural, i64)
Returns a Float
’s integer mantissa and exponent, taking the Float
by reference.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = (\frac{|x|}{2^{e_i}}, e_i), $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
The inverse operation is
from_integer_mantissa_and_exponent
.
The integer exponent is less than or equal to $2^{30}-2$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, IntegerMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;
assert_eq!(
(&Float::ONE).integer_mantissa_and_exponent(),
(Natural::ONE, 0)
);
assert_eq!(
(&Float::from(std::f64::consts::PI)).integer_mantissa_and_exponent(),
(Natural::from(884279719003555u64), -48)
);
assert_eq!(
(&Float::exact_from(Natural::from(3u32).pow(50u64))).integer_mantissa_and_exponent(),
(Natural::from_str("717897987691852588770249").unwrap(), 0)
);
assert_eq!(
(&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
.integer_mantissa_and_exponent(),
(
Natural::from_str("1067349099133908271875104088939").unwrap(),
-179
)
);
Source§fn integer_exponent(self) -> i64
fn integer_exponent(self) -> i64
Returns a Float
’s integer exponent, taking the Float
by reference.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = e_i, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
The integer exponent is less than or equal to $2^{30}-2$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, IntegerMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!((&Float::ONE).integer_exponent(), 0);
assert_eq!((&Float::from(std::f64::consts::PI)).integer_exponent(), -48);
assert_eq!(
(&Float::exact_from(Natural::from(3u32).pow(50u64))).integer_exponent(),
0
);
assert_eq!(
(&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
.integer_exponent(),
-179
);
Source§fn from_integer_mantissa_and_exponent(
integer_mantissa: Natural,
integer_exponent: i64,
) -> Option<Float>
fn from_integer_mantissa_and_exponent( integer_mantissa: Natural, integer_exponent: i64, ) -> Option<Float>
Constructs a Float
from its integer mantissa and exponent.
When $x$ is finite and nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer.
$$ f(x) = 2^{e_i}m_i. $$
The input does not have to be reduced; that is, the mantissa does not have to be odd. If the
inputs correspond to a number too large in absolute value or too close to zero to be
represented by a Float
, 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
integer_mantissa.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
use std::str::FromStr;
assert_eq!(
<&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
Natural::ONE,
0
)
.unwrap(),
1
);
assert_eq!(
<&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
Natural::from(884279719003555u64),
-48
)
.unwrap(),
std::f64::consts::PI
);
assert_eq!(
<&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
Natural::from_str("717897987691852588770249").unwrap(),
0
)
.unwrap(),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
<&Float as IntegerMantissaAndExponent<_, _, _>>::from_integer_mantissa_and_exponent(
Natural::from_str("1067349099133908271875104088939").unwrap(),
-179
)
.unwrap(),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
Source§fn integer_mantissa(self) -> M
fn integer_mantissa(self) -> M
Source§impl IsInteger for &Float
impl IsInteger for &Float
Source§fn is_integer(self) -> bool
fn is_integer(self) -> bool
Determines whether a Float
is an integer.
$f(x) = x \in \Z$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{One, OneHalf, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_float::Float;
assert_eq!(Float::ZERO.is_integer(), true);
assert_eq!(Float::ONE.is_integer(), true);
assert_eq!(Float::from(100).is_integer(), true);
assert_eq!(Float::from(-100).is_integer(), true);
assert_eq!(Float::ONE_HALF.is_integer(), false);
assert_eq!((-Float::ONE_HALF).is_integer(), false);
Source§impl IsPowerOf2 for Float
impl IsPowerOf2 for Float
Source§fn is_power_of_2(&self) -> bool
fn is_power_of_2(&self) -> bool
Determines whether a Float
is an integer power of 2.
$f(x) = (\exists n \in \Z : 2^n = x)$.
Float
s that are NaN, infinite, or zero are not powers of 2.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::IsPowerOf2;
use malachite_base::num::basic::traits::{NaN, One, OneHalf, Two};
use malachite_float::Float;
assert_eq!(Float::NAN.is_power_of_2(), false);
assert_eq!(Float::ONE.is_power_of_2(), true);
assert_eq!(Float::TWO.is_power_of_2(), true);
assert_eq!(Float::ONE_HALF.is_power_of_2(), true);
assert_eq!(Float::from(1024).is_power_of_2(), true);
assert_eq!(Float::from(3).is_power_of_2(), false);
assert_eq!(Float::from(1025).is_power_of_2(), false);
assert_eq!(Float::from(0.1f64).is_power_of_2(), false);
Source§impl Mul<&Float> for &Float
impl Mul<&Float> for &Float
Source§fn mul(self, other: &Float) -> Float
fn mul(self, other: &Float) -> Float
Multiplies two Float
s, taking both by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm0.0)=f(\pm0.0,\pm\infty) = \text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x>0.0$
- $f(\infty,x)=f(x,\infty)=-\infty$ if $x<0.0$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x>0.0$
- $f(-\infty,x)=f(x,-\infty)=\infty$ if $x<0.0$
- $f(0.0,x)=f(x,0.0)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(0.0,x)=f(x,0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=f(x,-0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(-0.0,x)=f(x,-0.0)=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)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_ref
instead. If you want to specify the output precision, consider
using Float::mul_round_ref_ref
. If you want both of these things, consider using
Float::mul_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
assert!((&Float::from(1.5) * &Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) * &Float::INFINITY, Float::INFINITY);
assert_eq!(
&Float::from(1.5) * &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(-1.5) * &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(-1.5) * &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((&Float::INFINITY * &Float::ZERO).is_nan());
assert_eq!(&Float::from(1.5) * &Float::from(2.5), 4.0);
assert_eq!(&Float::from(1.5) * &Float::from(-2.5), -4.0);
assert_eq!(&Float::from(-1.5) * &Float::from(2.5), -4.0);
assert_eq!(&Float::from(-1.5) * &Float::from(-2.5), 4.0);
Source§impl Mul<&Float> for &Rational
impl Mul<&Float> for &Rational
Source§fn mul(self, other: &Float) -> Float
fn mul(self, other: &Float) -> Float
Multiplies a Rational
by a Float
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=f(0,\pm\infty)=\text{NaN}$
- $f(x,\infty)=\infty$ if $x>0$
- $f(x,\infty)=-\infty$ if $x<0$
- $f(x,-\infty)=-\infty$ if $x>0$
- $f(x,-\infty)=\infty$ if $x<0$
- $f(x,0.0)=0.0$ if $x\geq0$
- $f(x,0.0)=-0.0$ if $x<0$
- $f(x,-0.0)=-0.0$ if $x\geq0$
- $f(x,-0.0)=0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) * &Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) * &Float::INFINITY,
Float::INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) * &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) * &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) * &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(&Rational::exact_from(1.5) * &Float::from(2.5), 4.0);
assert_eq!(&Rational::exact_from(-1.5) * &Float::from(2.5), -4.0);
assert_eq!(&Rational::exact_from(1.5) * &Float::from(-2.5), -4.0);
assert_eq!(&Rational::exact_from(-1.5) * &Float::from(-2.5), 4.0);
Source§impl Mul<&Float> for Float
impl Mul<&Float> for Float
Source§fn mul(self, other: &Float) -> Float
fn mul(self, other: &Float) -> Float
Multiplies two Float
s, taking the first by value and the second by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm0.0)=f(\pm0.0,\pm\infty) = \text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x>0.0$
- $f(\infty,x)=f(x,\infty)=-\infty$ if $x<0.0$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x>0.0$
- $f(-\infty,x)=f(x,-\infty)=\infty$ if $x<0.0$
- $f(0.0,x)=f(x,0.0)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(0.0,x)=f(x,0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=f(x,-0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(-0.0,x)=f(x,-0.0)=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)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_val_ref
instead. If you want to specify the output precision, consider
using Float::mul_round_val_ref
. If you want both of these things, consider using
Float::mul_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
assert!((Float::from(1.5) * &Float::NAN).is_nan());
assert_eq!(Float::from(1.5) * &Float::INFINITY, Float::INFINITY);
assert_eq!(
Float::from(1.5) * &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::from(-1.5) * &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::from(-1.5) * &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((Float::INFINITY * &Float::ZERO).is_nan());
assert_eq!(Float::from(1.5) * &Float::from(2.5), 4.0);
assert_eq!(Float::from(1.5) * &Float::from(-2.5), -4.0);
assert_eq!(Float::from(-1.5) * &Float::from(2.5), -4.0);
assert_eq!(Float::from(-1.5) * &Float::from(-2.5), 4.0);
Source§impl Mul<&Float> for Rational
impl Mul<&Float> for Rational
Source§fn mul(self, other: &Float) -> Float
fn mul(self, other: &Float) -> Float
Multiplies a Rational
by a Float
, taking the Rational
by value and the Float
by reference.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=f(0,\pm\infty)=\text{NaN}$
- $f(x,\infty)=\infty$ if $x>0$
- $f(x,\infty)=-\infty$ if $x<0$
- $f(x,-\infty)=-\infty$ if $x>0$
- $f(x,-\infty)=\infty$ if $x<0$
- $f(x,0.0)=0.0$ if $x\geq0$
- $f(x,0.0)=-0.0$ if $x<0$
- $f(x,-0.0)=-0.0$ if $x\geq0$
- $f(x,-0.0)=0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) * &Float::NAN).is_nan());
assert_eq!(
Rational::exact_from(1.5) * &Float::INFINITY,
Float::INFINITY
);
assert_eq!(
Rational::exact_from(1.5) * &Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) * &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) * &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(Rational::exact_from(1.5) * &Float::from(2.5), 4.0);
assert_eq!(Rational::exact_from(-1.5) * &Float::from(2.5), -4.0);
assert_eq!(Rational::exact_from(1.5) * &Float::from(-2.5), -4.0);
assert_eq!(Rational::exact_from(-1.5) * &Float::from(-2.5), 4.0);
Source§impl Mul<&Rational> for &Float
impl Mul<&Rational> for &Float
Source§fn mul(self, other: &Rational) -> Float
fn mul(self, other: &Rational) -> Float
Multiplies a Float
by a Rational
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x>0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x>0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x\geq0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x\geq0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_ref_ref
instead. If you want to specify the output precision,
consider using Float::mul_rational_round_ref_ref
. If you want both of these things,
consider using Float::mul_rational_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN * &Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY * &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY * &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::INFINITY * &Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY * &Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(&Float::from(2.5) * &Rational::exact_from(1.5), 4.0);
assert_eq!(&Float::from(2.5) * &Rational::exact_from(-1.5), -4.0);
assert_eq!(&Float::from(-2.5) * &Rational::exact_from(1.5), -4.0);
assert_eq!(&Float::from(-2.5) * &Rational::exact_from(-1.5), 4.0);
Source§impl Mul<&Rational> for Float
impl Mul<&Rational> for Float
Source§fn mul(self, other: &Rational) -> Float
fn mul(self, other: &Rational) -> Float
Multiplies a Float
by a Rational
, taking the first by value and the second by
reference.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x>0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x>0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x\geq0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x\geq0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_val_ref
instead. If you want to specify the output precision,
consider using Float::mul_rational_round_val_ref
. If you want both of these things,
consider using Float::mul_rational_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN * &Rational::exact_from(1.5)).is_nan());
assert_eq!(
Float::INFINITY * &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY * &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::INFINITY * &Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY * &Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(Float::from(2.5) * &Rational::exact_from(1.5), 4.0);
assert_eq!(Float::from(2.5) * &Rational::exact_from(-1.5), -4.0);
assert_eq!(Float::from(-2.5) * &Rational::exact_from(1.5), -4.0);
assert_eq!(Float::from(-2.5) * &Rational::exact_from(-1.5), 4.0);
Source§impl Mul<Float> for &Float
impl Mul<Float> for &Float
Source§fn mul(self, other: Float) -> Float
fn mul(self, other: Float) -> Float
Multiplies two Float
s, taking the first by reference and the second by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm0.0)=f(\pm0.0,\pm\infty) = \text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x>0.0$
- $f(\infty,x)=f(x,\infty)=-\infty$ if $x<0.0$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x>0.0$
- $f(-\infty,x)=f(x,-\infty)=\infty$ if $x<0.0$
- $f(0.0,x)=f(x,0.0)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(0.0,x)=f(x,0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=f(x,-0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(-0.0,x)=f(x,-0.0)=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)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_val
instead. If you want to specify the output precision, consider
using Float::mul_round_ref_val
. If you want both of these things, consider using
Float::mul_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
assert!((&Float::from(1.5) * Float::NAN).is_nan());
assert_eq!(&Float::from(1.5) * Float::INFINITY, Float::INFINITY);
assert_eq!(
&Float::from(1.5) * Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(-1.5) * Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(-1.5) * Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((&Float::INFINITY * Float::ZERO).is_nan());
assert_eq!(&Float::from(1.5) * Float::from(2.5), 4.0);
assert_eq!(&Float::from(1.5) * Float::from(-2.5), -4.0);
assert_eq!(&Float::from(-1.5) * Float::from(2.5), -4.0);
assert_eq!(&Float::from(-1.5) * Float::from(-2.5), 4.0);
Source§impl Mul<Float> for &Rational
impl Mul<Float> for &Rational
Source§fn mul(self, other: Float) -> Float
fn mul(self, other: Float) -> Float
Multiplies a Rational
by a Float
, taking the Rational
by reference and the
Float
by value.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=f(0,\pm\infty)=\text{NaN}$
- $f(x,\infty)=\infty$ if $x>0$
- $f(x,\infty)=-\infty$ if $x<0$
- $f(x,-\infty)=-\infty$ if $x>0$
- $f(x,-\infty)=\infty$ if $x<0$
- $f(x,0.0)=0.0$ if $x\geq0$
- $f(x,0.0)=-0.0$ if $x<0$
- $f(x,-0.0)=-0.0$ if $x\geq0$
- $f(x,-0.0)=0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) * Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) * Float::INFINITY,
Float::INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) * Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) * Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(-1.5) * Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(&Rational::exact_from(1.5) * Float::from(2.5), 4.0);
assert_eq!(&Rational::exact_from(-1.5) * Float::from(2.5), -4.0);
assert_eq!(&Rational::exact_from(1.5) * Float::from(-2.5), -4.0);
assert_eq!(&Rational::exact_from(-1.5) * Float::from(-2.5), 4.0);
Source§impl Mul<Float> for Rational
impl Mul<Float> for Rational
Source§fn mul(self, other: Float) -> Float
fn mul(self, other: Float) -> Float
Multiplies a Rational
by a Float
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=f(0,\pm\infty)=\text{NaN}$
- $f(x,\infty)=\infty$ if $x>0$
- $f(x,\infty)=-\infty$ if $x<0$
- $f(x,-\infty)=-\infty$ if $x>0$
- $f(x,-\infty)=\infty$ if $x<0$
- $f(x,0.0)=0.0$ if $x\geq0$
- $f(x,0.0)=-0.0$ if $x<0$
- $f(x,-0.0)=-0.0$ if $x\geq0$
- $f(x,-0.0)=0.0$ if $x<0$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) * Float::NAN).is_nan());
assert_eq!(Rational::exact_from(1.5) * Float::INFINITY, Float::INFINITY);
assert_eq!(
Rational::exact_from(1.5) * Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) * Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(-1.5) * Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(Rational::exact_from(1.5) * Float::from(2.5), 4.0);
assert_eq!(Rational::exact_from(-1.5) * Float::from(2.5), -4.0);
assert_eq!(Rational::exact_from(1.5) * Float::from(-2.5), -4.0);
assert_eq!(Rational::exact_from(-1.5) * Float::from(-2.5), 4.0);
Source§impl Mul<Rational> for &Float
impl Mul<Rational> for &Float
Source§fn mul(self, other: Rational) -> Float
fn mul(self, other: Rational) -> Float
Multiplies a Float
by a Rational
, taking the first by reference and the second by
value.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x>0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x>0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x\geq0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x\geq0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_ref_val
instead. If you want to specify the output precision,
consider using Float::mul_rational_round_ref_val
. If you want both of these things,
consider using Float::mul_rational_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN * Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY * Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY * Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::INFINITY * Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY * Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(&Float::from(2.5) * Rational::exact_from(1.5), 4.0);
assert_eq!(&Float::from(2.5) * Rational::exact_from(-1.5), -4.0);
assert_eq!(&Float::from(-2.5) * Rational::exact_from(1.5), -4.0);
assert_eq!(&Float::from(-2.5) * Rational::exact_from(-1.5), 4.0);
Source§impl Mul<Rational> for Float
impl Mul<Rational> for Float
Source§fn mul(self, other: Rational) -> Float
fn mul(self, other: Rational) -> Float
Multiplies a Float
by a Rational
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=f(\pm\infty,0)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x>0$
- $f(\infty,x)=-\infty$ if $x<0$
- $f(-\infty,x)=-\infty$ if $x>0$
- $f(-\infty,x)=\infty$ if $x<0$
- $f(0.0,x)=0.0$ if $x\geq0$
- $f(0.0,x)=-0.0$ if $x<0$
- $f(-0.0,x)=-0.0$ if $x\geq0$
- $f(-0.0,x)=0.0$ if $x<0$
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec
instead. If you want to specify the output precision, consider
using Float::mul_rational_round
. If you want both of these things, consider using
Float::mul_rational_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN * Rational::exact_from(1.5)).is_nan());
assert_eq!(Float::INFINITY * Rational::exact_from(1.5), Float::INFINITY);
assert_eq!(
Float::NEGATIVE_INFINITY * Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::INFINITY * Rational::exact_from(-1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY * Rational::exact_from(-1.5),
Float::INFINITY
);
assert_eq!(Float::from(2.5) * Rational::exact_from(1.5), 4.0);
assert_eq!(Float::from(2.5) * Rational::exact_from(-1.5), -4.0);
assert_eq!(Float::from(-2.5) * Rational::exact_from(1.5), -4.0);
assert_eq!(Float::from(-2.5) * Rational::exact_from(-1.5), 4.0);
Source§impl Mul for Float
impl Mul for Float
Source§fn mul(self, other: Float) -> Float
fn mul(self, other: Float) -> Float
Multiplies two Float
s, taking both by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\pm\infty,\pm0.0)=f(\pm0.0,\pm\infty) = \text{NaN}$
- $f(\infty,x)=f(x,\infty)=\infty$ if $x>0.0$
- $f(\infty,x)=f(x,\infty)=-\infty$ if $x<0.0$
- $f(-\infty,x)=f(x,-\infty)=-\infty$ if $x>0.0$
- $f(-\infty,x)=f(x,-\infty)=\infty$ if $x<0.0$
- $f(0.0,x)=f(x,0.0)=0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(0.0,x)=f(x,0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=-0.0$ or $x<0.0$
- $f(-0.0,x)=f(x,-0.0)=-0.0$ if $x$ is not NaN or $\pm\infty$, and if $x=0.0$ or $x>0.0$
- $f(-0.0,x)=f(x,-0.0)=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)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider using Float::mul_round
.
If you want both of these things, consider using Float::mul_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
assert!((Float::from(1.5) * Float::NAN).is_nan());
assert_eq!(Float::from(1.5) * Float::INFINITY, Float::INFINITY);
assert_eq!(
Float::from(1.5) * Float::NEGATIVE_INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::from(-1.5) * Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::from(-1.5) * Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((Float::INFINITY * Float::ZERO).is_nan());
assert_eq!(Float::from(1.5) * Float::from(2.5), 4.0);
assert_eq!(Float::from(1.5) * Float::from(-2.5), -4.0);
assert_eq!(Float::from(-1.5) * Float::from(2.5), -4.0);
assert_eq!(Float::from(-1.5) * Float::from(-2.5), 4.0);
Source§impl MulAssign<&Float> for Float
impl MulAssign<&Float> for Float
Source§fn mul_assign(&mut self, other: &Float)
fn mul_assign(&mut self, other: &Float)
Multiplies a Float
by a Float
in place, taking the Float
on the right-hand side
by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the *
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_prec_assign
instead. If you want to specify the output precision, consider
using Float::mul_round_assign
. If you want both of these things, consider using
Float::mul_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
let mut x = Float::from(1.5);
x *= &Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x *= &Float::INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x *= &Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x *= &Float::INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x *= &Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x *= &Float::ZERO;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x *= &Float::from(2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(1.5);
x *= &Float::from(-2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x *= &Float::from(2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x *= &Float::from(-2.5);
assert_eq!(x, 4.0);
Source§impl MulAssign<&Rational> for Float
impl MulAssign<&Rational> for Float
Source§fn mul_assign(&mut self, other: &Rational)
fn mul_assign(&mut self, other: &Rational)
Multiplies a Float
by a Rational
in place, taking the Rational
by reference.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the *
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_assign_ref
instead. If you want to specify the output
precision, consider using Float::mul_rational_round_assign_ref
. If you want both of
these things, consider using Float::mul_rational_prec_round_assign_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x *= &Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x *= &Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x *= &Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x *= &Rational::exact_from(-1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x *= &Rational::exact_from(-1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(2.5);
x *= &Rational::exact_from(1.5);
assert_eq!(x, 4.0);
Source§impl MulAssign<Rational> for Float
impl MulAssign<Rational> for Float
Source§fn mul_assign(&mut self, other: Rational)
fn mul_assign(&mut self, other: Rational)
Multiplies a Float
by a Rational
in place, taking the Rational
by value.
If the output has a precision, it is the precision of the input Float
. If the product is
equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the *
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_rational_prec_assign
instead. If you want to specify the output precision,
consider using Float::mul_rational_round_assign
. If you want both of these things,
consider using Float::mul_rational_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x *= Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x *= Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x *= Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::INFINITY;
x *= Rational::exact_from(-1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x *= Rational::exact_from(-1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(2.5);
x *= Rational::exact_from(1.5);
assert_eq!(x, 4.0);
Source§impl MulAssign for Float
impl MulAssign for Float
Source§fn mul_assign(&mut self, other: Float)
fn mul_assign(&mut self, other: Float)
Multiplies a Float
by a Float
in place, taking the Float
on the right-hand side
by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
product is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the *
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::mul_prec_assign
instead. If you want to specify the output precision, consider
using Float::mul_round_assign
. If you want both of these things, consider using
Float::mul_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity, Zero};
use malachite_float::Float;
let mut x = Float::from(1.5);
x *= Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x *= Float::INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x *= Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x *= Float::INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(-1.5);
x *= Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x *= Float::ZERO;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x *= Float::from(2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(1.5);
x *= Float::from(-2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x *= Float::from(2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x *= Float::from(-2.5);
assert_eq!(x, 4.0);
Source§impl Neg for &Float
impl Neg for &Float
Source§fn neg(self) -> Float
fn neg(self) -> Float
Negates a Float
, taking it by reference.
$$ f(x) = -x. $$
Special cases:
- $f(\text{NaN}) = \text{NaN}$
- $f(\infty) = -\infty$
- $f(-\infty) = \infty$
- $f(0.0) = -0.0$
- $f(-0.0) = 0.0$
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), ComparableFloat(Float::NAN));
assert_eq!(-&Float::INFINITY, Float::NEGATIVE_INFINITY);
assert_eq!(-&Float::NEGATIVE_INFINITY, Float::INFINITY);
assert_eq!(
ComparableFloat(-&Float::ZERO),
ComparableFloat(Float::NEGATIVE_ZERO)
);
assert_eq!(
ComparableFloat(-&Float::NEGATIVE_ZERO),
ComparableFloat(Float::ZERO)
);
assert_eq!(-&Float::ONE, Float::NEGATIVE_ONE);
assert_eq!(-&Float::NEGATIVE_ONE, Float::ONE);
Source§impl Neg for Float
impl Neg for Float
Source§fn neg(self) -> Float
fn neg(self) -> Float
Negates a Float
, taking it by value.
$$ f(x) = -x. $$
Special cases:
- $f(\text{NaN}) = \text{NaN}$
- $f(\infty) = -\infty$
- $f(-\infty) = \infty$
- $f(0.0) = -0.0$
- $f(-0.0) = 0.0$
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
assert_eq!(ComparableFloat(-Float::NAN), ComparableFloat(Float::NAN));
assert_eq!(-Float::INFINITY, Float::NEGATIVE_INFINITY);
assert_eq!(-Float::NEGATIVE_INFINITY, Float::INFINITY);
assert_eq!(
ComparableFloat(-Float::ZERO),
ComparableFloat(Float::NEGATIVE_ZERO)
);
assert_eq!(
ComparableFloat(-Float::NEGATIVE_ZERO),
ComparableFloat(Float::ZERO)
);
assert_eq!(-Float::ONE, Float::NEGATIVE_ONE);
assert_eq!(-Float::NEGATIVE_ONE, Float::ONE);
Source§impl NegAssign for Float
impl NegAssign for Float
Source§fn neg_assign(&mut self)
fn neg_assign(&mut self)
Negates a Float
in place.
$$ x \gets -x. $$
Special cases:
- $\text{NaN} \gets \text{NaN}$
- $\infty \gets -\infty$
- $-\infty \gets \infty$
- $0.0 \gets -0.0$
- $-0.0 \gets 0.0$
This function does not overflow or underflow.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::NegAssign;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::{ComparableFloat, Float};
let mut x = Float::NAN;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NAN));
let mut x = Float::INFINITY;
x.neg_assign();
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x.neg_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::ZERO;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::NEGATIVE_ZERO));
let mut x = Float::NEGATIVE_ZERO;
x.neg_assign();
assert_eq!(ComparableFloat(x), ComparableFloat(Float::ZERO));
let mut x = Float::ONE;
x.neg_assign();
assert_eq!(x, Float::NEGATIVE_ONE);
let mut x = Float::NEGATIVE_ONE;
x.neg_assign();
assert_eq!(x, Float::ONE);
Source§impl NegativeInfinity for Float
The constant $-\infty$.
impl NegativeInfinity for Float
The constant $-\infty$.
const NEGATIVE_INFINITY: Float
Source§impl NegativeOne for Float
The constant -1.0, with precision 1.
impl NegativeOne for Float
The constant -1.0, with precision 1.
const NEGATIVE_ONE: Float
Source§impl NegativeZero for Float
The constant -0.0, with precision 1.
impl NegativeZero for Float
The constant -0.0, with precision 1.
const NEGATIVE_ZERO: Float
Source§impl PartialEq<Float> for Integer
impl PartialEq<Float> for Integer
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an Integer
is equal to a Float
.
No Integer
is equal to $\infty$, $-\infty$, or NaN. The Integer
zero is equal to
both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Integer::from(123) == Float::from(123));
assert!(Integer::from(-123) == Float::from(-123));
assert!(Integer::ONE != Float::ONE_HALF);
Source§impl PartialEq<Float> for Natural
impl PartialEq<Float> for Natural
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a Natural
is equal to a Float
.
No Natural
is equal to $\infty$, $-\infty$, or NaN. The Natural
zero is equal to
both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Natural::from(123u32) == Float::from(123));
assert!(Natural::ONE != Float::ONE_HALF);
Source§impl PartialEq<Float> for Rational
impl PartialEq<Float> for Rational
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a Rational
is equal to a Float
.
No Rational
is equal to $\infty$, $-\infty$, or NaN. The Rational
zero is equal to
both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::OneHalf;
use malachite_float::Float;
use malachite_q::Rational;
assert!(Rational::from(123) == Float::from(123));
assert!(Rational::from(-123) == Float::from(-123));
assert!(Rational::ONE_HALF == Float::ONE_HALF);
assert!(Rational::from_unsigneds(1u8, 3) != Float::from(1.0f64 / 3.0));
Source§impl PartialEq<Float> for f32
impl PartialEq<Float> for f32
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a primitive float is equal to a Float
.
The primitive float $\infty$ is equal to the Float
$\infty$, and the primitive
float $-\infty$ is equal to the Float
$-\infty$. The primitive float NaN is not
equal to anything, not even the Float
NaN. Every primitive float zero is equal
to every Float
zero, regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialEq<Float> for f64
impl PartialEq<Float> for f64
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a primitive float is equal to a Float
.
The primitive float $\infty$ is equal to the Float
$\infty$, and the primitive
float $-\infty$ is equal to the Float
$-\infty$. The primitive float NaN is not
equal to anything, not even the Float
NaN. Every primitive float zero is equal
to every Float
zero, regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialEq<Float> for i128
impl PartialEq<Float> for i128
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for i16
impl PartialEq<Float> for i16
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for i32
impl PartialEq<Float> for i32
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for i64
impl PartialEq<Float> for i64
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for i8
impl PartialEq<Float> for i8
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for isize
impl PartialEq<Float> for isize
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether a signed primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for u128
impl PartialEq<Float> for u128
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for u16
impl PartialEq<Float> for u16
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for u32
impl PartialEq<Float> for u32
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for u64
impl PartialEq<Float> for u64
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for u8
impl PartialEq<Float> for u8
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Float> for usize
impl PartialEq<Float> for usize
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Determines whether an unsigned primitive integer is equal to a Float
.
No primitive integer is equal to $\infty$, $-\infty$, or NaN. The integer zero is
equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<Integer> for Float
impl PartialEq<Integer> for Float
Source§fn eq(&self, other: &Integer) -> bool
fn eq(&self, other: &Integer) -> bool
Determines whether a Float
is equal to an Integer
.
$\infty$, $-\infty$, and NaN are not equal to any Integer
. Both the Float
zero and
the Float
negative zero are equal to the Integer
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Float::from(123) == Integer::from(123));
assert!(Float::from(-123) == Integer::from(-123));
assert!(Float::ONE_HALF != Integer::ONE);
Source§impl PartialEq<Natural> for Float
impl PartialEq<Natural> for Float
Source§fn eq(&self, other: &Natural) -> bool
fn eq(&self, other: &Natural) -> bool
Determines whether a Float
is equal to a Natural
.
$\infty$, $-\infty$, and NaN are not equal to any Natural
. Both the Float
zero and
the Float
negative zero are equal to the Natural
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Float::from(123) == Natural::from(123u32));
assert!(Float::ONE_HALF != Natural::ONE);
Source§impl PartialEq<Rational> for Float
impl PartialEq<Rational> for Float
Source§fn eq(&self, other: &Rational) -> bool
fn eq(&self, other: &Rational) -> bool
Determines whether a Float
is equal to a Rational
.
$\infty$, $-\infty$, and NaN are not equal to any Rational
. Both the Float
zero and
the Float
negative zero are equal to the Rational
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::OneHalf;
use malachite_float::Float;
use malachite_q::Rational;
assert!(Float::from(123) == Rational::from(123));
assert!(Float::from(-123) == Rational::from(-123));
assert!(Float::ONE_HALF == Rational::ONE_HALF);
assert!(Float::from(1.0f64 / 3.0) != Rational::from_unsigneds(1u8, 3));
Source§impl PartialEq<f32> for Float
impl PartialEq<f32> for Float
Source§fn eq(&self, other: &f32) -> bool
fn eq(&self, other: &f32) -> bool
Determines whether a Float
is equal to a primitive float.
The Float
$\infty$ is equal to the primitive float $\infty$, and the Float
$-\infty$ is equal to the primitive float $-\infty$. The Float
NaN is not equal
to anything, not even the primitive float NaN. Every Float
zero is equal to
every primitive float zero, regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialEq<f64> for Float
impl PartialEq<f64> for Float
Source§fn eq(&self, other: &f64) -> bool
fn eq(&self, other: &f64) -> bool
Determines whether a Float
is equal to a primitive float.
The Float
$\infty$ is equal to the primitive float $\infty$, and the Float
$-\infty$ is equal to the primitive float $-\infty$. The Float
NaN is not equal
to anything, not even the primitive float NaN. Every Float
zero is equal to
every primitive float zero, regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialEq<i128> for Float
impl PartialEq<i128> for Float
Source§fn eq(&self, other: &i128) -> bool
fn eq(&self, other: &i128) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<i16> for Float
impl PartialEq<i16> for Float
Source§fn eq(&self, other: &i16) -> bool
fn eq(&self, other: &i16) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<i32> for Float
impl PartialEq<i32> for Float
Source§fn eq(&self, other: &i32) -> bool
fn eq(&self, other: &i32) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<i64> for Float
impl PartialEq<i64> for Float
Source§fn eq(&self, other: &i64) -> bool
fn eq(&self, other: &i64) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<i8> for Float
impl PartialEq<i8> for Float
Source§fn eq(&self, other: &i8) -> bool
fn eq(&self, other: &i8) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<isize> for Float
impl PartialEq<isize> for Float
Source§fn eq(&self, other: &isize) -> bool
fn eq(&self, other: &isize) -> bool
Determines whether a Float
is equal to a signed primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<u128> for Float
impl PartialEq<u128> for Float
Source§fn eq(&self, other: &u128) -> bool
fn eq(&self, other: &u128) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<u16> for Float
impl PartialEq<u16> for Float
Source§fn eq(&self, other: &u16) -> bool
fn eq(&self, other: &u16) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<u32> for Float
impl PartialEq<u32> for Float
Source§fn eq(&self, other: &u32) -> bool
fn eq(&self, other: &u32) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<u64> for Float
impl PartialEq<u64> for Float
Source§fn eq(&self, other: &u64) -> bool
fn eq(&self, other: &u64) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<u8> for Float
impl PartialEq<u8> for Float
Source§fn eq(&self, other: &u8) -> bool
fn eq(&self, other: &u8) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq<usize> for Float
impl PartialEq<usize> for Float
Source§fn eq(&self, other: &usize) -> bool
fn eq(&self, other: &usize) -> bool
Determines whether a Float
is equal to an unsigned primitive integer.
$\infty$, $-\infty$, and NaN are not equal to any primitive integer. Both the
Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialEq for Float
impl PartialEq for Float
Source§fn eq(&self, other: &Float) -> bool
fn eq(&self, other: &Float) -> bool
Compares two Float
s for equality.
This implementation follows the IEEE 754 standard. NaN
is not equal to anything, not even
itself. Positive zero is equal to negative zero. Float
s with different precisions are
equal if they represent the same numeric value.
For different equality behavior, consider using ComparableFloat
or
ComparableFloatRef
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{NaN, NegativeZero, One, Two, Zero};
use malachite_float::Float;
assert_ne!(Float::NAN, Float::NAN);
assert_eq!(Float::ZERO, Float::ZERO);
assert_eq!(Float::NEGATIVE_ZERO, Float::NEGATIVE_ZERO);
assert_eq!(Float::ZERO, Float::NEGATIVE_ZERO);
assert_eq!(Float::ONE, Float::ONE);
assert_ne!(Float::ONE, Float::TWO);
assert_eq!(Float::ONE, Float::one_prec(100));
Source§impl PartialOrd<Float> for Integer
impl PartialOrd<Float> for Integer
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an Integer
to a Float
.
No Integer
is comparable to NaN. Every Integer
is smaller than $\infty$ and greater
than $-\infty$. The Integer
zero is equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Integer::from(100) > Float::from(80));
assert!(Integer::from(-100) < Float::from(-80));
assert!(Integer::from(100) < Float::INFINITY);
assert!(Integer::from(-100) > Float::NEGATIVE_INFINITY);
Source§impl PartialOrd<Float> for Natural
impl PartialOrd<Float> for Natural
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a Natural
to a Float
.
No Natural
is comparable to NaN. Every Natural
is smaller than $\infty$ and greater
than $-\infty$. The Natural
zero is equal to both the Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Natural::from(100u32) > Float::from(80));
assert!(Natural::from(100u32) < Float::INFINITY);
assert!(Natural::from(100u32) > Float::NEGATIVE_INFINITY);
Source§impl PartialOrd<Float> for Rational
impl PartialOrd<Float> for Rational
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an Rational
to a Float
.
No Rational
is comparable to NaN. Every Rational
is smaller than $\infty$ and
greater than $-\infty$. The Rational
zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_q::Rational;
assert!(Rational::from(100) > Float::from(80));
assert!(Rational::from(-100) < Float::from(-80));
assert!(Rational::from(100) < Float::INFINITY);
assert!(Rational::from(-100) > Float::NEGATIVE_INFINITY);
assert!(Rational::from_unsigneds(1u8, 3) > Float::from(1.0f64 / 3.0));
Source§impl PartialOrd<Float> for f32
impl PartialOrd<Float> for f32
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a primitive float to a Float
.
The primitive float NaN is not comparable to any primitive float, not even the
Float
NaN. Every primitive float zero is equal to every Float
zero,
regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialOrd<Float> for f64
impl PartialOrd<Float> for f64
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a primitive float to a Float
.
The primitive float NaN is not comparable to any primitive float, not even the
Float
NaN. Every primitive float zero is equal to every Float
zero,
regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialOrd<Float> for i128
impl PartialOrd<Float> for i128
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for i16
impl PartialOrd<Float> for i16
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for i32
impl PartialOrd<Float> for i32
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for i64
impl PartialOrd<Float> for i64
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for i8
impl PartialOrd<Float> for i8
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for isize
impl PartialOrd<Float> for isize
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares a signed primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for u128
impl PartialOrd<Float> for u128
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for u16
impl PartialOrd<Float> for u16
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for u32
impl PartialOrd<Float> for u32
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for u64
impl PartialOrd<Float> for u64
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for u8
impl PartialOrd<Float> for u8
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Float> for usize
impl PartialOrd<Float> for usize
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares an unsigned primitive integer to a Float
.
No integer is comparable to NaN. Every integer is smaller than $\infty$ and greater
than $-\infty$. The integer zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<Integer> for Float
impl PartialOrd<Integer> for Float
Source§fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
Compares a Float
to an Integer
.
NaN is not comparable to any Integer
. $\infty$ is greater than any Integer
, and
$-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the
Integer
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Float::from(80) < Integer::from(100));
assert!(Float::from(-80) > Integer::from(-100));
assert!(Float::INFINITY > Integer::from(100));
assert!(Float::NEGATIVE_INFINITY < Integer::from(-100));
Source§impl PartialOrd<Natural> for Float
impl PartialOrd<Natural> for Float
Source§fn partial_cmp(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp(&self, other: &Natural) -> Option<Ordering>
Compares a Float
to a Natural
.
NaN is not comparable to any Natural
. $\infty$ is greater than any Natural
, and
$-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the
Natural
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Float::from(80) < Natural::from(100u32));
assert!(Float::INFINITY > Natural::from(100u32));
assert!(Float::NEGATIVE_INFINITY < Natural::from(100u32));
Source§impl PartialOrd<Rational> for Float
impl PartialOrd<Rational> for Float
Source§fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
Compares a Float
to a Rational
.
NaN is not comparable to any Rational
. $\infty$ is greater than any Rational
, and
$-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the
Rational
zero.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_float::Float;
use malachite_q::Rational;
assert!(Float::from(80) < Rational::from(100));
assert!(Float::from(-80) > Rational::from(-100));
assert!(Float::INFINITY > Rational::from(100));
assert!(Float::NEGATIVE_INFINITY < Rational::from(-100));
assert!(Float::from(1.0f64 / 3.0) < Rational::from_unsigneds(1u8, 3));
Source§impl PartialOrd<f32> for Float
impl PartialOrd<f32> for Float
Source§fn partial_cmp(&self, other: &f32) -> Option<Ordering>
fn partial_cmp(&self, other: &f32) -> Option<Ordering>
Compares a Float
to a primitive float.
The Float
NaN is not comparable to any primitive float, not even the primitive
float NaN. Every Float
zero is equal to every primitive float zero, regardless
of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialOrd<f64> for Float
impl PartialOrd<f64> for Float
Source§fn partial_cmp(&self, other: &f64) -> Option<Ordering>
fn partial_cmp(&self, other: &f64) -> Option<Ordering>
Compares a Float
to a primitive float.
The Float
NaN is not comparable to any primitive float, not even the primitive
float NaN. Every Float
zero is equal to every primitive float zero, regardless
of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§impl PartialOrd<i128> for Float
impl PartialOrd<i128> for Float
Source§fn partial_cmp(&self, other: &i128) -> Option<Ordering>
fn partial_cmp(&self, other: &i128) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<i16> for Float
impl PartialOrd<i16> for Float
Source§fn partial_cmp(&self, other: &i16) -> Option<Ordering>
fn partial_cmp(&self, other: &i16) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<i32> for Float
impl PartialOrd<i32> for Float
Source§fn partial_cmp(&self, other: &i32) -> Option<Ordering>
fn partial_cmp(&self, other: &i32) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<i64> for Float
impl PartialOrd<i64> for Float
Source§fn partial_cmp(&self, other: &i64) -> Option<Ordering>
fn partial_cmp(&self, other: &i64) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<i8> for Float
impl PartialOrd<i8> for Float
Source§fn partial_cmp(&self, other: &i8) -> Option<Ordering>
fn partial_cmp(&self, other: &i8) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<isize> for Float
impl PartialOrd<isize> for Float
Source§fn partial_cmp(&self, other: &isize) -> Option<Ordering>
fn partial_cmp(&self, other: &isize) -> Option<Ordering>
Compares a Float
to a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<u128> for Float
impl PartialOrd<u128> for Float
Source§fn partial_cmp(&self, other: &u128) -> Option<Ordering>
fn partial_cmp(&self, other: &u128) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<u16> for Float
impl PartialOrd<u16> for Float
Source§fn partial_cmp(&self, other: &u16) -> Option<Ordering>
fn partial_cmp(&self, other: &u16) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<u32> for Float
impl PartialOrd<u32> for Float
Source§fn partial_cmp(&self, other: &u32) -> Option<Ordering>
fn partial_cmp(&self, other: &u32) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<u64> for Float
impl PartialOrd<u64> for Float
Source§fn partial_cmp(&self, other: &u64) -> Option<Ordering>
fn partial_cmp(&self, other: &u64) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<u8> for Float
impl PartialOrd<u8> for Float
Source§fn partial_cmp(&self, other: &u8) -> Option<Ordering>
fn partial_cmp(&self, other: &u8) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd<usize> for Float
impl PartialOrd<usize> for Float
Source§fn partial_cmp(&self, other: &usize) -> Option<Ordering>
fn partial_cmp(&self, other: &usize) -> Option<Ordering>
Compares a Float
to an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ is greater than any
primitive integer, and $-\infty$ is less. Both the Float
zero and the Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§impl PartialOrd for Float
impl PartialOrd for Float
Source§fn partial_cmp(&self, other: &Float) -> Option<Ordering>
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Compares two Float
s.
This implementation follows the IEEE 754 standard. NaN
is not comparable to anything, not
even itself. Positive zero is equal to negative zero. Float
s with different precisions
are equal if they represent the same numeric value.
For different comparison behavior that provides a total order, consider using
ComparableFloat
or ComparableFloatRef
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero,
};
use malachite_float::Float;
use std::cmp::Ordering::*;
assert_eq!(Float::NAN.partial_cmp(&Float::NAN), None);
assert_eq!(Float::ZERO.partial_cmp(&Float::NEGATIVE_ZERO), Some(Equal));
assert_eq!(Float::ONE.partial_cmp(&Float::one_prec(100)), Some(Equal));
assert!(Float::INFINITY > Float::ONE);
assert!(Float::NEGATIVE_INFINITY < Float::ONE);
assert!(Float::ONE_HALF < Float::ONE);
assert!(Float::ONE_HALF > Float::NEGATIVE_ONE);
Source§impl PartialOrdAbs<Float> for Integer
impl PartialOrdAbs<Float> for Integer
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an Integer
and a Float
.
No Integer
is comparable to NaN. Every Integer
is smaller in absolute value than
$\infty$ and $-\infty$. The Integer
zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Integer::from(100).gt_abs(&Float::from(80)));
assert!(Integer::from(100).lt_abs(&Float::INFINITY));
assert!(Integer::from(-100).lt_abs(&Float::INFINITY));
assert!(Integer::from(-100).lt_abs(&Float::NEGATIVE_INFINITY));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for Natural
impl PartialOrdAbs<Float> for Natural
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares a Natural
to the absolute value of a Float
.
No Natural
is comparable to NaN. Every Natural
is smaller in absolute value than
$\infty$ and $-\infty$. The Natural
zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Natural::from(100u32).gt_abs(&Float::from(80)));
assert!(Natural::from(100u32).lt_abs(&Float::INFINITY));
assert!(Natural::from(100u32).lt_abs(&Float::NEGATIVE_INFINITY));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for Rational
impl PartialOrdAbs<Float> for Rational
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a Rational
and a Float
.
No Rational
is comparable to NaN. Every Rational
is smaller in absolute value than
$\infty$ and $-\infty$. The Rational
zero is equal to both the Float
zero and the
Float
negative zero.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_q::Rational;
assert!(Rational::from(100).gt_abs(&Float::from(80)));
assert!(Rational::from(-100).gt_abs(&Float::from(-80)));
assert!(Rational::from(100).lt_abs(&Float::INFINITY));
assert!(Rational::from(-100).lt_abs(&Float::NEGATIVE_INFINITY));
assert!(Rational::from_unsigneds(1u8, 3).gt_abs(&Float::from(1.0f64 / 3.0)));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for f32
impl PartialOrdAbs<Float> for f32
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a primitive float and a Float
.
The primitive float NaN is not comparable to any primitive float, not even the
Float
NaN. Every primitive float zero is equal to every Float
zero,
regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for f64
impl PartialOrdAbs<Float> for f64
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a primitive float and a Float
.
The primitive float NaN is not comparable to any primitive float, not even the
Float
NaN. Every primitive float zero is equal to every Float
zero,
regardless of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for i128
impl PartialOrdAbs<Float> for i128
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for i16
impl PartialOrdAbs<Float> for i16
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for i32
impl PartialOrdAbs<Float> for i32
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for i64
impl PartialOrdAbs<Float> for i64
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for i8
impl PartialOrdAbs<Float> for i8
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for isize
impl PartialOrdAbs<Float> for isize
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of a signed primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for u128
impl PartialOrdAbs<Float> for u128
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for u16
impl PartialOrdAbs<Float> for u16
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for u32
impl PartialOrdAbs<Float> for u32
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for u64
impl PartialOrdAbs<Float> for u64
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for u8
impl PartialOrdAbs<Float> for u8
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Float> for usize
impl PartialOrdAbs<Float> for usize
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of an unsigned primitive integer and a Float
.
No primitive integer is comparable to NaN. Every primitive integer is smaller in
absolute value than $\infty$ and $-\infty$. The integer zero is equal to both the
Float
zero and the Float
negative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Integer> for Float
impl PartialOrdAbs<Integer> for Float
Source§fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>
Compares the absolute values of a Float
and an Integer
.
NaN is not comparable to any Integer
. $\infty$ and $-\infty$ are greater in absolute
value than any Integer
. Both the Float
zero and the Float
negative zero are
equal to the Integer
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert!(Float::from(80).lt_abs(&Integer::from(100)));
assert!(Float::from(-80).lt_abs(&Integer::from(-100)));
assert!(Float::INFINITY.gt_abs(&Integer::from(100)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Integer::from(-100)));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Natural> for Float
impl PartialOrdAbs<Natural> for Float
Source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares the absolute value of a Float
to a Natural
.
NaN is not comparable to any Natural
. $\infty$ and $-\infty$ are greater in absolute
value than any Natural
. Both the Float
zero and the Float
negative zero are
equal to the Natural
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert!(Float::from(80).lt_abs(&Natural::from(100u32)));
assert!(Float::INFINITY.gt_abs(&Natural::from(100u32)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Natural::from(100u32)));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<Rational> for Float
impl PartialOrdAbs<Rational> for Float
Source§fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>
Compares the absolute values of a Float
and a Rational
.
NaN is not comparable to any Rational
. $\infty$ and $-\infty$ are greater in absolute
value than any Rational
. Both the Float
zero and the Float
negative zero are
equal to the Rational
zero.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use malachite_q::Rational;
assert!(Float::from(80).lt_abs(&Rational::from(100)));
assert!(Float::from(-80).lt_abs(&Rational::from(-100)));
assert!(Float::INFINITY.gt_abs(&Rational::from(100)));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Rational::from(-100)));
assert!(Float::from(1.0f64 / 3.0).lt_abs(&Rational::from_unsigneds(1u8, 3)));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<f32> for Float
impl PartialOrdAbs<f32> for Float
Source§fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>
Compares the absolute values of a Float
and a primitive float.
The Float
NaN is not comparable to any primitive float, not even the primitive
float NaN. Every Float
zero is equal to every primitive float zero, regardless
of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<f64> for Float
impl PartialOrdAbs<f64> for Float
Source§fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>
Compares the absolute values of a Float
and a primitive float.
The Float
NaN is not comparable to any primitive float, not even the primitive
float NaN. Every Float
zero is equal to every primitive float zero, regardless
of sign.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is
max(self.significant_bits(), other.sci_exponent().abs())
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<i128> for Float
impl PartialOrdAbs<i128> for Float
Source§fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<i16> for Float
impl PartialOrdAbs<i16> for Float
Source§fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<i32> for Float
impl PartialOrdAbs<i32> for Float
Source§fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<i64> for Float
impl PartialOrdAbs<i64> for Float
Source§fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<i8> for Float
impl PartialOrdAbs<i8> for Float
Source§fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<isize> for Float
impl PartialOrdAbs<isize> for Float
Source§fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>
Compares the absolute values of a Float
and a signed primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<u128> for Float
impl PartialOrdAbs<u128> for Float
Source§fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<u16> for Float
impl PartialOrdAbs<u16> for Float
Source§fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<u32> for Float
impl PartialOrdAbs<u32> for Float
Source§fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<u64> for Float
impl PartialOrdAbs<u64> for Float
Source§fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<u8> for Float
impl PartialOrdAbs<u8> for Float
Source§fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs<usize> for Float
impl PartialOrdAbs<usize> for Float
Source§fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>
Compares the absolute values of a Float
and an unsigned primitive integer.
NaN is not comparable to any primitive integer. $\infty$ and $-\infty$ are greater
in absolute value than any primitive integer. Both the Float
zero and the
Float
negative zero are equal to the integer zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PartialOrdAbs for Float
impl PartialOrdAbs for Float
Source§fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Float) -> Option<Ordering>
Compares the absolute values of two Float
s.
This implementation follows the IEEE 754 standard. NaN
is not comparable to anything, not
even itself. Float
s with different precisions are equal if they represent the same
numeric value.
For different comparison behavior that provides a total order, consider using
ComparableFloat
or ComparableFloatRef
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeOne, NegativeZero, One, OneHalf, Zero,
};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_float::Float;
use std::cmp::Ordering::*;
assert_eq!(Float::NAN.partial_cmp_abs(&Float::NAN), None);
assert_eq!(
Float::ZERO.partial_cmp_abs(&Float::NEGATIVE_ZERO),
Some(Equal)
);
assert_eq!(
Float::ONE.partial_cmp_abs(&Float::one_prec(100)),
Some(Equal)
);
assert!(Float::INFINITY.gt_abs(&Float::ONE));
assert!(Float::NEGATIVE_INFINITY.gt_abs(&Float::ONE));
assert!(Float::ONE_HALF.lt_abs(&Float::ONE));
assert!(Float::ONE_HALF.lt_abs(&Float::NEGATIVE_ONE));
Source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
Source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
Source§impl PowerOf2<i64> for Float
impl PowerOf2<i64> for Float
Source§fn power_of_2(pow: i64) -> Float
fn power_of_2(pow: i64) -> Float
Raises 2 to an integer power, returning a Float
with precision 1.
To get a Float
with a higher precision, try Float::power_of_2_prec
.
$f(k) = 2^k$.
If pow
is greater than $2^{30}-2$, $\infty$ is returned. If pow
is less than $-2^{30}$,
positive zero is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_float::Float;
assert_eq!(Float::power_of_2(0i64).to_string(), "1.0");
assert_eq!(Float::power_of_2(3i64).to_string(), "8.0");
assert_eq!(Float::power_of_2(100i64).to_string(), "1.0e30");
assert_eq!(Float::power_of_2(-3i64).to_string(), "0.1");
assert_eq!(Float::power_of_2(-100i64).to_string(), "8.0e-31");
assert_eq!(
Float::power_of_2(i64::power_of_2(30) - 1).to_string(),
"Infinity"
);
assert_eq!(
Float::power_of_2(-i64::power_of_2(30) - 1).to_string(),
"0.0"
);
Source§impl PowerOf2<u64> for Float
impl PowerOf2<u64> for Float
Source§fn power_of_2(pow: u64) -> Float
fn power_of_2(pow: u64) -> Float
Raises 2 to an integer power, returning a Float
with precision 1.
To get a Float
with a higher precision, try Float::power_of_2_prec
.
$f(k) = 2^k$.
If pow
is greater than $2^{30}-2$, $\infty$ is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_float::Float;
assert_eq!(Float::power_of_2(0u64).to_string(), "1.0");
assert_eq!(Float::power_of_2(3u64).to_string(), "8.0");
assert_eq!(Float::power_of_2(100u64).to_string(), "1.0e30");
assert_eq!(
Float::power_of_2(u64::power_of_2(30) - 1).to_string(),
"Infinity"
);
Source§impl RawMantissaAndExponent<Natural, i32> for Float
impl RawMantissaAndExponent<Natural, i32> for Float
Source§fn raw_mantissa_and_exponent(self) -> (Natural, i32)
fn raw_mantissa_and_exponent(self) -> (Natural, i32)
Returns the raw mantissa and exponent of a Float
, taking the Float
by value.
The raw exponent and raw mantissa are the actual bit patterns used to represent the
components of self
. When self
is finite and nonzero, the raw mantissa is an integer
whose number of significant bits is a multiple of the limb width, and which is equal to the
absolute value of self
multiplied by some integer power of 2. The raw exponent is one more
than the floor of the base-2 logarithm of the absolute value of self
.
The inverse operation is Self::from_raw_mantissa_and_exponent
.
The raw exponent is in the range $[-(2^{30}-1), 2^{30}-1]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not finite or not zero.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, RawMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
if Limb::WIDTH == u64::WIDTH {
let (m, e) = Float::ONE.raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "9223372036854775808");
assert_eq!(e, 1);
let (m, e) = Float::from(std::f64::consts::PI).raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "14488038916154245120");
assert_eq!(e, 2);
let (m, e) =
Float::exact_from(Natural::from(3u32).pow(50u64)).raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "202070319366191015160784900114134073344");
assert_eq!(e, 80);
let (m, e) = Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "286514342137199872022965541161805021184");
assert_eq!(e, -79);
}
Source§fn raw_exponent(self) -> i32
fn raw_exponent(self) -> i32
Returns the raw exponent of a Float
, taking the Float
by value.
The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of
self
.
The raw exponent is in the range $[-(2^{30}-1), 2^{30}-1]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not finite or not zero.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, RawMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(Float::ONE.raw_exponent(), 1);
assert_eq!(Float::from(std::f64::consts::PI).raw_exponent(), 2);
assert_eq!(
Float::exact_from(Natural::from(3u32).pow(50u64)).raw_exponent(),
80
);
assert_eq!(
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.raw_exponent(),
-79
);
Source§fn from_raw_mantissa_and_exponent(
raw_mantissa: Natural,
raw_exponent: i32,
) -> Float
fn from_raw_mantissa_and_exponent( raw_mantissa: Natural, raw_exponent: i32, ) -> Float
Constructs a Float
from its raw mantissa and exponent. The resulting Float
is
positive and has the smallest precision possible.
The number of significant bits of the raw mantissa must be divisible by the limb width. The raw exponent must be in the range $[-(2^{30}-1), 2^{30}-1]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if raw_mantissa
is zero, if its number of significant bits is not divisible by the
limb width, or if raw_exponent
is out of range.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
use std::str::FromStr;
if Limb::WIDTH == u64::WIDTH {
assert_eq!(
Float::from_raw_mantissa_and_exponent(Natural::from(9223372036854775808u64), 1),
1
);
assert_eq!(
Float::from_raw_mantissa_and_exponent(Natural::from(14488038916154245120u64), 2),
std::f64::consts::PI
);
assert_eq!(
Float::from_raw_mantissa_and_exponent(
Natural::from_str("202070319366191015160784900114134073344").unwrap(),
80
),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
Float::from_raw_mantissa_and_exponent(
Natural::from_str("286514342137199872022965541161805021184").unwrap(),
-79
),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
}
Source§fn raw_mantissa(self) -> M
fn raw_mantissa(self) -> M
Source§impl RawMantissaAndExponent<Natural, i32, Float> for &Float
impl RawMantissaAndExponent<Natural, i32, Float> for &Float
Source§fn raw_mantissa_and_exponent(self) -> (Natural, i32)
fn raw_mantissa_and_exponent(self) -> (Natural, i32)
Returns the raw mantissa and exponent of a Float
, taking the Float
by reference.
The raw exponent and raw mantissa are the actual bit patterns used to represent the
components of self
. When self
is finite and nonzero, the raw mantissa is an integer
whose number of significant bits is a multiple of the limb width, and which is equal to the
absolute value of self
multiplied by some integer power of 2. The raw exponent is one more
than the floor of the base-2 logarithm of the absolute value of self
.
The raw exponent is in the range $[-(2^{30}-1), 2^{30}-1]$.
The inverse operation is Float::from_raw_mantissa_and_exponent
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.significant_bits()
.
§Panics
Panics if the Float
is not finite or not zero.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, RawMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
if Limb::WIDTH == u64::WIDTH {
let (m, e) = (&Float::ONE).raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "9223372036854775808");
assert_eq!(e, 1);
let (m, e) = (&Float::from(std::f64::consts::PI)).raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "14488038916154245120");
assert_eq!(e, 2);
let (m, e) =
(&Float::exact_from(Natural::from(3u32).pow(50u64))).raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "202070319366191015160784900114134073344");
assert_eq!(e, 80);
let (m, e) = (&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
.raw_mantissa_and_exponent();
assert_eq!(m.to_string(), "286514342137199872022965541161805021184");
assert_eq!(e, -79);
}
Source§fn raw_exponent(self) -> i32
fn raw_exponent(self) -> i32
Returns the raw exponent of a Float
, taking the Float
by reference.
The raw exponent is one more than the floor of the base-2 logarithm of the absolute value of
self
.
The raw exponent is in the range $[-(2^{30}-1), 2^{30}-1]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not finite or not zero.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, RawMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!((&Float::ONE).raw_exponent(), 1);
assert_eq!((&Float::from(std::f64::consts::PI)).raw_exponent(), 2);
assert_eq!(
(&Float::exact_from(Natural::from(3u32).pow(50u64))).raw_exponent(),
80
);
assert_eq!(
(&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0).raw_exponent(),
-79
);
Source§fn from_raw_mantissa_and_exponent(
raw_mantissa: Natural,
raw_exponent: i32,
) -> Float
fn from_raw_mantissa_and_exponent( raw_mantissa: Natural, raw_exponent: i32, ) -> Float
Constructs a Float
from its raw mantissa and exponent. The resulting Float
is
positive and has the smallest precision possible.
§Worst-case complexity
Constant time and additional memory.
The number of significant bits of the raw mantissa must be divisible by the limb width. The raw exponent must be in the range $[-(2^{30}-1), 2^{30}-1]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if raw_mantissa
is zero, if its number of significant bits is not divisible by the
limb width, or if raw_exponent
is out of range.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::conversion::traits::RawMantissaAndExponent;
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
use malachite_q::Rational;
use std::str::FromStr;
if Limb::WIDTH == u64::WIDTH {
assert_eq!(
<&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
Natural::from(9223372036854775808u64),
1
),
1
);
assert_eq!(
<&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
Natural::from(14488038916154245120u64),
2
),
std::f64::consts::PI
);
assert_eq!(
<&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
Natural::from_str("202070319366191015160784900114134073344").unwrap(),
80
),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
<&Float as RawMantissaAndExponent<_, _, _>>::from_raw_mantissa_and_exponent(
Natural::from_str("286514342137199872022965541161805021184").unwrap(),
-79
),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
}
Source§fn raw_mantissa(self) -> M
fn raw_mantissa(self) -> M
Source§impl Reciprocal for &Float
impl Reciprocal for &Float
Source§fn reciprocal(self) -> Float
fn reciprocal(self) -> Float
Takes the reciprocal of a Float
, taking it by reference.
If the output has a precision, it is the precision of the input. If the reciprocal is
equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\infty)=0.0$
- $f(-\infty)=-0.0$
- $f(0.0)=\infty$
- $f(-0.0)=-\infty$
If you want to use a rounding mode other than Nearest
, consider using
Float::reciprocal_prec_ref
instead. If you want to specify the output precision,
consider using Float::reciprocal_round_ref
. If you want both of these things, consider
using Float::reciprocal_prec_round_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Reciprocal;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::NAN).reciprocal().is_nan());
assert_eq!((&Float::INFINITY).reciprocal().to_string(), "0.0");
assert_eq!((&Float::NEGATIVE_INFINITY).reciprocal().to_string(), "-0.0");
assert_eq!((&Float::from(1.5)).reciprocal().to_string(), "0.8");
assert_eq!((&Float::from(-1.5)).reciprocal().to_string(), "-0.8");
type Output = Float
Source§impl Reciprocal for Float
impl Reciprocal for Float
Source§fn reciprocal(self) -> Float
fn reciprocal(self) -> Float
Takes the reciprocal of a Float
, taking it by value.
If the output has a precision, it is the precision of the input. If the reciprocal is
equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\infty)=0.0$
- $f(-\infty)=-0.0$
- $f(0.0)=\infty$
- $f(-0.0)=-\infty$
If you want to use a rounding mode other than Nearest
, consider using
Float::reciprocal_prec
instead. If you want to specify the output precision, consider
using Float::reciprocal_round
. If you want both of these things, consider using
Float::reciprocal_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Reciprocal;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!(Float::NAN.reciprocal().is_nan());
assert_eq!(Float::INFINITY.reciprocal().to_string(), "0.0");
assert_eq!(Float::NEGATIVE_INFINITY.reciprocal().to_string(), "-0.0");
assert_eq!(Float::from(1.5).reciprocal().to_string(), "0.8");
assert_eq!(Float::from(-1.5).reciprocal().to_string(), "-0.8");
type Output = Float
Source§impl ReciprocalAssign for Float
impl ReciprocalAssign for Float
Source§fn reciprocal_assign(&mut self)
fn reciprocal_assign(&mut self)
Takes the reciprocal of a Float
in place.
If the output has a precision, it is the precision of the input. If the reciprocal is
equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the Float::reciprocal
documentation for information on special cases.
If you want to use a rounding mode other than Nearest
, consider using
Float::reciprocal_prec_assign
instead. If you want to specify the output precision,
consider using Float::reciprocal_round_assign
. If you want both of these things,
consider using Float::reciprocal_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::ReciprocalAssign;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
let mut x = Float::NAN;
x.reciprocal_assign();
assert!(x.is_nan());
let mut x = Float::INFINITY;
x.reciprocal_assign();
assert_eq!(x.to_string(), "0.0");
let mut x = Float::NEGATIVE_INFINITY;
x.reciprocal_assign();
assert_eq!(x.to_string(), "-0.0");
let mut x = Float::from(1.5);
x.reciprocal_assign();
assert_eq!(x.to_string(), "0.8");
let mut x = Float::from(-1.5);
x.reciprocal_assign();
assert_eq!(x.to_string(), "-0.8");
Source§impl RoundingFrom<&Float> for Integer
impl RoundingFrom<&Float> for Integer
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (Integer, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (Integer, Ordering)
Converts a Float
to an Integer
, using a specified RoundingMode
and taking the
Float
by reference. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
If the Float
is NaN or infinite, the function will panic regardless of the rounding
mode.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is NaN or
infinite.
§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(
Integer::rounding_from(&Float::from(1.5), Floor).to_debug_string(),
"(1, Less)"
);
assert_eq!(
Integer::rounding_from(&Float::from(1.5), Ceiling).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Integer::rounding_from(&Float::from(1.5), Nearest).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Integer::rounding_from(&Float::from(-1.5), Floor).to_debug_string(),
"(-2, Less)"
);
assert_eq!(
Integer::rounding_from(&Float::from(-1.5), Ceiling).to_debug_string(),
"(-1, Greater)"
);
assert_eq!(
Integer::rounding_from(&Float::from(-1.5), Nearest).to_debug_string(),
"(-2, Less)"
);
Source§impl RoundingFrom<&Float> for Natural
impl RoundingFrom<&Float> for Natural
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (Natural, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (Natural, Ordering)
Converts a Float
to a Natural
, using a specified RoundingMode
and taking the
Float
by reference. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero when the
RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is NaN or $\infty$, the function will panic regardless of the rounding
mode.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less
than zero and rm
is not Down
, Ceiling
, or Nearest
, or if the Float
is NaN or
$\infty$.
§Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::rounding_from(&Float::from(1.5), Floor).to_debug_string(),
"(1, Less)"
);
assert_eq!(
Natural::rounding_from(&Float::from(1.5), Ceiling).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Natural::rounding_from(&Float::from(1.5), Nearest).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Natural::rounding_from(&Float::NEGATIVE_INFINITY, Down).to_debug_string(),
"(0, Greater)"
);
assert_eq!(
Natural::rounding_from(&Float::NEGATIVE_INFINITY, Ceiling).to_debug_string(),
"(0, Greater)"
);
assert_eq!(
Natural::rounding_from(&Float::NEGATIVE_INFINITY, Nearest).to_debug_string(),
"(0, Greater)"
);
Source§impl RoundingFrom<&Float> for f32
impl RoundingFrom<&Float> for f32
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (f32, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (f32, Ordering)
Converts a Float
to a primitive float, using a specified RoundingMode
and
taking the Float
by reference. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original
value. (Although a NaN is not comparable to any Float
, converting a NaN to a NaN
will also return Equal
, indicating an exact conversion.)
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not exactly equal to any float of the target type, and
rm
is Exact
.
§Examples
See here.
Source§impl RoundingFrom<&Float> for f64
impl RoundingFrom<&Float> for f64
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (f64, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (f64, Ordering)
Converts a Float
to a primitive float, using a specified RoundingMode
and
taking the Float
by reference. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original
value. (Although a NaN is not comparable to any Float
, converting a NaN to a NaN
will also return Equal
, indicating an exact conversion.)
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not exactly equal to any float of the target type, and
rm
is Exact
.
§Examples
See here.
Source§impl RoundingFrom<&Float> for i128
impl RoundingFrom<&Float> for i128
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (i128, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (i128, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for i16
impl RoundingFrom<&Float> for i16
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (i16, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (i16, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for i32
impl RoundingFrom<&Float> for i32
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (i32, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (i32, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for i64
impl RoundingFrom<&Float> for i64
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (i64, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (i64, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for i8
impl RoundingFrom<&Float> for i8
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (i8, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (i8, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for isize
impl RoundingFrom<&Float> for isize
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (isize, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (isize, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for u128
impl RoundingFrom<&Float> for u128
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (u128, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (u128, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for u16
impl RoundingFrom<&Float> for u16
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (u16, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (u16, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for u32
impl RoundingFrom<&Float> for u32
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (u32, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (u32, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for u64
impl RoundingFrom<&Float> for u64
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (u64, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (u64, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for u8
impl RoundingFrom<&Float> for u8
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (u8, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (u8, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<&Float> for usize
impl RoundingFrom<&Float> for usize
Source§fn rounding_from(f: &Float, rm: RoundingMode) -> (usize, Ordering)
fn rounding_from(f: &Float, rm: RoundingMode) -> (usize, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by reference. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for Integer
impl RoundingFrom<Float> for Integer
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (Integer, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (Integer, Ordering)
Converts a Float
to an Integer
, using a specified RoundingMode
and taking the
Float
by value. An Ordering
is also returned, indicating whether the returned value
is less than, equal to, or greater than the original value.
If the Float
is NaN or infinite, the function will panic regardless of the rounding
mode.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is NaN or
infinite.
§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(
Integer::rounding_from(Float::from(1.5), Floor).to_debug_string(),
"(1, Less)"
);
assert_eq!(
Integer::rounding_from(Float::from(1.5), Ceiling).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Integer::rounding_from(Float::from(1.5), Nearest).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Integer::rounding_from(Float::from(-1.5), Floor).to_debug_string(),
"(-2, Less)"
);
assert_eq!(
Integer::rounding_from(Float::from(-1.5), Ceiling).to_debug_string(),
"(-1, Greater)"
);
assert_eq!(
Integer::rounding_from(Float::from(-1.5), Nearest).to_debug_string(),
"(-2, Less)"
);
Source§impl RoundingFrom<Float> for Natural
impl RoundingFrom<Float> for Natural
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (Natural, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (Natural, Ordering)
Converts a Float
to a Natural
, using a specified RoundingMode
and taking the
Float
by value. An Ordering
is also returned, indicating whether the returned value
is less than, equal to, or greater than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero when the
RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is NaN or $\infty$, the function will panic regardless of the rounding
mode.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less
than zero and rm
is not Down
, Ceiling
, or Nearest
, or if the Float
is NaN or
$\infty$.
§Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::rounding_from(Float::from(1.5), Floor).to_debug_string(),
"(1, Less)"
);
assert_eq!(
Natural::rounding_from(Float::from(1.5), Ceiling).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Natural::rounding_from(Float::from(1.5), Nearest).to_debug_string(),
"(2, Greater)"
);
assert_eq!(
Natural::rounding_from(Float::NEGATIVE_INFINITY, Down).to_debug_string(),
"(0, Greater)"
);
assert_eq!(
Natural::rounding_from(Float::NEGATIVE_INFINITY, Ceiling).to_debug_string(),
"(0, Greater)"
);
assert_eq!(
Natural::rounding_from(Float::NEGATIVE_INFINITY, Nearest).to_debug_string(),
"(0, Greater)"
);
Source§impl RoundingFrom<Float> for f32
impl RoundingFrom<Float> for f32
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (f32, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (f32, Ordering)
Converts a Float
to a primitive float, using a specified RoundingMode
and
taking the Float
by value. An Ordering
is also returned, indicating whether
the returned value is less than, equal to, or greater than the original value.
(Although a NaN is not comparable to any Float
, converting a NaN to a NaN will
also return Equal
, indicating an exact conversion.)
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not exactly equal to any float of the target type, and
rm
is Exact
.
§Examples
See here.
Source§impl RoundingFrom<Float> for f64
impl RoundingFrom<Float> for f64
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (f64, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (f64, Ordering)
Converts a Float
to a primitive float, using a specified RoundingMode
and
taking the Float
by value. An Ordering
is also returned, indicating whether
the returned value is less than, equal to, or greater than the original value.
(Although a NaN is not comparable to any Float
, converting a NaN to a NaN will
also return Equal
, indicating an exact conversion.)
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not exactly equal to any float of the target type, and
rm
is Exact
.
§Examples
See here.
Source§impl RoundingFrom<Float> for i128
impl RoundingFrom<Float> for i128
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (i128, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (i128, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for i16
impl RoundingFrom<Float> for i16
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (i16, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (i16, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for i32
impl RoundingFrom<Float> for i32
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (i32, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (i32, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for i64
impl RoundingFrom<Float> for i64
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (i64, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (i64, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for i8
impl RoundingFrom<Float> for i8
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (i8, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (i8, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for isize
impl RoundingFrom<Float> for isize
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (isize, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (isize, Ordering)
Converts a Float
to a signed primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is less than the minimum representable value of the signed type
(including $-\infty$), then it will be rounded to zero when the RoundingMode
is
Ceiling
, Down
, or Nearest
. Otherwise, this function will panic.
If the Float
is greater than the maximum representable value of the signed type
(including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is smaller than the minimum representable value of the signed type and rm
is not
Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum
representable value of the signed type and rm
is not Down
, Floor
, or
Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for u128
impl RoundingFrom<Float> for u128
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (u128, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (u128, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for u16
impl RoundingFrom<Float> for u16
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (u16, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (u16, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for u32
impl RoundingFrom<Float> for u32
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (u32, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (u32, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for u64
impl RoundingFrom<Float> for u64
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (u64, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (u64, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for u8
impl RoundingFrom<Float> for u8
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (u8, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (u8, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl RoundingFrom<Float> for usize
impl RoundingFrom<Float> for usize
Source§fn rounding_from(f: Float, rm: RoundingMode) -> (usize, Ordering)
fn rounding_from(f: Float, rm: RoundingMode) -> (usize, Ordering)
Converts a Float
to an unsigned primitive integer, using a specified
RoundingMode
and taking the Float
by value. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
If the Float
is negative (including $-\infty$), then it will be rounded to zero
when the RoundingMode
is Ceiling
, Down
, or Nearest
. Otherwise, this
function will panic.
If the Float
is greater than the maximum representable value of the unsigned
type (including $\infty$), then it will be rounded to the maximum value when the
RoundingMode
is Floor
, Down
, or Nearest
. Otherwise, this function will
panic.
If the Float
is NaN, the function will panic regardless of the rounding mode.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the Float
is not an integer and rm
is Exact
, or if the Float
is less than zero and rm
is not Down
, Ceiling
, or Nearest
, if the Float
is greater than the maximum representable value of the unsigned type and rm
is not
Down
, Floor
, or Nearest
, or if the Float
is NaN.
§Examples
See here.
Source§impl SciMantissaAndExponent<Float, i32> for Float
impl SciMantissaAndExponent<Float, i32> for Float
Source§fn sci_mantissa_and_exponent(self) -> (Float, i32)
fn sci_mantissa_and_exponent(self) -> (Float, i32)
Returns a Float
’s scientific mantissa and exponent, taking the Float
by value.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer
and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as
a Float
.
$$
f(x) = (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor).
$$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(Float::ONE.sci_mantissa_and_exponent(), (Float::ONE, 0));
let (m, e) = Float::from(std::f64::consts::PI).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.570796326794897");
assert_eq!(e, 1);
let (m, e) = Float::exact_from(Natural::from(3u32).pow(50u64)).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.187662594419065093441695");
assert_eq!(e, 79);
let (m, e) = Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.683979953059212693885095551367");
assert_eq!(e, -80);
Source§fn sci_exponent(self) -> i32
fn sci_exponent(self) -> i32
Returns a Float
’s scientific exponent, taking the Float
by value.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. $$ f(x) = \lfloor \log_2 |x| \rfloor. $$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(Float::ONE.sci_exponent(), 0);
assert_eq!(Float::from(std::f64::consts::PI).sci_exponent(), 1);
assert_eq!(
Float::exact_from(Natural::from(3u32).pow(50u64)).sci_exponent(),
79
);
assert_eq!(
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100)
.0
.sci_exponent(),
-80
);
Source§fn from_sci_mantissa_and_exponent(
sci_mantissa: Float,
sci_exponent: i32,
) -> Option<Float>
fn from_sci_mantissa_and_exponent( sci_mantissa: Float, sci_exponent: i32, ) -> Option<Float>
Constructs a Float
from its scientific mantissa and exponent.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.
$$ f(x) = 2^{e_i}m_i. $$
If the mantissa is zero or not finite, this function panics. If it is finite but not in the
interval $[1, 2)$, None
is returned. If the inputs correspond to a number too large in
absolute value or too close to zero to be represented by a Float
, None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{FromStringBase, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(
Float::from_sci_mantissa_and_exponent(Float::ONE, 0).unwrap(),
1
);
assert_eq!(
Float::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.921fb54442d18#53").unwrap(),
1
)
.unwrap(),
std::f64::consts::PI
);
assert_eq!(
Float::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.300aa7e1b65fa13bc792#80").unwrap(),
79
)
.unwrap(),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
Float::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.af194f6982497a23f9dc546d6#100").unwrap(),
-80
)
.unwrap(),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
Source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
Source§impl SciMantissaAndExponent<Float, i32, Float> for &Float
impl SciMantissaAndExponent<Float, i32, Float> for &Float
Source§fn sci_mantissa_and_exponent(self) -> (Float, i32)
fn sci_mantissa_and_exponent(self) -> (Float, i32)
Returns a Float
’s scientific mantissa and exponent, taking the Float
by reference.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer
and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as
a Float
.
$$
f(x) = (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}}, \lfloor \log_2 |x| \rfloor).
$$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!((&Float::ONE).sci_mantissa_and_exponent(), (Float::ONE, 0));
let (m, e): (Float, i32) = (&Float::from(std::f64::consts::PI)).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.570796326794897");
assert_eq!(e, 1);
let (m, e): (Float, i32) =
(&Float::exact_from(Natural::from(3u32).pow(50u64))).sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.187662594419065093441695");
assert_eq!(e, 79);
let (m, e): (Float, i32) =
(&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0)
.sci_mantissa_and_exponent();
assert_eq!(m.to_string(), "1.683979953059212693885095551367");
assert_eq!(e, -80);
Source§fn sci_exponent(self) -> i32
fn sci_exponent(self) -> i32
Returns a Float
’s scientific exponent, taking the Float
by reference.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$. $$ f(x) = \lfloor \log_2 |x| \rfloor. $$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is zero or not finite.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{ExactFrom, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(&Float::ONE),
0
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(&Float::from(
std::f64::consts::PI
)),
1
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(&Float::exact_from(
Natural::from(3u32).pow(50u64)
)),
79
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::sci_exponent(
&Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
),
-80
);
Source§fn from_sci_mantissa_and_exponent(
sci_mantissa: Float,
sci_exponent: i32,
) -> Option<Float>
fn from_sci_mantissa_and_exponent( sci_mantissa: Float, sci_exponent: i32, ) -> Option<Float>
Constructs a Float
from its scientific mantissa and exponent.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.
$$ f(x) = 2^{e_i}m_i. $$
If the mantissa is zero or not finite, this function panics. If it is finite but not in the
interval $[1, 2)$, this function returns None
.
If the mantissa is zero or not finite, this function panics. If it is finite but not in the
interval $[1, 2)$, None
is returned. If the inputs correspond to a number too large in
absolute value or too close to zero to be represented by a Float
, None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_base::num::conversion::traits::{FromStringBase, SciMantissaAndExponent};
use malachite_float::Float;
use malachite_nz::natural::Natural;
use malachite_q::Rational;
assert_eq!(
Float::from_sci_mantissa_and_exponent(Float::ONE, 0).unwrap(),
1
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.921fb54442d18#53").unwrap(),
1
)
.unwrap(),
std::f64::consts::PI
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.300aa7e1b65fa13bc792#80").unwrap(),
79
)
.unwrap(),
Natural::from(3u32).pow(50u64)
);
assert_eq!(
<&Float as SciMantissaAndExponent<Float, _, _>>::from_sci_mantissa_and_exponent(
Float::from_string_base(16, "0x1.af194f6982497a23f9dc546d6#100").unwrap(),
-80
)
.unwrap(),
Float::from_rational_prec(Rational::from(3u32).pow(-50i64), 100).0
);
Source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
Source§impl SciMantissaAndExponent<f32, i32, Float> for &Float
impl SciMantissaAndExponent<f32, i32, Float> for &Float
Source§fn sci_mantissa_and_exponent(self) -> (f32, i32)
fn sci_mantissa_and_exponent(self) -> (f32, i32)
Returns a Float
’s scientific mantissa and exponent, taking the Float
by
value.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an
integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the
rational mantissa as a primitive float. The conversion might not be exact, so we
round to the nearest float using the Nearest
rounding mode. To use other rounding
modes, use
sci_mantissa_and_exponent_round
.
$$
f(x) \approx (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}},
\lfloor \log_2 |x| \rfloor).
$$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero or not finite.
§Examples
See here.
Source§fn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: i32,
) -> Option<Float>
fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: i32, ) -> Option<Float>
Constructs a Float
from its scientific mantissa and exponent.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.
$$ f(x) = 2^{e_i}m_i. $$
If the mantissa is zero or not finite, this function panics. If it is finite but not
in the interval $[1, 2)$, None
is returned. If the inputs correspond to a number
too large in absolute value or too close to zero to be represented by a Float
,
None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
Source§fn sci_exponent(self) -> E
fn sci_exponent(self) -> E
Source§impl SciMantissaAndExponent<f64, i32, Float> for &Float
impl SciMantissaAndExponent<f64, i32, Float> for &Float
Source§fn sci_mantissa_and_exponent(self) -> (f64, i32)
fn sci_mantissa_and_exponent(self) -> (f64, i32)
Returns a Float
’s scientific mantissa and exponent, taking the Float
by
value.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an
integer and $m_s$ is a rational number with $1 \leq m_s < 2$. We represent the
rational mantissa as a primitive float. The conversion might not be exact, so we
round to the nearest float using the Nearest
rounding mode. To use other rounding
modes, use
sci_mantissa_and_exponent_round
.
$$
f(x) \approx (\frac{|x|}{2^{\lfloor \log_2 |x| \rfloor}},
\lfloor \log_2 |x| \rfloor).
$$
The returned exponent is always in the range $[-2^{30}, 2^{30}-2]$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero or not finite.
§Examples
See here.
Source§fn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: i32,
) -> Option<Float>
fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: i32, ) -> Option<Float>
Constructs a Float
from its scientific mantissa and exponent.
When $x$ is finite and nonzero, we can write $|x| = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is a rational number with $1 \leq m_s < 2$.
$$ f(x) = 2^{e_i}m_i. $$
If the mantissa is zero or not finite, this function panics. If it is finite but not
in the interval $[1, 2)$, None
is returned. If the inputs correspond to a number
too large in absolute value or too close to zero to be represented by a Float
,
None
is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
Source§fn sci_exponent(self) -> E
fn sci_exponent(self) -> E
Source§impl Shl<i128> for &Float
impl Shl<i128> for &Float
Source§fn shl(self, bits: i128) -> Float
fn shl(self, bits: i128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i128> for Float
impl Shl<i128> for Float
Source§fn shl(self, bits: i128) -> Float
fn shl(self, bits: i128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i16> for &Float
impl Shl<i16> for &Float
Source§fn shl(self, bits: i16) -> Float
fn shl(self, bits: i16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i16> for Float
impl Shl<i16> for Float
Source§fn shl(self, bits: i16) -> Float
fn shl(self, bits: i16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i32> for &Float
impl Shl<i32> for &Float
Source§fn shl(self, bits: i32) -> Float
fn shl(self, bits: i32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i32> for Float
impl Shl<i32> for Float
Source§fn shl(self, bits: i32) -> Float
fn shl(self, bits: i32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i64> for &Float
impl Shl<i64> for &Float
Source§fn shl(self, bits: i64) -> Float
fn shl(self, bits: i64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i64> for Float
impl Shl<i64> for Float
Source§fn shl(self, bits: i64) -> Float
fn shl(self, bits: i64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i8> for &Float
impl Shl<i8> for &Float
Source§fn shl(self, bits: i8) -> Float
fn shl(self, bits: i8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<i8> for Float
impl Shl<i8> for Float
Source§fn shl(self, bits: i8) -> Float
fn shl(self, bits: i8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<isize> for &Float
impl Shl<isize> for &Float
Source§fn shl(self, bits: isize) -> Float
fn shl(self, bits: isize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<isize> for Float
impl Shl<isize> for Float
Source§fn shl(self, bits: isize) -> Float
fn shl(self, bits: isize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u128> for &Float
impl Shl<u128> for &Float
Source§fn shl(self, bits: u128) -> Float
fn shl(self, bits: u128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u128> for Float
impl Shl<u128> for Float
Source§fn shl(self, bits: u128) -> Float
fn shl(self, bits: u128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u16> for &Float
impl Shl<u16> for &Float
Source§fn shl(self, bits: u16) -> Float
fn shl(self, bits: u16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u16> for Float
impl Shl<u16> for Float
Source§fn shl(self, bits: u16) -> Float
fn shl(self, bits: u16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u32> for &Float
impl Shl<u32> for &Float
Source§fn shl(self, bits: u32) -> Float
fn shl(self, bits: u32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u32> for Float
impl Shl<u32> for Float
Source§fn shl(self, bits: u32) -> Float
fn shl(self, bits: u32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u64> for &Float
impl Shl<u64> for &Float
Source§fn shl(self, bits: u64) -> Float
fn shl(self, bits: u64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u64> for Float
impl Shl<u64> for Float
Source§fn shl(self, bits: u64) -> Float
fn shl(self, bits: u64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u8> for &Float
impl Shl<u8> for &Float
Source§fn shl(self, bits: u8) -> Float
fn shl(self, bits: u8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<u8> for Float
impl Shl<u8> for Float
Source§fn shl(self, bits: u8) -> Float
fn shl(self, bits: u8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<usize> for &Float
impl Shl<usize> for &Float
Source§fn shl(self, bits: usize) -> Float
fn shl(self, bits: usize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shl<usize> for Float
impl Shl<usize> for Float
Source§fn shl(self, bits: usize) -> Float
fn shl(self, bits: usize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<i128> for Float
impl ShlAssign<i128> for Float
Source§fn shl_assign(&mut self, bits: i128)
fn shl_assign(&mut self, bits: i128)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<i16> for Float
impl ShlAssign<i16> for Float
Source§fn shl_assign(&mut self, bits: i16)
fn shl_assign(&mut self, bits: i16)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<i32> for Float
impl ShlAssign<i32> for Float
Source§fn shl_assign(&mut self, bits: i32)
fn shl_assign(&mut self, bits: i32)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<i64> for Float
impl ShlAssign<i64> for Float
Source§fn shl_assign(&mut self, bits: i64)
fn shl_assign(&mut self, bits: i64)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<i8> for Float
impl ShlAssign<i8> for Float
Source§fn shl_assign(&mut self, bits: i8)
fn shl_assign(&mut self, bits: i8)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<isize> for Float
impl ShlAssign<isize> for Float
Source§fn shl_assign(&mut self, bits: isize)
fn shl_assign(&mut self, bits: isize)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<u128> for Float
impl ShlAssign<u128> for Float
Source§fn shl_assign(&mut self, bits: u128)
fn shl_assign(&mut self, bits: u128)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<u16> for Float
impl ShlAssign<u16> for Float
Source§fn shl_assign(&mut self, bits: u16)
fn shl_assign(&mut self, bits: u16)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<u32> for Float
impl ShlAssign<u32> for Float
Source§fn shl_assign(&mut self, bits: u32)
fn shl_assign(&mut self, bits: u32)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<u64> for Float
impl ShlAssign<u64> for Float
Source§fn shl_assign(&mut self, bits: u64)
fn shl_assign(&mut self, bits: u64)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<u8> for Float
impl ShlAssign<u8> for Float
Source§fn shl_assign(&mut self, bits: u8)
fn shl_assign(&mut self, bits: u8)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlAssign<usize> for Float
impl ShlAssign<usize> for Float
Source§fn shl_assign(&mut self, bits: usize)
fn shl_assign(&mut self, bits: usize)
Left-shifts a Float
(multiplies it by a power of 2), in place. If the Float
has a precision, the precision is unchanged.
NaN
, infinities, and zeros are unchanged.
$$ x \gets x2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShlRound<i128> for &Float
impl ShlRound<i128> for &Float
Source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i128> for Float
impl ShlRound<i128> for Float
Source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i16> for &Float
impl ShlRound<i16> for &Float
Source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i16> for Float
impl ShlRound<i16> for Float
Source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i32> for &Float
impl ShlRound<i32> for &Float
Source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i32> for Float
impl ShlRound<i32> for Float
Source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i64> for &Float
impl ShlRound<i64> for &Float
Source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i64> for Float
impl ShlRound<i64> for Float
Source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i8> for &Float
impl ShlRound<i8> for &Float
Source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<i8> for Float
impl ShlRound<i8> for Float
Source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<isize> for &Float
impl ShlRound<isize> for &Float
Source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<isize> for Float
impl ShlRound<isize> for Float
Source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u128> for &Float
impl ShlRound<u128> for &Float
Source§fn shl_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u128> for Float
impl ShlRound<u128> for Float
Source§fn shl_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u16> for &Float
impl ShlRound<u16> for &Float
Source§fn shl_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u16> for Float
impl ShlRound<u16> for Float
Source§fn shl_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u32> for &Float
impl ShlRound<u32> for &Float
Source§fn shl_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u32> for Float
impl ShlRound<u32> for Float
Source§fn shl_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u64> for &Float
impl ShlRound<u64> for &Float
Source§fn shl_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u64> for Float
impl ShlRound<u64> for Float
Source§fn shl_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u8> for &Float
impl ShlRound<u8> for &Float
Source§fn shl_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<u8> for Float
impl ShlRound<u8> for Float
Source§fn shl_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<usize> for &Float
impl ShlRound<usize> for &Float
Source§fn shl_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRound<usize> for Float
impl ShlRound<usize> for Float
Source§fn shl_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
fn shl_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
Left-shifts a Float
(multiplies it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShlRoundAssign<i128> for Float
impl ShlRoundAssign<i128> for Float
Source§fn shl_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<i16> for Float
impl ShlRoundAssign<i16> for Float
Source§fn shl_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<i32> for Float
impl ShlRoundAssign<i32> for Float
Source§fn shl_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<i64> for Float
impl ShlRoundAssign<i64> for Float
Source§fn shl_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<i8> for Float
impl ShlRoundAssign<i8> for Float
Source§fn shl_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<isize> for Float
impl ShlRoundAssign<isize> for Float
Source§fn shl_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<u128> for Float
impl ShlRoundAssign<u128> for Float
Source§fn shl_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<u16> for Float
impl ShlRoundAssign<u16> for Float
Source§fn shl_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<u32> for Float
impl ShlRoundAssign<u32> for Float
Source§fn shl_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<u64> for Float
impl ShlRoundAssign<u64> for Float
Source§fn shl_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<u8> for Float
impl ShlRoundAssign<u8> for Float
Source§fn shl_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShlRoundAssign<usize> for Float
impl ShlRoundAssign<usize> for Float
Source§fn shl_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use <<=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl Shr<i128> for &Float
impl Shr<i128> for &Float
Source§fn shr(self, bits: i128) -> Float
fn shr(self, bits: i128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i128> for Float
impl Shr<i128> for Float
Source§fn shr(self, bits: i128) -> Float
fn shr(self, bits: i128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i16> for &Float
impl Shr<i16> for &Float
Source§fn shr(self, bits: i16) -> Float
fn shr(self, bits: i16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i16> for Float
impl Shr<i16> for Float
Source§fn shr(self, bits: i16) -> Float
fn shr(self, bits: i16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i32> for &Float
impl Shr<i32> for &Float
Source§fn shr(self, bits: i32) -> Float
fn shr(self, bits: i32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i32> for Float
impl Shr<i32> for Float
Source§fn shr(self, bits: i32) -> Float
fn shr(self, bits: i32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i64> for &Float
impl Shr<i64> for &Float
Source§fn shr(self, bits: i64) -> Float
fn shr(self, bits: i64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i64> for Float
impl Shr<i64> for Float
Source§fn shr(self, bits: i64) -> Float
fn shr(self, bits: i64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i8> for &Float
impl Shr<i8> for &Float
Source§fn shr(self, bits: i8) -> Float
fn shr(self, bits: i8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<i8> for Float
impl Shr<i8> for Float
Source§fn shr(self, bits: i8) -> Float
fn shr(self, bits: i8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<isize> for &Float
impl Shr<isize> for &Float
Source§fn shr(self, bits: isize) -> Float
fn shr(self, bits: isize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<isize> for Float
impl Shr<isize> for Float
Source§fn shr(self, bits: isize) -> Float
fn shr(self, bits: isize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u128> for &Float
impl Shr<u128> for &Float
Source§fn shr(self, bits: u128) -> Float
fn shr(self, bits: u128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u128> for Float
impl Shr<u128> for Float
Source§fn shr(self, bits: u128) -> Float
fn shr(self, bits: u128) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u16> for &Float
impl Shr<u16> for &Float
Source§fn shr(self, bits: u16) -> Float
fn shr(self, bits: u16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u16> for Float
impl Shr<u16> for Float
Source§fn shr(self, bits: u16) -> Float
fn shr(self, bits: u16) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u32> for &Float
impl Shr<u32> for &Float
Source§fn shr(self, bits: u32) -> Float
fn shr(self, bits: u32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u32> for Float
impl Shr<u32> for Float
Source§fn shr(self, bits: u32) -> Float
fn shr(self, bits: u32) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u64> for &Float
impl Shr<u64> for &Float
Source§fn shr(self, bits: u64) -> Float
fn shr(self, bits: u64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u64> for Float
impl Shr<u64> for Float
Source§fn shr(self, bits: u64) -> Float
fn shr(self, bits: u64) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u8> for &Float
impl Shr<u8> for &Float
Source§fn shr(self, bits: u8) -> Float
fn shr(self, bits: u8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<u8> for Float
impl Shr<u8> for Float
Source§fn shr(self, bits: u8) -> Float
fn shr(self, bits: u8) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<usize> for &Float
impl Shr<usize> for &Float
Source§fn shr(self, bits: usize) -> Float
fn shr(self, bits: usize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl Shr<usize> for Float
impl Shr<usize> for Float
Source§fn shr(self, bits: usize) -> Float
fn shr(self, bits: usize) -> Float
Left-shifts a Float
(multiplies it by a power of 2), taking it by value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x, k) = x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<i128> for Float
impl ShrAssign<i128> for Float
Source§fn shr_assign(&mut self, bits: i128)
fn shr_assign(&mut self, bits: i128)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<i16> for Float
impl ShrAssign<i16> for Float
Source§fn shr_assign(&mut self, bits: i16)
fn shr_assign(&mut self, bits: i16)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<i32> for Float
impl ShrAssign<i32> for Float
Source§fn shr_assign(&mut self, bits: i32)
fn shr_assign(&mut self, bits: i32)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<i64> for Float
impl ShrAssign<i64> for Float
Source§fn shr_assign(&mut self, bits: i64)
fn shr_assign(&mut self, bits: i64)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<i8> for Float
impl ShrAssign<i8> for Float
Source§fn shr_assign(&mut self, bits: i8)
fn shr_assign(&mut self, bits: i8)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<isize> for Float
impl ShrAssign<isize> for Float
Source§fn shr_assign(&mut self, bits: isize)
fn shr_assign(&mut self, bits: isize)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<u128> for Float
impl ShrAssign<u128> for Float
Source§fn shr_assign(&mut self, bits: u128)
fn shr_assign(&mut self, bits: u128)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<u16> for Float
impl ShrAssign<u16> for Float
Source§fn shr_assign(&mut self, bits: u16)
fn shr_assign(&mut self, bits: u16)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<u32> for Float
impl ShrAssign<u32> for Float
Source§fn shr_assign(&mut self, bits: u32)
fn shr_assign(&mut self, bits: u32)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<u64> for Float
impl ShrAssign<u64> for Float
Source§fn shr_assign(&mut self, bits: u64)
fn shr_assign(&mut self, bits: u64)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<u8> for Float
impl ShrAssign<u8> for Float
Source§fn shr_assign(&mut self, bits: u8)
fn shr_assign(&mut self, bits: u8)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrAssign<usize> for Float
impl ShrAssign<usize> for Float
Source§fn shr_assign(&mut self, bits: usize)
fn shr_assign(&mut self, bits: usize)
Left-shifts a Float
(multiplies it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x \gets x/2^k. $$
- If $f(x,k)\geq 2^{2^{30}-1}$, $\infty$ is assigned instead.
- If $f(x,k)\leq -2^{2^{30}-1}$, $-\infty$ is assigned instead.
- If $0<f(x,k)\leq2^{-2^{30}-1}$, $0.0$ is assigned instead.
- If $2^{-2^{30}-1}<f(x,k)<2^{-2^{30}}$, $2^{-2^{30}}$ is assigned instead.
- If $-2^{-2^{30}-1}\leq f(x,k)<0$, $-0.0$ is assigned instead.
- If $-2^{-2^{30}}<f(x,k)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is assigned instead.
Constant time and additional memory.
§Examples
See here.
Source§impl ShrRound<i128> for &Float
impl ShrRound<i128> for &Float
Source§fn shr_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i128> for Float
impl ShrRound<i128> for Float
Source§fn shr_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i128, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i16> for &Float
impl ShrRound<i16> for &Float
Source§fn shr_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i16> for Float
impl ShrRound<i16> for Float
Source§fn shr_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i16, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i32> for &Float
impl ShrRound<i32> for &Float
Source§fn shr_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i32> for Float
impl ShrRound<i32> for Float
Source§fn shr_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i32, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i64> for &Float
impl ShrRound<i64> for &Float
Source§fn shr_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i64> for Float
impl ShrRound<i64> for Float
Source§fn shr_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i64, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i8> for &Float
impl ShrRound<i8> for &Float
Source§fn shr_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<i8> for Float
impl ShrRound<i8> for Float
Source§fn shr_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: i8, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<isize> for &Float
impl ShrRound<isize> for &Float
Source§fn shr_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<isize> for Float
impl ShrRound<isize> for Float
Source§fn shr_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: isize, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u128> for &Float
impl ShrRound<u128> for &Float
Source§fn shr_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u128> for Float
impl ShrRound<u128> for Float
Source§fn shr_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u128, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u16> for &Float
impl ShrRound<u16> for &Float
Source§fn shr_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u16> for Float
impl ShrRound<u16> for Float
Source§fn shr_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u16, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u32> for &Float
impl ShrRound<u32> for &Float
Source§fn shr_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u32> for Float
impl ShrRound<u32> for Float
Source§fn shr_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u32, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u64> for &Float
impl ShrRound<u64> for &Float
Source§fn shr_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u64> for Float
impl ShrRound<u64> for Float
Source§fn shr_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u64, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u8> for &Float
impl ShrRound<u8> for &Float
Source§fn shr_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<u8> for Float
impl ShrRound<u8> for Float
Source§fn shr_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: u8, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<usize> for &Float
impl ShrRound<usize> for &Float
Source§fn shr_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
reference.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRound<usize> for Float
impl ShrRound<usize> for Float
Source§fn shr_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
fn shr_round(self, bits: usize, rm: RoundingMode) -> (Float, Ordering)
Right-shifts a Float
(divides it by a power of 2), taking the Float
by
value.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
output has the same precision.
$$ f(x,k,m) = x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
type Output = Float
Source§impl ShrRoundAssign<i128> for Float
impl ShrRoundAssign<i128> for Float
Source§fn shr_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<i16> for Float
impl ShrRoundAssign<i16> for Float
Source§fn shr_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<i32> for Float
impl ShrRoundAssign<i32> for Float
Source§fn shr_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<i64> for Float
impl ShrRoundAssign<i64> for Float
Source§fn shr_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<i8> for Float
impl ShrRoundAssign<i8> for Float
Source§fn shr_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<isize> for Float
impl ShrRoundAssign<isize> for Float
Source§fn shr_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<u128> for Float
impl ShrRoundAssign<u128> for Float
Source§fn shr_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<u16> for Float
impl ShrRoundAssign<u16> for Float
Source§fn shr_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<u32> for Float
impl ShrRoundAssign<u32> for Float
Source§fn shr_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<u64> for Float
impl ShrRoundAssign<u64> for Float
Source§fn shr_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<u8> for Float
impl ShrRoundAssign<u8> for Float
Source§fn shr_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl ShrRoundAssign<usize> for Float
impl ShrRoundAssign<usize> for Float
Source§fn shr_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
Right-shifts a Float
(divides it by a power of 2), in place.
NaN
, infinities, and zeros are unchanged. If the Float
has a precision, the
precision is unchanged.
$$ x\gets x/2^k. $$
- If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
,Up
, orNearest
, $\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
orDown
, $(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Floor
,Up
, orNearest
, $-\infty$ is returned instead. - If $f(x,k,m)\geq 2^{2^{30}-1}$ and $m$ is
Ceiling
orDown
, $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead, wherep
is the precision of the input. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Floor
orDown
, $0.0$ is returned instead. - If $0<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Ceiling
orUp
, $2^{-2^{30}}$ is returned instead. - If $0<f(x,k,m)\leq2^{-2^{30}-1}$, and $m$ is
Nearest
, $0.0$ is returned instead. - If $2^{-2^{30}-1}<f(x,k,m)<2^{-2^{30}}$, and $m$ is
Nearest
, $2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Ceiling
orDown
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<0$, and $m$ is
Floor
orUp
, $-2^{-2^{30}}$ is returned instead. - If $-2^{-2^{30}-1}\leq f(x,k,m)<0$, and $m$ is
Nearest
, $-0.0$ is returned instead. - If $-2^{-2^{30}}<f(x,k,m)<-2^{-2^{30}-1}$, and $m$ is
Nearest
, $-2^{-2^{30}}$ is returned instead.
If you don’t care about overflow or underflow behavior, or only want the behavior of
the Nearest
rounding mode, you can just use >>=
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 the result overflows or underflows and rm
is Exact
.
§Examples
See here.
Source§impl Sign for Float
impl Sign for Float
Source§fn sign(&self) -> Ordering
fn sign(&self) -> Ordering
Returns the sign of a Float
.
Returns Greater
if the sign is positive and Less
if the sign is negative. Never returns
Equal
. $\infty$ and positive zero have a positive sign, and $-\infty$ and negative zero
have a negative sign.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is NaN.
§Examples
use malachite_base::num::arithmetic::traits::Sign;
use malachite_base::num::basic::traits::{
Infinity, NegativeInfinity, NegativeOne, NegativeZero, One, Zero,
};
use malachite_float::Float;
use std::cmp::Ordering::*;
assert_eq!(Float::INFINITY.sign(), Greater);
assert_eq!(Float::NEGATIVE_INFINITY.sign(), Less);
assert_eq!(Float::ZERO.sign(), Greater);
assert_eq!(Float::NEGATIVE_ZERO.sign(), Less);
assert_eq!(Float::ONE.sign(), Greater);
assert_eq!(Float::NEGATIVE_ONE.sign(), Less);
Source§impl SignificantBits for &Float
impl SignificantBits for &Float
Source§fn significant_bits(self) -> u64
fn significant_bits(self) -> u64
Returns the number of significant bits of a Float
. This is defined as follows:
$$ f(\text{NaN}) = f(\pm\infty) = f(\pm 0.0) = 1, $$
and, if $x$ is finite and nonzero,
$$ f(x) = p, $$
where $p$ is the precision of $x$.
See also the complexity
function.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_base::num::basic::traits::{NaN, One};
use malachite_base::num::logic::traits::SignificantBits;
use malachite_float::Float;
assert_eq!(Float::NAN.significant_bits(), 1);
assert_eq!(Float::ONE.significant_bits(), 1);
assert_eq!(Float::one_prec(100).significant_bits(), 100);
assert_eq!(Float::from(std::f64::consts::PI).significant_bits(), 50);
assert_eq!(Float::power_of_2(100u64).significant_bits(), 1);
assert_eq!(Float::power_of_2(-100i64).significant_bits(), 1);
Source§impl Square for &Float
impl Square for &Float
Source§fn square(self) -> Float
fn square(self) -> Float
Squares a Float
, taking it by reference.
If the output has a precision, it is the precision of the input. If the square is
equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\pm\infty)=\infty$
- $f(\pm0.0)=0.0$
Overflow and underflow:
- If $f(x)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
If you want to use a rounding mode other than Nearest
, consider using
Float::square_prec_ref
instead. If you want to specify the output precision, consider
using Float::square_round_ref
. If you want both of these things, consider using
Float::square_prec_round_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::NAN).square().is_nan());
assert_eq!((&Float::INFINITY).square(), Float::INFINITY);
assert_eq!((&Float::NEGATIVE_INFINITY).square(), Float::INFINITY);
assert_eq!((&Float::from(1.5)).square(), 2.0);
assert_eq!((&Float::from(-1.5)).square(), 2.0);
type Output = Float
Source§impl Square for Float
impl Square for Float
Source§fn square(self) -> Float
fn square(self) -> Float
Squares a Float
, taking it by value.
If the output has a precision, it is the precision of the input. If the square is
equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\pm\infty)=\infty$
- $f(\pm0.0)=0.0$
Overflow and underflow:
- If $f(x)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x)<-2^{-2^{30}-1}$, $-2^{-2^{30}}$ is returned instead.
If you want to use a rounding mode other than Nearest
, consider using
Float::square_prec
instead. If you want to specify the output precision, consider using
Float::square_round
. If you want both of these things, consider using
Float::square_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!(Float::NAN.square().is_nan());
assert_eq!(Float::INFINITY.square(), Float::INFINITY);
assert_eq!(Float::NEGATIVE_INFINITY.square(), Float::INFINITY);
assert_eq!(Float::from(1.5).square(), 2.0);
assert_eq!(Float::from(-1.5).square(), 2.0);
type Output = Float
Source§impl SquareAssign for Float
impl SquareAssign for Float
Source§fn square_assign(&mut self)
fn square_assign(&mut self)
Squares a Float
in place.
If the output has a precision, it is the precision of the input. If the square is
equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the Float::square
documentation for information on special cases, overflow, and
underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::square_prec_assign
instead. If you want to specify the output precision, consider
using Float::square_round_assign
. If you want both of these things, consider using
Float::square_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::SquareAssign;
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
let mut x = Float::NAN;
x.square_assign();
assert!(x.is_nan());
let mut x = Float::INFINITY;
x.square_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x.square_assign();
assert_eq!(x, Float::INFINITY);
let mut x = Float::from(1.5);
x.square_assign();
assert_eq!(x, 2.0);
let mut x = Float::from(-1.5);
x.square_assign();
assert_eq!(x, 2.0);
Source§impl Sub<&Float> for &Float
impl Sub<&Float> for &Float
Source§fn sub(self, other: &Float) -> Float
fn sub(self, other: &Float) -> Float
Subtracts two Float
s, taking both by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,\infty)=f(-\infty,-\infty)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x$ is not NaN or $\infty$
- $f(x,-\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=-\infty$ if $x$ is not NaN or $-\infty$
- $f(x,\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,-0.0)=0.0$
- $f(-0.0,0.0)=-0.0$
- $f(0.0,0.0)=f(-0.0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(0.0,x)=f(-0.0,x)=-x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider using Float::sub_round
.
If you want both of these things, consider using Float::sub_prec_round
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::from(1.5) - &Float::NAN).is_nan());
assert_eq!(
&Float::from(1.5) - &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(1.5) - &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((&Float::INFINITY - &Float::INFINITY).is_nan());
assert_eq!(&Float::from(1.5) - &Float::from(2.5), -1.0);
assert_eq!(&Float::from(1.5) - &Float::from(-2.5), 4.0);
assert_eq!(&Float::from(-1.5) - &Float::from(2.5), -4.0);
assert_eq!(&Float::from(-1.5) - &Float::from(-2.5), 1.0);
Source§impl Sub<&Float> for &Rational
impl Sub<&Float> for &Rational
Source§fn sub(self, other: &Float) -> Float
fn sub(self, other: &Float) -> Float
Subtracts a Rational
by a Float
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=-\infty$
- $f(x,-\infty)=\infty$
- $f(0,0.0)=-0.0$
- $f(0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$
- $f(0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) - &Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) - &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) - &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(&Rational::exact_from(1.5) - &Float::from(2.5), -1.0);
assert_eq!(&Rational::exact_from(1.5) - &Float::from(-2.5), 4.0);
assert_eq!(&Rational::exact_from(-1.5) - &Float::from(2.5), -4.0);
assert_eq!(&Rational::exact_from(-1.5) - &Float::from(-2.5), 1.0);
Source§impl Sub<&Float> for Float
impl Sub<&Float> for Float
Source§fn sub(self, other: &Float) -> Float
fn sub(self, other: &Float) -> Float
Subtracts two Float
s, taking the first by value and the second by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,\infty)=f(-\infty,-\infty)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x$ is not NaN or $\infty$
- $f(x,-\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=-\infty$ if $x$ is not NaN or $-\infty$
- $f(x,\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,-0.0)=0.0$
- $f(-0.0,0.0)=-0.0$
- $f(0.0,0.0)=f(-0.0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(0.0,x)=f(-0.0,x)=-x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_val_ref
instead. If you want to specify the output precision, consider
using Float::sub_round_val_ref
. If you want both of these things, consider using
Float::sub_prec_round_val_ref
.
§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 other.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((Float::from(1.5) - &Float::NAN).is_nan());
assert_eq!(
Float::from(1.5) - &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Float::from(1.5) - &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((Float::INFINITY - &Float::INFINITY).is_nan());
assert_eq!(Float::from(1.5) - &Float::from(2.5), -1.0);
assert_eq!(Float::from(1.5) - &Float::from(-2.5), 4.0);
assert_eq!(Float::from(-1.5) - &Float::from(2.5), -4.0);
assert_eq!(Float::from(-1.5) - &Float::from(-2.5), 1.0);
Source§impl Sub<&Float> for Rational
impl Sub<&Float> for Rational
Source§fn sub(self, other: &Float) -> Float
fn sub(self, other: &Float) -> Float
Subtracts a Rational
by a Float
, taking the Rational
by value and the Float
by reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=-\infty$
- $f(x,-\infty)=\infty$
- $f(0,0.0)=-0.0$
- $f(0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$
- $f(0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) - &Float::NAN).is_nan());
assert_eq!(
Rational::exact_from(1.5) - &Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(1.5) - &Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(Rational::exact_from(1.5) - &Float::from(2.5), -1.0);
assert_eq!(Rational::exact_from(1.5) - &Float::from(-2.5), 4.0);
assert_eq!(Rational::exact_from(-1.5) - &Float::from(2.5), -4.0);
assert_eq!(Rational::exact_from(-1.5) - &Float::from(-2.5), 1.0);
Source§impl Sub<&Rational> for &Float
impl Sub<&Rational> for &Float
Source§fn sub(self, other: &Rational) -> Float
fn sub(self, other: &Rational) -> Float
Subtracts a Float
by a Rational
, taking both by reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(x,0)=x$
- $f(0.0,x)=f(-0.0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_ref
instead. If you want to specify the output precision,
consider using Float::sub_rational_round_ref_ref
. If you want both of these things,
consider using Float::sub_rational_prec_round_ref_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN - Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY - Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY - Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(2.5) - &Rational::exact_from(1.5), 1.0);
assert_eq!(&Float::from(2.5) - &Rational::exact_from(-1.5), 4.0);
assert_eq!(&Float::from(-2.5) - &Rational::exact_from(1.5), -4.0);
assert_eq!(&Float::from(-2.5) - &Rational::exact_from(-1.5), -1.0);
Source§impl Sub<&Rational> for Float
impl Sub<&Rational> for Float
Source§fn sub(self, other: &Rational) -> Float
fn sub(self, other: &Rational) -> Float
Subtracts a Float
by a Rational
, taking the first by value and the second by
reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(x,0)=x$
- $f(0.0,x)=f(-0.0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_val_ref
instead. If you want to specify the output precision,
consider using Float::sub_rational_round_val_ref
. If you want both of these things,
consider using Float::sub_rational_prec_round_val_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN - &Rational::exact_from(1.5)).is_nan());
assert_eq!(
Float::INFINITY - &Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
Float::NEGATIVE_INFINITY - &Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(2.5) - &Rational::exact_from(1.5), 1.0);
assert_eq!(Float::from(2.5) - &Rational::exact_from(-1.5), 4.0);
assert_eq!(Float::from(-2.5) - &Rational::exact_from(1.5), -4.0);
assert_eq!(Float::from(-2.5) - &Rational::exact_from(-1.5), -1.0);
Source§impl Sub<Float> for &Float
impl Sub<Float> for &Float
Source§fn sub(self, other: Float) -> Float
fn sub(self, other: Float) -> Float
Subtracts two Float
s, taking the first by reference and the second by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,\infty)=f(-\infty,-\infty)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x$ is not NaN or $\infty$
- $f(x,-\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=-\infty$ if $x$ is not NaN or $-\infty$
- $f(x,\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,-0.0)=0.0$
- $f(-0.0,0.0)=-0.0$
- $f(0.0,0.0)=f(-0.0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(0.0,x)=f(-0.0,x)=-x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_val
instead. If you want to specify the output precision, consider
using Float::sub_round_ref_val
. If you want both of these things, consider using
Float::sub_prec_round_ref_val
.
§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()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
assert!((&Float::from(1.5) - Float::NAN).is_nan());
assert_eq!(
&Float::from(1.5) - Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Float::from(1.5) - Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert!((&Float::INFINITY - Float::INFINITY).is_nan());
assert_eq!(&Float::from(1.5) - Float::from(2.5), -1.0);
assert_eq!(&Float::from(1.5) - Float::from(-2.5), 4.0);
assert_eq!(&Float::from(-1.5) - Float::from(2.5), -4.0);
assert_eq!(&Float::from(-1.5) - Float::from(-2.5), 1.0);
Source§impl Sub<Float> for &Rational
impl Sub<Float> for &Rational
Source§fn sub(self, other: Float) -> Float
fn sub(self, other: Float) -> Float
Subtracts a Rational
by a Float
, taking the Rational
by value and the Float
by reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=-\infty$
- $f(x,-\infty)=\infty$
- $f(0,0.0)=-0.0$
- $f(0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$
- $f(0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Rational::exact_from(1.5) - Float::NAN).is_nan());
assert_eq!(
&Rational::exact_from(1.5) - Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
&Rational::exact_from(1.5) - Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(&Rational::exact_from(1.5) - Float::from(2.5), -1.0);
assert_eq!(&Rational::exact_from(1.5) - Float::from(-2.5), 4.0);
assert_eq!(&Rational::exact_from(-1.5) - Float::from(2.5), -4.0);
assert_eq!(&Rational::exact_from(-1.5) - Float::from(-2.5), 1.0);
Source§impl Sub<Float> for Rational
impl Sub<Float> for Rational
Source§fn sub(self, other: Float) -> Float
fn sub(self, other: Float) -> Float
Subtracts a Rational
by a Float
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(x,\text{NaN})=\text{NaN}$
- $f(x,\infty)=-\infty$
- $f(x,-\infty)=\infty$
- $f(0,0.0)=-0.0$
- $f(0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$
- $f(0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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 \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Rational::exact_from(1.5) - Float::NAN).is_nan());
assert_eq!(
Rational::exact_from(1.5) - Float::INFINITY,
Float::NEGATIVE_INFINITY
);
assert_eq!(
Rational::exact_from(1.5) - Float::NEGATIVE_INFINITY,
Float::INFINITY
);
assert_eq!(Rational::exact_from(1.5) - Float::from(2.5), -1.0);
assert_eq!(Rational::exact_from(1.5) - Float::from(-2.5), 4.0);
assert_eq!(Rational::exact_from(-1.5) - Float::from(2.5), -4.0);
assert_eq!(Rational::exact_from(-1.5) - Float::from(-2.5), 1.0);
Source§impl Sub<Rational> for &Float
impl Sub<Rational> for &Float
Source§fn sub(self, other: Rational) -> Float
fn sub(self, other: Rational) -> Float
Subtracts a Float
by a Rational
, taking the first by reference and the second by
value.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(x,0)=x$
- $f(0.0,x)=f(-0.0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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_ref_val
instead. If you want to specify the output precision,
consider using Float::sub_rational_round_ref_val
. If you want both of these things,
consider using Float::sub_rational_prec_round_ref_val
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((&Float::NAN - Rational::exact_from(1.5)).is_nan());
assert_eq!(
&Float::INFINITY - Rational::exact_from(1.5),
Float::INFINITY
);
assert_eq!(
&Float::NEGATIVE_INFINITY - Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(&Float::from(2.5) - Rational::exact_from(1.5), 1.0);
assert_eq!(&Float::from(2.5) - Rational::exact_from(-1.5), 4.0);
assert_eq!(&Float::from(-2.5) - Rational::exact_from(1.5), -4.0);
assert_eq!(&Float::from(-2.5) - Rational::exact_from(-1.5), -1.0);
Source§impl Sub<Rational> for Float
impl Sub<Rational> for Float
Source§fn sub(self, other: Rational) -> Float
fn sub(self, other: Rational) -> Float
Subtracts a Float
by a Rational
, taking both by value.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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) = 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}$,
where $p$ is the precision of the input
Float
.
Special cases:
- $f(\text{NaN},x)=\text{NaN}$
- $f(\infty,x)=\infty$
- $f(-\infty,x)=-\infty$
- $f(0.0,0)=0.0$
- $f(-0.0,0)=-0.0$
- $f(x,0)=x$
- $f(0.0,x)=f(-0.0,x)=-x$
- $f(x,x)=0.0$ if $x$ is nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider
using Float::sub_rational_round
. If you want both of these things, consider using
Float::sub_rational_prec_round
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
assert!((Float::NAN - Rational::exact_from(1.5)).is_nan());
assert_eq!(Float::INFINITY - Rational::exact_from(1.5), Float::INFINITY);
assert_eq!(
Float::NEGATIVE_INFINITY - Rational::exact_from(1.5),
Float::NEGATIVE_INFINITY
);
assert_eq!(Float::from(2.5) - Rational::exact_from(1.5), 1.0);
assert_eq!(Float::from(2.5) - Rational::exact_from(-1.5), 4.0);
assert_eq!(Float::from(-2.5) - Rational::exact_from(1.5), -4.0);
assert_eq!(Float::from(-2.5) - Rational::exact_from(-1.5), -1.0);
Source§impl Sub for Float
impl Sub for Float
Source§fn sub(self, other: Float) -> Float
fn sub(self, other: Float) -> Float
Subtracts two Float
s, taking both by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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) = 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}$, where $p$ is the maximum precision of the inputs.
Special cases:
- $f(\text{NaN},x)=f(x,\text{NaN})=f(\infty,\infty)=f(-\infty,-\infty)=\text{NaN}$
- $f(\infty,x)=\infty$ if $x$ is not NaN or $\infty$
- $f(x,-\infty)=\infty$ if $x$ is not NaN or $-\infty$
- $f(-\infty,x)=-\infty$ if $x$ is not NaN or $-\infty$
- $f(x,\infty)=-\infty$ if $x$ is not NaN or $\infty$
- $f(0.0,-0.0)=0.0$
- $f(-0.0,0.0)=-0.0$
- $f(0.0,0.0)=f(-0.0,-0.0)=0.0$
- $f(x,0.0)=f(x,-0.0)=x$ if $x$ is not NaN and $x$ is nonzero
- $f(0.0,x)=f(-0.0,x)=-x$ if $x$ is not NaN and $x$ is nonzero
- $f(x,x)=0.0$ if $x$ is finite and nonzero
Overflow and underflow:
- If $f(x,y)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
- If $f(x,y)\geq 2^{2^{30}-1}$, $-\infty$ is returned instead.
- If $0<f(x,y)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
- If $2^{-2^{30}-1}<f(x,y)<2^{-2^{30}}$, $2^{-2^{30}}$ is returned instead.
- If $-2^{-2^{30}-1}\leq f(x,y)<0$, $-0.0$ is returned instead.
- If $-2^{-2^{30}}<f(x,y)<-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
instead. If you want to specify the output precision, consider using Float::sub_round
.
If you want both of these things, consider using Float::sub_prec_round
.
§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};
use malachite_float::Float;
assert!((Float::from(1.5) - Float::NAN).is_nan());
assert_eq!(Float::from(1.5) - Float::INFINITY, Float::NEGATIVE_INFINITY);
assert_eq!(Float::from(1.5) - Float::NEGATIVE_INFINITY, Float::INFINITY);
assert!((Float::INFINITY - Float::INFINITY).is_nan());
assert_eq!(Float::from(1.5) - Float::from(2.5), -1.0);
assert_eq!(Float::from(1.5) - Float::from(-2.5), 4.0);
assert_eq!(Float::from(-1.5) - Float::from(2.5), -4.0);
assert_eq!(Float::from(-1.5) - Float::from(-2.5), 1.0);
Source§impl SubAssign<&Float> for Float
impl SubAssign<&Float> for Float
Source§fn sub_assign(&mut self, other: &Float)
fn sub_assign(&mut self, other: &Float)
Subtracts a Float
by a Float
in place, taking the Float
on the right-hand side
by reference.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the -
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_prec_assign
instead. If you want to specify the output precision, consider
using Float::sub_round_assign
. If you want both of these things, consider using
Float::sub_prec_round_assign
.
§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 malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_float::Float;
let mut x = Float::from(1.5);
x -= &Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x -= &Float::INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(1.5);
x -= &Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x -= &Float::INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x -= &Float::from(2.5);
assert_eq!(x, -1.0);
let mut x = Float::from(1.5);
x -= &Float::from(-2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(-1.5);
x -= &Float::from(2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x -= &Float::from(-2.5);
assert_eq!(x, 1.0);
Source§impl SubAssign<&Rational> for Float
impl SubAssign<&Rational> for Float
Source§fn sub_assign(&mut self, other: &Rational)
fn sub_assign(&mut self, other: &Rational)
Subtracts a Rational
by a Float
in place, taking the Rational
by reference.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the -
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_rational_prec_assign_ref
instead. If you want to specify the output
precision, consider using Float::sub_rational_round_assign_ref
. If you want both of
these things, consider using Float::sub_rational_prec_round_assign_ref
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x -= &Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x -= &Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x -= &Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(2.5);
x -= &Rational::exact_from(1.5);
assert_eq!(x, 1.0);
let mut x = Float::from(2.5);
x -= &Rational::exact_from(-1.5);
assert_eq!(x, 4.0);
let mut x = Float::from(-2.5);
x -= &Rational::exact_from(1.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-2.5);
x -= &Rational::exact_from(-1.5);
assert_eq!(x, -1.0);
Source§impl SubAssign<Rational> for Float
impl SubAssign<Rational> for Float
Source§fn sub_assign(&mut self, other: Rational)
fn sub_assign(&mut self, other: Rational)
Subtracts a Rational
by a Float
in place, taking the Rational
by value.
If the output has a precision, it is the precision of the input Float
. If the difference
is equidistant from two Float
s 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.
$$ x\gets = 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}$,
where $p$ is the precision of the input
Float
.
See the -
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_rational_prec_assign
instead. If you want to specify the output precision,
consider using Float::sub_rational_round_assign
. If you want both of these things,
consider using Float::sub_rational_prec_round_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, NegativeInfinity};
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_float::Float;
use malachite_q::Rational;
let mut x = Float::NAN;
x -= Rational::exact_from(1.5);
assert!(x.is_nan());
let mut x = Float::INFINITY;
x -= Rational::exact_from(1.5);
assert_eq!(x, Float::INFINITY);
let mut x = Float::NEGATIVE_INFINITY;
x -= Rational::exact_from(1.5);
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(2.5);
x -= Rational::exact_from(1.5);
assert_eq!(x, 1.0);
let mut x = Float::from(2.5);
x -= Rational::exact_from(-1.5);
assert_eq!(x, 4.0);
let mut x = Float::from(-2.5);
x -= Rational::exact_from(1.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-2.5);
x -= Rational::exact_from(-1.5);
assert_eq!(x, -1.0);
Source§impl SubAssign for Float
impl SubAssign for Float
Source§fn sub_assign(&mut self, other: Float)
fn sub_assign(&mut self, other: Float)
Subtracts a Float
by a Float
in place, taking the Float
on the right-hand side
by value.
If the output has a precision, it is the maximum of the precisions of the inputs. If the
difference is equidistant from two Float
s 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.
$$ x\gets = 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}$, where $p$ is the maximum precision of the inputs.
See the -
documentation for information on special cases, overflow, and underflow.
If you want to use a rounding mode other than Nearest
, consider using
Float::sub_prec_assign
instead. If you want to specify the output precision, consider
using Float::sub_round_assign
. If you want both of these things, consider using
Float::sub_prec_round_assign
.
§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};
use malachite_float::Float;
let mut x = Float::from(1.5);
x -= Float::NAN;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x -= Float::INFINITY;
assert_eq!(x, Float::NEGATIVE_INFINITY);
let mut x = Float::from(1.5);
x -= Float::NEGATIVE_INFINITY;
assert_eq!(x, Float::INFINITY);
let mut x = Float::INFINITY;
x -= Float::INFINITY;
assert!(x.is_nan());
let mut x = Float::from(1.5);
x -= Float::from(2.5);
assert_eq!(x, -1.0);
let mut x = Float::from(1.5);
x -= Float::from(-2.5);
assert_eq!(x, 4.0);
let mut x = Float::from(-1.5);
x -= Float::from(2.5);
assert_eq!(x, -4.0);
let mut x = Float::from(-1.5);
x -= Float::from(-2.5);
assert_eq!(x, 1.0);
Source§impl TryFrom<&Float> for Integer
impl TryFrom<&Float> for Integer
Source§fn try_from(f: &Float) -> Result<Integer, Self::Error>
fn try_from(f: &Float) -> Result<Integer, Self::Error>
Converts a Float
to an Integer
, taking the Float
by reference. If the Float
is not equal to an integer, an error is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::SignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Integer::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(Integer::try_from(&Float::from(123.0)).unwrap(), 123);
assert_eq!(Integer::try_from(&Float::from(-123.0)).unwrap(), -123);
assert_eq!(
Integer::try_from(&Float::from(1.5)),
Err(FloatNonIntegerOrOutOfRange)
);
assert_eq!(Integer::try_from(&Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Integer::try_from(&Float::NAN), Err(FloatInfiniteOrNan));
Source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
Source§impl TryFrom<&Float> for Natural
impl TryFrom<&Float> for Natural
Source§fn try_from(f: &Float) -> Result<Natural, Self::Error>
fn try_from(f: &Float) -> Result<Natural, Self::Error>
Converts a Float
to a Natural
, taking the Float
by reference. If the Float
is not equal to a non-negative integer, an error is returned.
Both positive and negative zero convert to a Natural
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::UnsignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Natural::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(Natural::try_from(&Float::from(123.0)).unwrap(), 123);
assert_eq!(Natural::try_from(&Float::from(-123.0)), Err(FloatNegative));
assert_eq!(
Natural::try_from(&Float::from(1.5)),
Err(FloatNonIntegerOrOutOfRange)
);
assert_eq!(Natural::try_from(&Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Natural::try_from(&Float::NAN), Err(FloatInfiniteOrNan));
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for Rational
impl TryFrom<&Float> for Rational
Source§fn try_from(x: &Float) -> Result<Rational, Self::Error>
fn try_from(x: &Float) -> Result<Rational, Self::Error>
Converts a Float
to a Rational
, taking the Float
by reference. If the Float
is not finite, an error is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::conversion::rational_from_float::RationalFromFloatError;
use malachite_float::Float;
use malachite_q::Rational;
assert_eq!(Rational::try_from(&Float::ZERO).unwrap(), 0);
assert_eq!(
Rational::try_from(&Float::from(1.5)).unwrap().to_string(),
"3/2"
);
assert_eq!(
Rational::try_from(&Float::from(-1.5)).unwrap().to_string(),
"-3/2"
);
assert_eq!(
Rational::try_from(&Float::INFINITY),
Err(RationalFromFloatError)
);
assert_eq!(Rational::try_from(&Float::NAN), Err(RationalFromFloatError));
Source§type Error = RationalFromFloatError
type Error = RationalFromFloatError
Source§impl TryFrom<&Float> for f32
impl TryFrom<&Float> for f32
Source§impl TryFrom<&Float> for f64
impl TryFrom<&Float> for f64
Source§impl TryFrom<&Float> for i128
impl TryFrom<&Float> for i128
Source§impl TryFrom<&Float> for i16
impl TryFrom<&Float> for i16
Source§impl TryFrom<&Float> for i32
impl TryFrom<&Float> for i32
Source§impl TryFrom<&Float> for i64
impl TryFrom<&Float> for i64
Source§impl TryFrom<&Float> for i8
impl TryFrom<&Float> for i8
Source§impl TryFrom<&Float> for isize
impl TryFrom<&Float> for isize
Source§impl TryFrom<&Float> for u128
impl TryFrom<&Float> for u128
Source§fn try_from(f: &Float) -> Result<u128, Self::Error>
fn try_from(f: &Float) -> Result<u128, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for u16
impl TryFrom<&Float> for u16
Source§fn try_from(f: &Float) -> Result<u16, Self::Error>
fn try_from(f: &Float) -> Result<u16, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for u32
impl TryFrom<&Float> for u32
Source§fn try_from(f: &Float) -> Result<u32, Self::Error>
fn try_from(f: &Float) -> Result<u32, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for u64
impl TryFrom<&Float> for u64
Source§fn try_from(f: &Float) -> Result<u64, Self::Error>
fn try_from(f: &Float) -> Result<u64, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for u8
impl TryFrom<&Float> for u8
Source§fn try_from(f: &Float) -> Result<u8, Self::Error>
fn try_from(f: &Float) -> Result<u8, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Float> for usize
impl TryFrom<&Float> for usize
Source§fn try_from(f: &Float) -> Result<usize, Self::Error>
fn try_from(f: &Float) -> Result<usize, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by
reference. If the Float
is not equal to an unsigned primitive integer of the
given type, an error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<&Integer> for Float
impl TryFrom<&Integer> for Float
Source§fn try_from(n: &Integer) -> Result<Float, Self::Error>
fn try_from(n: &Integer) -> Result<Float, Self::Error>
Converts an Integer
to a Float
, taking the Integer
by reference.
If the Integer
is nonzero, the precision of the Float
is the minimum possible
precision to represent the Integer
exactly. If you want to specify some other precision,
try Float::from_integer_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_integer_prec_round
.
If the absolue value of the Integer
is greater than or equal to $2^{2^{30}-1}$, this
function returns an overflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Float::try_from(&Integer::ZERO).unwrap().to_string(), "0.0");
assert_eq!(
Float::try_from(&Integer::from(123)).unwrap().to_string(),
"123.0"
);
assert_eq!(
Float::try_from(&Integer::from(123)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(&Integer::from(10)).unwrap().to_string(),
"10.0"
);
assert_eq!(
Float::try_from(&Integer::from(10)).unwrap().get_prec(),
Some(3)
);
assert_eq!(
Float::try_from(&Integer::from(-123)).unwrap().to_string(),
"-123.0"
);
assert_eq!(
Float::try_from(&Integer::from(-123)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(&Integer::from(-10)).unwrap().to_string(),
"-10.0"
);
assert_eq!(
Float::try_from(&Integer::from(-10)).unwrap().get_prec(),
Some(3)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Source§impl TryFrom<&Natural> for Float
impl TryFrom<&Natural> for Float
Source§fn try_from(x: &Natural) -> Result<Float, Self::Error>
fn try_from(x: &Natural) -> Result<Float, Self::Error>
Converts a Natural
to a Float
, taking the Natural
by reference.
If the Natural
is nonzero, the precision of the Float
is the minimum possible
precision to represent the Natural
exactly. If you want to specify some other precision,
try Float::from_natural_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_natural_prec_round
.
If the Natural
is greater than or equal to $2^{2^{30}-1}$, this function returns an
overflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Float::try_from(&Natural::ZERO).unwrap().to_string(), "0.0");
assert_eq!(
Float::try_from(&Natural::from(123u32)).unwrap().to_string(),
"123.0"
);
assert_eq!(
Float::try_from(&Natural::from(123u32)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(&Natural::from(10u32)).unwrap().to_string(),
"10.0"
);
assert_eq!(
Float::try_from(&Natural::from(10u32)).unwrap().get_prec(),
Some(3)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Source§impl TryFrom<&Rational> for Float
impl TryFrom<&Rational> for Float
Source§fn try_from(x: &Rational) -> Result<Float, Self::Error>
fn try_from(x: &Rational) -> Result<Float, Self::Error>
Converts a Rational
to an Float
, taking the Rational
by reference. If the
Rational
’s denominator is not a power of 2, or if the Rational
is too far from zero
or too close to zero to be represented as a Float
, an error is returned.
The Float
’s precision is the minimum number of bits needed to exactly represent the
Rational
.
- If the
Rational
is greater than or equal to $2^{2^{30}-1}$), this function returns an overflow error. - If the
Rational
is less than or equal to $-2^{2^{30}-1}$), this function returns an overflow error. - If the
Rational
is positive and less than $2^{-2^{30}}$), this function returns an underflow error. - If the
Rational
is negative and greater than $-2^{-2^{30}}$), this function returns an underflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::conversion::primitive_float_from_rational::FloatConversionError;
use malachite_q::Rational;
assert_eq!(Float::try_from(&Rational::ZERO).unwrap(), 0);
assert_eq!(
Float::try_from(&Rational::from_signeds(1, 8)).unwrap(),
0.125
);
assert_eq!(
Float::try_from(&Rational::from_signeds(-1, 8)).unwrap(),
-0.125
);
assert_eq!(
Float::try_from(&Rational::from_signeds(1, 3)),
Err(FloatConversionError::Inexact)
);
assert_eq!(
Float::try_from(&Rational::from_signeds(-1, 3)),
Err(FloatConversionError::Inexact)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Source§impl TryFrom<Float> for Integer
impl TryFrom<Float> for Integer
Source§fn try_from(f: Float) -> Result<Integer, Self::Error>
fn try_from(f: Float) -> Result<Integer, Self::Error>
Converts a Float
to an Integer
, taking the Float
by value. If the Float
is
not equal to an integer, an error is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::SignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Integer::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(Integer::try_from(Float::from(123.0)).unwrap(), 123);
assert_eq!(Integer::try_from(Float::from(-123.0)).unwrap(), -123);
assert_eq!(
Integer::try_from(Float::from(1.5)),
Err(FloatNonIntegerOrOutOfRange)
);
assert_eq!(Integer::try_from(Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Integer::try_from(Float::NAN), Err(FloatInfiniteOrNan));
Source§type Error = SignedFromFloatError
type Error = SignedFromFloatError
Source§impl TryFrom<Float> for Natural
impl TryFrom<Float> for Natural
Source§fn try_from(f: Float) -> Result<Natural, Self::Error>
fn try_from(f: Float) -> Result<Natural, Self::Error>
Converts a Float
to a Natural
, taking the Float
by value. If the Float
is
not equal to a non-negative integer, an error is returned.
Both positive and negative zero convert to a Natural
zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is f.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_base::num::conversion::from::UnsignedFromFloatError::*;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Natural::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(Natural::try_from(Float::from(123.0)).unwrap(), 123);
assert_eq!(Natural::try_from(Float::from(-123.0)), Err(FloatNegative));
assert_eq!(
Natural::try_from(Float::from(1.5)),
Err(FloatNonIntegerOrOutOfRange)
);
assert_eq!(Natural::try_from(Float::INFINITY), Err(FloatInfiniteOrNan));
assert_eq!(Natural::try_from(Float::NAN), Err(FloatInfiniteOrNan));
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for Rational
impl TryFrom<Float> for Rational
Source§fn try_from(x: Float) -> Result<Rational, Self::Error>
fn try_from(x: Float) -> Result<Rational, Self::Error>
Converts a Float
to a Rational
, taking the Float
by value. If the Float
is
not finite, an error is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.complexity()
.
§Examples
use malachite_base::num::basic::traits::{Infinity, NaN, Zero};
use malachite_float::conversion::rational_from_float::RationalFromFloatError;
use malachite_float::Float;
use malachite_q::Rational;
assert_eq!(Rational::try_from(Float::ZERO).unwrap(), 0);
assert_eq!(
Rational::try_from(Float::from(1.5)).unwrap().to_string(),
"3/2"
);
assert_eq!(
Rational::try_from(Float::from(-1.5)).unwrap().to_string(),
"-3/2"
);
assert_eq!(
Rational::try_from(Float::INFINITY),
Err(RationalFromFloatError)
);
assert_eq!(Rational::try_from(Float::NAN), Err(RationalFromFloatError));
Source§type Error = RationalFromFloatError
type Error = RationalFromFloatError
Source§impl TryFrom<Float> for f32
impl TryFrom<Float> for f32
Source§impl TryFrom<Float> for f64
impl TryFrom<Float> for f64
Source§impl TryFrom<Float> for i128
impl TryFrom<Float> for i128
Source§impl TryFrom<Float> for i16
impl TryFrom<Float> for i16
Source§impl TryFrom<Float> for i32
impl TryFrom<Float> for i32
Source§impl TryFrom<Float> for i64
impl TryFrom<Float> for i64
Source§impl TryFrom<Float> for i8
impl TryFrom<Float> for i8
Source§impl TryFrom<Float> for isize
impl TryFrom<Float> for isize
Source§impl TryFrom<Float> for u128
impl TryFrom<Float> for u128
Source§fn try_from(f: Float) -> Result<u128, Self::Error>
fn try_from(f: Float) -> Result<u128, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for u16
impl TryFrom<Float> for u16
Source§fn try_from(f: Float) -> Result<u16, Self::Error>
fn try_from(f: Float) -> Result<u16, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for u32
impl TryFrom<Float> for u32
Source§fn try_from(f: Float) -> Result<u32, Self::Error>
fn try_from(f: Float) -> Result<u32, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for u64
impl TryFrom<Float> for u64
Source§fn try_from(f: Float) -> Result<u64, Self::Error>
fn try_from(f: Float) -> Result<u64, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for u8
impl TryFrom<Float> for u8
Source§fn try_from(f: Float) -> Result<u8, Self::Error>
fn try_from(f: Float) -> Result<u8, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Float> for usize
impl TryFrom<Float> for usize
Source§fn try_from(f: Float) -> Result<usize, Self::Error>
fn try_from(f: Float) -> Result<usize, Self::Error>
Converts a Float
to a primitive unsigned integer, taking the Float
by value.
If the Float
is not equal to an unsigned primitive integer of the given type, an
error is returned.
Both positive and negative zero convert to a primitive unsigned integer zero.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§type Error = UnsignedFromFloatError
type Error = UnsignedFromFloatError
Source§impl TryFrom<Integer> for Float
impl TryFrom<Integer> for Float
Source§fn try_from(n: Integer) -> Result<Float, Self::Error>
fn try_from(n: Integer) -> Result<Float, Self::Error>
Converts an Integer
to a Float
, taking the Integer
by value.
If the Integer
is nonzero, the precision of the Float
is the minimum possible
precision to represent the Integer
exactly. If you want to specify some other precision,
try Float::from_integer_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_integer_prec_round
.
If the absolue value of the Integer
is greater than or equal to $2^{2^{30}-1}$, this
function returns an overflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::integer::Integer;
assert_eq!(Float::try_from(Integer::ZERO).unwrap().to_string(), "0.0");
assert_eq!(
Float::try_from(Integer::from(123)).unwrap().to_string(),
"123.0"
);
assert_eq!(
Float::try_from(Integer::from(123)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(Integer::from(10)).unwrap().to_string(),
"10.0"
);
assert_eq!(
Float::try_from(Integer::from(10)).unwrap().get_prec(),
Some(3)
);
assert_eq!(
Float::try_from(Integer::from(-123)).unwrap().to_string(),
"-123.0"
);
assert_eq!(
Float::try_from(Integer::from(-123)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(Integer::from(-10)).unwrap().to_string(),
"-10.0"
);
assert_eq!(
Float::try_from(Integer::from(-10)).unwrap().get_prec(),
Some(3)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Source§impl TryFrom<Natural> for Float
impl TryFrom<Natural> for Float
Source§fn try_from(x: Natural) -> Result<Float, Self::Error>
fn try_from(x: Natural) -> Result<Float, Self::Error>
Converts a Natural
to a Float
, taking the Natural
by value.
If the Natural
is nonzero, the precision of the Float
is the minimum possible
precision to represent the Natural
exactly. If you want to specify some other precision,
try Float::from_natural_prec
. This may require rounding, which uses Nearest
by
default. To specify a rounding mode as well as a precision, try
Float::from_natural_prec_round
.
If the Natural
is greater than or equal to $2^{2^{30}-1}$, this function returns an
overflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_nz::natural::Natural;
assert_eq!(Float::try_from(Natural::ZERO).unwrap().to_string(), "0.0");
assert_eq!(
Float::try_from(Natural::from(123u32)).unwrap().to_string(),
"123.0"
);
assert_eq!(
Float::try_from(Natural::from(123u32)).unwrap().get_prec(),
Some(7)
);
assert_eq!(
Float::try_from(Natural::from(10u32)).unwrap().to_string(),
"10.0"
);
assert_eq!(
Float::try_from(Natural::from(10u32)).unwrap().get_prec(),
Some(3)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Source§impl TryFrom<Rational> for Float
impl TryFrom<Rational> for Float
Source§fn try_from(x: Rational) -> Result<Float, Self::Error>
fn try_from(x: Rational) -> Result<Float, Self::Error>
Converts a Rational
to an Float
, taking the Rational
by value. If the
Rational
’s denominator is not a power of 2, or if the Rational
is too far from zero
or too close to zero to be represented as a Float
, an error is returned.
The Float
’s precision is the minimum number of bits needed to exactly represent the
Rational
.
- If the
Rational
is greater than or equal to $2^{2^{30}-1}$), this function returns an overflow error. - If the
Rational
is less than or equal to $-2^{2^{30}-1}$), this function returns an overflow error. - If the
Rational
is positive and less than $2^{-2^{30}}$), this function returns an underflow error. - If the
Rational
is negative and greater than $-2^{-2^{30}}$), this function returns an underflow error.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_float::Float;
use malachite_q::conversion::primitive_float_from_rational::FloatConversionError;
use malachite_q::Rational;
assert_eq!(Float::try_from(Rational::ZERO).unwrap(), 0);
assert_eq!(
Float::try_from(Rational::from_signeds(1, 8)).unwrap(),
0.125
);
assert_eq!(
Float::try_from(Rational::from_signeds(-1, 8)).unwrap(),
-0.125
);
assert_eq!(
Float::try_from(Rational::from_signeds(1, 3)),
Err(FloatConversionError::Inexact)
);
assert_eq!(
Float::try_from(Rational::from_signeds(-1, 3)),
Err(FloatConversionError::Inexact)
);
Source§type Error = FloatConversionError
type Error = FloatConversionError
Auto Trait Implementations§
impl Freeze for Float
impl RefUnwindSafe for Float
impl Send for Float
impl Sync for Float
impl Unpin for Float
impl UnwindSafe for Float
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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