Skip to main content

Q

Enum Q 

Source
pub enum Q {
    Number(Rat),
    PosSat,
    NegSat,
    PosInf,
    NegInf,
    Nan,
}
Expand description

A bounded rational, or an explicit statement that the value is not one.

variantdenotes
Number(x){x}
PosSat / NegSat(MAX_MAG, +∞) / (-∞, -MAX_MAG), reals only
PosInf / NegInf{+∞} / {-∞}
Nanno information

Saturation denotes reals, so Number(0) · PosSat == Number(0). PartialEq is derived and Nan == Nan, which keeps Eq, Hash and the total Ord lawful. Ord is hand-written: variant order is not value order.

Variants§

§

Number(Rat)

A representable rational.

§

PosSat

The true magnitude exceeds MAX_MAG and the value is positive.

§

NegSat

The true magnitude exceeds MAX_MAG and the value is negative.

§

PosInf

Exactly +∞.

§

NegInf

Exactly -∞.

§

Nan

No information about the value.

Implementations§

Source§

impl Q

Source

pub fn is_number(self) -> bool

Whether this is a representable rational.

The four classification predicates are mutually exclusive and jointly exhaustive. See theorem_classification_partitions.

use the_q::{Q, Rat};

assert!(Q::number(Rat::one()).is_number());
assert!(!Q::PosSat.is_number());
assert!(!Q::Nan.is_number());
Source

pub fn is_saturated(self) -> bool

Whether the true magnitude is known to exceed MAX_MAG.

This predicate is not the negation of is_number. It separates an overflow from a division by zero. That distinction is the purpose of the saturation states.

use the_q::Q;

assert!(Q::PosSat.is_saturated());
assert!(Q::NegSat.is_saturated());
assert!(!Q::PosInf.is_saturated());
Source

pub fn is_infinite(self) -> bool

Whether this is exactly ±∞.

use the_q::Q;

assert!(Q::PosInf.is_infinite());
assert!(Q::NegInf.is_infinite());
assert!(!Q::PosSat.is_infinite());
Source

pub fn is_nan(self) -> bool

Whether this carries no information about the value.

use the_q::Q;

assert!(Q::Nan.is_nan());
assert!(!Q::zero().is_nan());
Source

pub fn number(x: Rat) -> Q

Lift a kernel rational into the extended type.

use the_q::{Q, Rat};

let half = Rat::new(1, 2).unwrap();
assert_eq!(Q::number(half), Q::Number(half));
Source

pub fn zero() -> Q

0.

use the_q::Q;

assert!(Q::zero().is_zero());
assert!(Q::zero().is_number());
Source

pub fn one() -> Q

1.

use the_q::Q;

assert!(Q::one().is_one());
Source

pub fn neg_one() -> Q

-1.

use the_q::{Q, Rat};

assert_eq!(Q::neg_one(), Q::Number(Rat::new(-1, 1).unwrap()));
Source

pub fn new(num: i64, den: i64) -> Q

The rational num / den, total: x/0 is ±Inf, 0/0 is Nan. Saturation is decided on the value (magnitude_fits), not on the components: 1 / i64::MIN is small and rounds, it does not saturate. Where Rat::new succeeds this returns the same value.

use the_q::{Q, Rat};

assert_eq!(Q::new(1, 2), Q::Number(Rat::new(1, 2).unwrap()));
assert_eq!(Q::new(1, 0), Q::PosInf);
assert_eq!(Q::new(0, 0), Q::Nan);
Source

pub fn is_zero(self) -> bool

self == 0.

The result is false for each special value. PosSat denotes (MAX_MAG, +∞), which does not contain zero, thus false is the true answer there. For Nan the result is a convention from the design.

use the_q::Q;

assert!(Q::zero().is_zero());
assert!(!Q::PosSat.is_zero());
assert!(!Q::Nan.is_zero());
Source

pub fn is_one(self) -> bool

self == 1.

use the_q::Q;

assert!(Q::one().is_one());
assert!(!Q::PosSat.is_one());
Source

pub fn in_unit_interval(self) -> bool

0 <= self <= 1.

The result is false for each special value. For the saturations false is the true answer, because both saturation ranges are outside [0, 1].

use the_q::{Q, Rat};

assert!(Q::number(Rat::new(1, 2).unwrap()).in_unit_interval());
assert!(!Q::PosSat.in_unit_interval());
Source

pub fn signum(self) -> Option<Sign>

The sign, where one exists.

The result is None for Nan only. Both saturations and both infinities have a definite sign and give Some. The discriminant carries that sign for this purpose.

use the_q::{Q, Sign};

assert_eq!(Q::one().signum(), Some(Sign::Positive));
assert_eq!(Q::zero().signum(), Some(Sign::Zero));
assert_eq!(Q::PosSat.signum(), Some(Sign::Positive));
assert_eq!(Q::Nan.signum(), None);
Source§

impl Q

Source

pub fn sum(xs: &[Q]) -> Q

xs[0] + xs[1] + ..., left to right. An empty slice gives 0.

The left-to-right order is part of the contract and not an implementation detail. With rounding, addition is not associative, thus the order fixes the answer and makes the result reproducible.

use the_q::Q;

let xs = [Q::one(), Q::one(), Q::one()];
assert_eq!(Q::sum(&xs), Q::number(the_q::Rat::new(3, 1).unwrap()));
assert!(Q::sum(&[]).is_zero());
Source

pub fn product(xs: &[Q]) -> Q

xs[0] * xs[1] * ..., left to right. An empty slice gives 1.

use the_q::{Q, Rat};

let xs = [Q::number(Rat::new(2, 1).unwrap()), Q::number(Rat::new(3, 1).unwrap())];
assert_eq!(Q::product(&xs), Q::number(Rat::new(6, 1).unwrap()));
assert!(Q::product(&[]).is_one());
Source

pub fn weighted_mean(pairs: &[(Q, Q)]) -> Q

sum(w_i · x_i) / sum(w_i), total: a zero weight sum gives Nan (0/0) or a signed infinity, and an empty slice gives Nan the same way.

use the_q::{Q, Rat};

let one = Q::one();
let two = Q::number(Rat::new(2, 1).unwrap());
// weight 1 on `1`, weight 3 on `2`: (1*1 + 3*2) / (1 + 3) == 7/4
let three = Q::number(Rat::new(3, 1).unwrap());
let pairs = [(one, one), (three, two)];
assert_eq!(Q::weighted_mean(&pairs), Q::number(Rat::new(7, 4).unwrap()));
assert!(Q::weighted_mean(&[]).is_nan());
Source§

impl Q

Source

pub fn add(a: Q, b: Q) -> Q

a + b, total. Replaces the kernel add, which clamps silently.

use the_q::{Q, Rat, MAX_MAG};

assert_eq!(Q::add(Q::one(), Q::one()), Q::number(Rat::new(2, 1).unwrap()));
// Two representable rationals overflowing the budget saturate, they do
// not become infinite.
let m = Q::number(Rat::new(MAX_MAG, 1).unwrap());
assert_eq!(Q::add(m, m), Q::PosSat);
assert!(Q::add(Q::Nan, Q::one()).is_nan());
Source

pub fn sub(a: Q, b: Q) -> Q

a - b, total.

The definition is a + (-b), as §5 specifies. The two operations thus agree for an overflowing difference.

use the_q::{Q, Rat};

assert_eq!(Q::sub(Q::one(), Q::one()), Q::zero());
assert!(Q::sub(Q::Nan, Q::zero()).is_nan());
Source

pub fn mul(a: Q, b: Q) -> Q

a * b, total.

use the_q::Q;

// Saturation denotes a finite real, so zero times it is exactly zero...
assert_eq!(Q::mul(Q::zero(), Q::PosSat), Q::zero());
// ...but zero times a true infinity is the classic indeterminate.
assert!(Q::mul(Q::zero(), Q::PosInf).is_nan());
Source

pub fn pow_u32(self, e: u32) -> Q

self^e, total. pow_u32(a, 0) is 1 for every a including Nan, as IEEE NaN^0. A left fold of Q::mul, associating like the kernel.

use the_q::{Q, Rat};

let two = Q::number(Rat::new(2, 1).unwrap());
assert_eq!(two.pow_u32(3), Q::number(Rat::new(8, 1).unwrap()));
assert!(Q::Nan.pow_u32(0).is_one());
Source

pub fn checked_add(a: Q, b: Q) -> Option<Rat>

a + b as a Rat, None otherwise. A view over Q::add; cannot panic.

use the_q::{Q, Rat};

assert_eq!(Q::checked_add(Q::one(), Q::one()), Some(Rat::new(2, 1).unwrap()));
assert_eq!(Q::checked_add(Q::PosInf, Q::one()), None);
Source

pub fn checked_sub(a: Q, b: Q) -> Option<Rat>

a - b when the result is a representable rational. See Q::checked_add.

use the_q::{Q, Rat};

assert_eq!(Q::checked_sub(Q::one(), Q::one()), Some(Rat::zero()));
assert_eq!(Q::checked_sub(Q::Nan, Q::one()), None);
Source

pub fn checked_mul(a: Q, b: Q) -> Option<Rat>

a * b as a Rat, None otherwise. Can succeed on a saturated operand: Number(0) * PosSat is 0.

use the_q::{Q, Rat};

assert_eq!(Q::checked_mul(Q::zero(), Q::PosSat), Some(Rat::zero()));
assert_eq!(Q::checked_mul(Q::one(), Q::PosSat), None);
Source§

impl Q

Source

pub fn neg(self) -> Q

-self, exact and total; saturations and infinities negate onto each other.

use the_q::Q;

assert_eq!(Q::one().neg(), Q::neg_one());
assert_eq!(Q::PosSat.neg(), Q::NegSat);
assert_eq!(Q::PosInf.neg(), Q::NegInf);
assert!(Q::Nan.neg().is_nan());
Source

pub fn abs(self) -> Q

|self|, exact and total. Not injective on the specials, which is why neg carries class-preservation postconditions and this does not.

use the_q::Q;

assert_eq!(Q::neg_one().abs(), Q::one());
assert_eq!(Q::NegSat.abs(), Q::PosSat);
assert_eq!(Q::NegInf.abs(), Q::PosInf);
Source§

impl Q

Source

pub fn min(a: Q, b: Q) -> Q

The smaller of a and b, propagating Nan; not Ord-based selection.

use the_q::Q;

assert_eq!(Q::min(Q::zero(), Q::one()), Q::zero());
// Unlike `Ord::min`, a `Nan` operand makes the result `Nan`.
assert!(Q::min(Q::Nan, Q::one()).is_nan());
Source

pub fn max(a: Q, b: Q) -> Q

The larger of a and b, propagating Nan. See Q::min.

use the_q::Q;

assert_eq!(Q::max(Q::zero(), Q::one()), Q::one());
assert!(Q::max(Q::Nan, Q::one()).is_nan());
Source

pub fn clamp(a: Q, lo: Q, hi: Q) -> Q

a clamped into [lo, hi]; Nan in any argument, or an inverted range, gives Nan rather than an endpoint that asserts a false value.

use the_q::{Q, Rat};

let half = Q::number(Rat::new(1, 2).unwrap());
assert_eq!(Q::clamp(half, Q::zero(), Q::one()), half);
let two = Q::number(Rat::new(2, 1).unwrap());
assert_eq!(Q::clamp(two, Q::zero(), Q::one()), Q::one());
// An inverted range has no consistent answer.
assert!(Q::clamp(half, Q::one(), Q::zero()).is_nan());
Source§

impl Q

Source

pub fn div(a: Q, b: Q) -> Q

a / b, total. Division by zero follows IEEE 754 uniformly, so that recip(x) == div(one, x) holds at zero. Sat / Inf is exactly 0 and Inf / Sat a signed infinity, because saturation denotes finite reals.

use the_q::{Q, Rat};

assert_eq!(Q::div(Q::one(), Q::one()), Q::one());
// Division by zero follows IEEE 754: a signed infinity, and `0/0` is `Nan`.
assert_eq!(Q::div(Q::one(), Q::zero()), Q::PosInf);
assert!(Q::div(Q::zero(), Q::zero()).is_nan());
Source

pub fn recip(self) -> Q

1 / self, total, defined as div(one, self) (theorem_recip_is_div_one). Exact on a nonzero Number: swapping a canonical pair cannot round.

use the_q::{Q, Rat};

let two = Q::number(Rat::new(2, 1).unwrap());
assert_eq!(two.recip(), Q::number(Rat::new(1, 2).unwrap()));
assert_eq!(Q::zero().recip(), Q::PosInf);
Source

pub fn checked_div(a: Q, b: Q) -> Option<Rat>

a / b as a Rat, None otherwise, including a zero divisor.

use the_q::{Q, Rat};

assert_eq!(Q::checked_div(Q::one(), Q::one()), Some(Rat::one()));
assert_eq!(Q::checked_div(Q::one(), Q::zero()), None);
Source§

impl Q

Source

pub fn compare(a: Q, b: Q) -> i32

Three-way comparison: negative, zero or positive as a < b, a == b or a > b in the order above.

The comparison is total. There is no incomparable pair, because Nan has a definite position.

use the_q::Q;

assert_eq!(Q::compare(Q::zero(), Q::one()), -1);
assert_eq!(Q::compare(Q::one(), Q::one()), 0);
// `Nan` sorts last, above every other state.
assert_eq!(Q::compare(Q::PosInf, Q::Nan), -1);
Source

pub fn lt(a: Q, b: Q) -> bool

a < b.

use the_q::Q;

assert!(Q::lt(Q::zero(), Q::one()));
assert!(!Q::lt(Q::one(), Q::one()));
Source

pub fn le(a: Q, b: Q) -> bool

a <= b.

use the_q::Q;

assert!(Q::le(Q::one(), Q::one()));
assert!(!Q::le(Q::one(), Q::zero()));
Source

pub fn gt(a: Q, b: Q) -> bool

a > b.

use the_q::Q;

assert!(Q::gt(Q::one(), Q::zero()));
assert!(!Q::gt(Q::zero(), Q::zero()));
Source

pub fn ge(a: Q, b: Q) -> bool

a >= b.

use the_q::Q;

assert!(Q::ge(Q::one(), Q::one()));
assert!(!Q::ge(Q::zero(), Q::one()));
Source§

impl Q

Source

pub fn sqrt(self) -> Q

The square root. Negative → Nan; PosSat → Nan (its image reaches below MAX_MAG); PosInf → PosInf. Seven Newton steps from the integer-root seed.

use the_q::Q;

assert_eq!(Q::new(4, 1).sqrt(), Q::new(2, 1));
assert_eq!(Q::PosSat.sqrt(), Q::Nan);
Source§

impl Q

Source

pub fn exp(self) -> Q

e^self. PosSat above 43.67 (where e^x > MAX_MAG), 0 below -44; exp(NegSat) is Nan because the image (0, e^-MAX_MAG) does not contain zero, whereas underflow of a Number is inside R3. Evaluated by crate::fx::fx_exp_reduced and reassembled here; the m >= 62 branch keeps results between 2^61 and MAX_MAG numeric.

Accuracy is measured, not proven.

use the_q::Q;

let e2 = Q::new(2, 1).exp();
if let Q::Number(x) = e2 {
    assert!((the_q::to_f64(x) - 7.38905609893065).abs() < 1e-9);
} else {
    panic!("expected a number");
}
assert_eq!(Q::new(100, 1).exp(), Q::PosSat);
Source§

impl Q

Source

pub fn ln(self) -> Q

The natural logarithm. ln(0) is NegInf; negative and PosSat are Nan. Binary reduction to m ∈ [1/2, 2], then ln(m) = 2·atanh((m-1)/(m+1)) with |argument| <= 1/3, plus k·ln 2.

use the_q::Q;

assert_eq!(Q::one().ln(), Q::zero());
assert_eq!(Q::zero().ln(), Q::NegInf);
assert_eq!(Q::new(-1, 1).ln(), Q::Nan);
Source

pub fn pow_i32(self, e: i32) -> Q

self^e; pow_i32(a, -n) is recip(pow_u32(a, n)), so pow_i32(0, -1) is PosInf.

use the_q::Q;

assert_eq!(Q::new(2, 1).pow_i32(3), Q::new(8, 1));
assert_eq!(Q::zero().pow_i32(-1), Q::PosInf);
Source§

impl Q

Source

pub fn atan(self) -> Q

The arctangent in (-π/2, π/2); atan(±∞) = ±π/2, atan(PosSat) is Nan. Reduced by |x| > 1 → π/2 − atan(1/x) and |x| > 1/2 → π/4 + atan((x−1)/(x+1)) to |x| <= 1/2 before the series.

use the_q::Q;
use the_q::transcendental::half_pi;

assert_eq!(Q::PosInf.atan(), half_pi());
assert_eq!(Q::PosSat.atan(), Q::Nan);
Source

pub fn sin(self) -> Q

The sine. Nan for |x| > 2^20 and for every special. Reduction r = x − round(x / (π/2)) · π/2, then the series selected by n mod 4.

use the_q::Q;

assert_eq!(Q::zero().sin(), Q::zero());
assert_eq!(Q::new((1i64 << 20) + 1, 1).sin(), Q::Nan);
Source

pub fn cos(self) -> Q

The cosine. Same domain and method as Q::sin.

use the_q::Q;

assert_eq!(Q::zero().cos(), Q::one());
assert_eq!(Q::new((1i64 << 20) + 1, 1).cos(), Q::Nan);
Source

pub fn tan(self) -> Q

The tangent, as sin/cos.

At an odd multiple of π/2 the cosine is near zero. The quotient then saturates or gives an infinity, and does not trap. tan has a pole at those points.

use the_q::Q;

assert_eq!(Q::zero().tan(), Q::zero());
assert_eq!(Q::new((1i64 << 20) + 1, 1).tan(), Q::Nan);
Source§

impl Q

Source

pub fn log2(self) -> Q

The base-2 logarithm. Exact at 2^k and 1 / 2^k for every power of two a Rat holds (k <= 61; MAX_MAG is 2^62 - 1), where it returns the integer k (or -k); otherwise ln(self) / ln(2), whose accuracy is measured, not proven.

Without the exact path log2(8) is a rational within 2^-59 of 3, not 3: ln(8) mixes the runtime series value of ln 2 with the stored ln2() literal, and the two differ by one grid unit. The exponent is found by comparison against the verified power table, so the exactness is a proven postcondition, not an accident of rounding.

use the_q::Q;

assert_eq!(Q::new(8, 1).log2(), Q::new(3, 1));
assert_eq!(Q::new(1, 1024).log2(), Q::new(-10, 1));
assert_eq!(Q::one().log2(), Q::zero());

// Off the powers of two it is a series result near the true value.
let Q::Number(x) = Q::new(10, 1).log2() else { panic!() };
assert!((the_q::to_f64(x) - 10f64.log2()).abs() < 1e-15);
assert_eq!(Q::zero().log2(), Q::NegInf);
Source

pub fn log10(self) -> Q

The base-10 logarithm. Exact at 10^k and 1 / 10^k for k <= 18 (10^18 is the largest power of ten a Rat holds), where it returns the integer k (or -k); otherwise ln(self) / ln(10), whose accuracy is measured, not proven. See log2 for why the exact path exists.

use the_q::Q;

assert_eq!(Q::new(1000, 1).log10(), Q::new(3, 1));
assert_eq!(Q::new(1, 100).log10(), Q::new(-2, 1));
assert_eq!(Q::one().log10(), Q::zero());

let Q::Number(x) = Q::new(2, 1).log10() else { panic!() };
assert!((the_q::to_f64(x) - 2f64.log10()).abs() < 1e-15);
Source

pub fn log(self, base: Q) -> Q

The logarithm in an arbitrary base: log2 when base is exactly 2, log10 when it is exactly 10 (so their exact paths apply), and ln(self) / ln(base) otherwise.

A base of 1 gives a zero denominator, thus an infinity or Nan. The function log_1 is undefined.

use the_q::Q;

assert_eq!(Q::new(8, 1).log(Q::new(2, 1)), Q::new(3, 1));
assert_eq!(Q::new(1000, 1).log(Q::new(10, 1)), Q::new(3, 1));
let Q::Number(x) = Q::new(9, 1).log(Q::new(3, 1)) else { panic!() };
assert!((the_q::to_f64(x) - 2.0).abs() < 1e-15);
assert_eq!(Q::new(8, 1).log(Q::one()), Q::PosInf);
Source

pub fn exp2(self) -> Q

2^self, as exp(self · ln 2).

Accuracy is measured, not proven; the result need not be the exact rational power.

use the_q::Q;

let r = Q::new(3, 1).exp2();
if let Q::Number(x) = r {
    assert!((the_q::to_f64(x) - 8.0).abs() < 1e-9);
} else {
    panic!("expected a number");
}
Source

pub fn powf(self, exponent: Q) -> Q

self^exponent as exp(exponent · ln(self)): Nan for a negative base (use Q::pow_i32 for integer exponents); 0^0 is 1.

use the_q::Q;

let r = Q::new(2, 1).powf(Q::new(3, 1));
if let Q::Number(x) = r {
    assert!((the_q::to_f64(x) - 8.0).abs() < 1e-9);
} else {
    panic!("expected a number");
}
assert_eq!(Q::new(-1, 1).powf(Q::new(2, 1)), Q::Nan);
Source

pub fn cbrt(self) -> Q

The cube root on the whole real line, as ±exp(ln|x| / 3).

Accuracy is measured, not proven.

use the_q::Q;

let r = Q::new(8, 1).cbrt();
if let Q::Number(x) = r {
    assert!((the_q::to_f64(x) - 2.0).abs() < 1e-9);
} else {
    panic!("expected a number");
}
assert_eq!(Q::PosSat.cbrt(), Q::Nan);
Source

pub fn hypot(self, other: Q) -> Q

sqrt(self² + other²) as |a|·sqrt(1 + (b/a)²) with a the larger, so the square stays representable when a² + b² does not.

use the_q::Q;

assert_eq!(Q::new(3, 1).hypot(Q::new(4, 1)), Q::new(5, 1));
assert_eq!(Q::zero().hypot(Q::zero()), Q::zero());
Source

pub fn sinh(self) -> Q

(e^x − e^-x) / 2; beyond |x| > 22 it is ±e^(|x| − ln 2) to within the grid, which saturates cleanly instead of dividing a PosSat by two.

use the_q::Q;

assert_eq!(Q::zero().sinh(), Q::zero());
assert_eq!(Q::new(100, 1).sinh(), Q::PosSat);
Source

pub fn cosh(self) -> Q

The hyperbolic cosine, (e^x + e^-x) / 2, with the same large-argument path as Q::sinh.

use the_q::Q;

assert_eq!(Q::zero().cosh(), Q::one());
assert_eq!(Q::new(100, 1).cosh(), Q::PosSat);
Source

pub fn tanh(self) -> Q

sinh / cosh; ±1 beyond |x| >= 22 (where 1 − |tanh x| < 2^-62) and for the infinite and saturated states.

use the_q::Q;

assert_eq!(Q::zero().tanh(), Q::zero());
assert_eq!(Q::new(100, 1).tanh(), Q::one());
assert_eq!(Q::PosInf.tanh(), Q::one());
Source

pub fn asin(self) -> Q

The arcsine, in [-π/2, π/2].

The result is Nan outside [-1, 1], where there is no real answer. The function computes the endpoints directly. The identity below divides by zero at those two points.

use the_q::Q;
use the_q::transcendental::half_pi;

assert_eq!(Q::one().asin(), half_pi());
assert_eq!(Q::new(2, 1).asin(), Q::Nan);
Source

pub fn acos(self) -> Q

The arccosine, in [0, π], as π/2 - asin(self).

use the_q::Q;

assert_eq!(Q::one().acos(), Q::zero());
let r = Q::zero().acos();
if let Q::Number(x) = r {
    assert!((the_q::to_f64(x) - std::f64::consts::FRAC_PI_2).abs() < 1e-9);
} else {
    panic!("expected a number");
}
Source

pub fn atan2(self, x: Q) -> Q

The angle of (x, y) in (-π, π]; atan2(0, 0) is Nan.

use the_q::Q;

assert_eq!(Q::zero().atan2(Q::one()), Q::zero());
assert_eq!(Q::zero().atan2(Q::zero()), Q::Nan);

Trait Implementations§

Source§

impl Add for Q

Source§

type Output = Q

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Q) -> Q

Performs the + operation. Read more
Source§

impl Clone for Q

Source§

fn clone(&self) -> Q

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Q

Source§

impl Debug for Q

Source§

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

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

impl Default for Q

Q::zero() — the additive identity, and the identity Sum folds from.

Source§

fn default() -> Q

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

impl<'de> Deserialize<'de> for Q

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Q

Source§

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

"num/den" for a number, and the fixed spelling above for each special.

Every output round-trips through FromStr.

Source§

impl Div for Q

Total division. The note above states why this operator exists here and not on Rat.

Source§

type Output = Q

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Q) -> Q

Performs the / operation. Read more
Source§

impl Eq for Q

Source§

impl From<BigDecimal> for Q

Available on crate feature bigdecimal only.
Source§

fn from(v: BigDecimal) -> Self

Rounds to nearest; see q_from_bigdecimal.

Source§

impl From<BigInt> for Q

Available on crate feature num-bigint only.
Source§

fn from(v: BigInt) -> Self

Source§

impl From<Decimal> for Q

Available on crate feature rust_decimal only.
Source§

fn from(v: Decimal) -> Self

Rounds to nearest; see q_from_rust_decimal.

Source§

impl From<Ratio<BigInt>> for Q

Available on crate feature num-rational only.
Source§

fn from(v: BigRational) -> Self

Rounds to nearest; see q_from_big_rational.

Source§

impl From<Ratio<i64>> for Q

Available on crate feature num-rational only.
Source§

fn from(v: Ratio<i64>) -> Self

Rounds to nearest; see q_from_num_rational_i64.

Source§

impl FromStr for Q

Source§

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

Parses what Display produces, plus a bare integer. Specials are case-insensitive; surrounding whitespace is rejected.

Source§

type Err = ParseQError

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

impl Hash for Q

Source§

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

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

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

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

impl Mul for Q

Source§

type Output = Q

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Q) -> Q

Performs the * operation. Read more
Source§

impl Neg for Q

Source§

type Output = Q

The resulting type after applying the - operator.
Source§

fn neg(self) -> Q

Performs the unary - operation. Read more
Source§

impl Ord for Q

Source§

fn cmp(&self, other: &Q) -> Ordering

Delegates to the verified Q::compare. Do not use for selection: Ord-based min(Nan, Number(5)) asserts the value 5.

1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Q

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Q

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Q

Available on crate feature serde only.

A number as the (num, den) pair, a special as its string. Untagged, so it decodes only in self-describing formats; bincode fails at run time.

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Q

Source§

impl Sub for Q

Source§

type Output = Q

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Q) -> Q

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Freeze for Q

§

impl RefUnwindSafe for Q

§

impl Send for Q

§

impl Sync for Q

§

impl Unpin for Q

§

impl UnsafeUnpin for Q

§

impl UnwindSafe for Q

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

fn to_string(&self) -> String

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.