[][src]Struct qd::Double

pub struct Double(_, _);

A 128-bit floating-point number implemented as the unevaluated sum of two 64-bit floating-point numbers. Discarding the bits used for exponents, this makes for about 106 bits of mantissa accuracy, or around 31 decimal digits.

There are several ways to create a new Double:

What kind of number you actually end up getting depends on the method called to get it. new will not normalize its result. This means that the arguments must be pre-normalized. from, parse, and dd! will both account for floating-point rounding error and produce normalized results.

The reason for these two different ways of going about creation is speed. If the number is already pre-computed to take normalization and error into account (as all of the constants in this library are), then new offers a way to avoid having to pay the efficiency cost of unnecessary normalization.

For the other methods, shortcuts can be taken if the input is a number and that number is dyadic (i.e., it can be represented in binary exactly, without rounding). In this case, from and dd! can also skip normalization and accounting for rounding, and they won't be much slower than new.

Parsing from strings or from numbers that are not dyadic cannot take these shortcuts. The results will be precise, but at the cost of speed.

See the module-level documentation for more information.

Implementations

impl Double[src]

pub const RADIX: u32[src]

The radix or base of the internal representation of Double. This is the same as the representation in the underlying f64.

pub const MANTISSA_DIGITS: u32[src]

Number of significant digits in base 2.

pub const DIGITS: u32[src]

Approximate number of significant digits in base 10.

pub const EPSILON: Double[src]

Machine epsilon value for Double.

This is the difference between 1.0 and the next largest representable number.

pub const MIN: Double[src]

Smallest finite Double value.

pub const MIN_POSITIVE: Double[src]

Smallest positive normal Double value.

pub const MAX: Double[src]

Largest finite Double value.

pub const MIN_EXP: i32[src]

One greater than the minimum possible normal power of 2 exponent.

pub const MAX_EXP: i32[src]

Maximum possible power of 2 exponent.

pub const MIN_10_EXP: i32[src]

Minimum possible normal power of 10 exponent.

pub const MAX_10_EXP: i32[src]

Maximum possible power of 10 exponent.

pub const NAN: Double[src]

Not a Number (NaN).

pub const INFINITY: Double[src]

Infinity (∞).

pub const NEG_INFINITY: Double[src]

Negative infinity (-∞).

pub const ZERO: Double[src]

Zero (0)

pub const NEG_ZERO: Double[src]

Negative zero (-0)

pub const ONE: Double[src]

One (1)

pub const NEG_ONE: Double[src]

Negative one (-1)

pub const PI: Double[src]

Archimedes' constant (π)

pub const TAU: Double[src]

The full circle constant (τ), or 2π

pub const FRAC_PI_2: Double[src]

π/2

pub const FRAC_PI_3: Double[src]

π/3

pub const FRAC_PI_4: Double[src]

π/4

pub const FRAC_PI_6: Double[src]

π/6

pub const FRAC_PI_8: Double[src]

π/8

pub const FRAC_PI_16: Double[src]

π/16

pub const FRAC_3_PI_2: Double[src]

3π/2

pub const FRAC_3_PI_4: Double[src]

3π/4

pub const FRAC_5_PI_4: Double[src]

5π/4

pub const FRAC_7_PI_4: Double[src]

7π/4

pub const FRAC_1_PI: Double[src]

1/π

pub const FRAC_2_PI: Double[src]

2/π

pub const FRAC_2_SQRT_PI: Double[src]

2/√π

pub const SQRT_2: Double[src]

√2

pub const FRAC_1_SQRT_2: Double[src]

1/√2

pub const E: Double[src]

Euler's number (e)

pub const LOG2_10: Double[src]

log2 10

pub const LOG2_E: Double[src]

log2 e

pub const LOG10_2: Double[src]

log10 2

pub const LOG10_E: Double[src]

log10 e

pub const LN_2: Double[src]

loge 2

pub const LN_10: Double[src]

loge 10

impl Double[src]

pub fn ldexp(self, n: i32) -> Double[src]

Calculates x · 2n, where x is the Double and n is an integer.

Though this is not an everyday operation, it is often used in more advanced mathematical calculations (including several within this library). Therefore an implementation that is much more efficient than calculating it through multiplication and powi is offered despite it not being part of the f64 API.

Examples

let x = dd!(5);
assert!(x.ldexp(3) == dd!(40)); // 5 * 2^3

pub fn sqr(self) -> Double[src]

Calculates the square of the Double.

This method takes advantage of optimizations in multiplication that are available when the two numbers being multiplied are the same, so it is more efficient than bare multiplication.

Examples

let x = dd!(3);
assert!(x.sqr() == x * x); // The left side is faster though

pub fn sqrt(self) -> Double[src]

Calculates the square root of the Double.

Examples

let x = dd!(2).sqrt();
let diff = (x - Double::SQRT_2).abs();
assert!(diff < dd!(1e-30));

pub fn nroot(self, n: i32) -> Double[src]

Calculates the nth root of the Double.

Examples

let x = dd!(2).nroot(4);
let expected = dd!("1.1892071150027210667174999705605");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn cbrt(self) -> Double[src]

Calculates the cube root of the Double.

Examples

let x = dd!(2).cbrt();
let expected = dd!("1.2599210498948731647672106072782");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn powi(self, n: i32) -> Double[src]

Calculates the Double raised to an integer power.

This function correctly handles the special inputs defined in IEEE 754. In particular:

  • x.powi(0) is 1 for any x (including 0, NaN, or infinity)
  • x.powi(n) is ±∞ for x = ±0 and any odd negative n
  • x.powi(n) is +∞ for x = ±0 and any even negative n
  • x.powi(n) is ±0 for x = ±0 and any odd positive n
  • x.powi(n) is +0 for x = ±0 and any even positive n

Examples

let x = dd!(3);
assert!(x.powi(3) == dd!(27));

pub fn powf(self, n: Double) -> Double[src]

Calculates the Double raised to a Quad power.

In general, xn is equal to en ln x. This precludes raising a negative Double to a fractional or irrational power because ln x is undefined when x is negative. In that case, this function returns NAN.

It's actually more complex than that; if the exponent can be expressed as a fraction with an odd denominator, then there is an answer (a cube root, which is defined for negative numbers, is the same as a power of 1/3). Therefore, something like dd!(-4).powf(dd!(0.2)) should work, as 0.2 is a fraction with an odd denominator (1/5). However, it's impossible in general to tell whether a number is a fraction while using floating-point numbers, so no attempt is made to make this work. If you need a fifth root of -4, use dd!(-4).nroot(5).

Examples

let x = dd!(3).powf(dd!(3.3));
let expected = dd!("37.540507598529552193101865954634");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-28));

pub fn recip(self) -> Double[src]

Calculates the reciprocal of the Double.

Examples

let x = Double::PI.recip();
let expected = dd!("0.31830988618379067153776752674503");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Double[src]

pub fn sinh_cosh(self) -> (Double, Double)[src]

Simultaneously computes the hyperbolic sine and cosine (sinh and cosh) of the Double.

The domain of this function is (-∞, ∞), and the range is (-∞, ∞) for the first component of the answer (the hyperbolic sine) and [1, ∞) for the second (the hyperbolic cosine).

This method is more efficient to run than sinh and cosh individually and is useful when both numbers are needed.

Examples

let (sin_h, cos_h) = dd!(1).sinh_cosh();
let esin = dd!("1.1752011936438014568823818505956");
let ecos = dd!("1.5430806348152437784779056207571");

let diff1 = (sin_h - esin).abs();
let diff2 = (cos_h - ecos).abs();

assert!(diff1 < dd!(1e-30));
assert!(diff2 < dd!(1e-30));

pub fn sinh(self) -> Double[src]

Computes the hyperbolic sine (sinh) of the Double.

The domain and range of this function are both (-∞, ∞). Large values will start to cause a loss of precision; by the time the number is ±130 or so, precision is down to 29 digits.

Examples

let x = dd!(1).sinh();
let expected = dd!("1.1752011936438014568823818505956");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn cosh(self) -> Double[src]

Computes the hyperbolic cosine (cosh) of the Double.

The domain of this function is (-∞, ∞), and the range is [1, ∞).

Examples

let x = dd!(1).cosh();
let expected = dd!("1.5430806348152437784779056207571");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn tanh(self) -> Double[src]

Computes the hyperbolic tangent (tanh) of the Double.

The domain of this function is (-∞, ∞), and the range is (-1, 1).

Examples

let x = dd!(1).tanh();
let expected = dd!("0.76159415595576488811945828260479");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn asinh(self) -> Double[src]

Calculates the inverse hyperbolic sine (sinh-1) of the Double.

The domain and range of this function are both (-∞, ∞).

Examples

let x = dd!(1.5).asinh();
let expected = dd!("1.1947632172871093041119308285191");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn acosh(self) -> Double[src]

Calculates the inverse hyperbolic cosine (cosh-1) of the Double.

The domain of the function is [1, ∞) and the range is [0, ∞). Any argument outside the range will result in NAN.

Examples

let x = dd!(1.5).acosh();
let expected = dd!("0.96242365011920689499551782684874");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn atanh(self) -> Double[src]

Calculates the inverse hyperbolic tangent (tanh-1) of the Double.

The domain of the function is (-1, 1) and the range is (-∞, ∞). Any argument whose absolute value is greater than or equal to 1 will result in NAN.

Examples

let x = dd!(0.5).atanh();
let expected = dd!("0.54930614433405484569762261846126");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Double[src]

pub fn abs(self) -> Double[src]

Calculates the absolute value of the Double.

Examples

assert!(dd!(3).abs() == dd!(3));
assert!(dd!(-3).abs() == dd!(3));

pub fn floor(self) -> Double[src]

Returns the largest integer value less than or equal to the Double.

Examples

let f = dd!(3.99);
let g = dd!(3.0);
let h = dd!(-3.99);

assert!(f.floor() == dd!(3));
assert!(g.floor() == dd!(3));
assert!(h.floor() == dd!(-4));

pub fn ceil(self) -> Double[src]

Returns the smallest integer value greater than or equal to the Double.

Examples

let f = dd!(3.01);
let g = dd!(4.0);
let h = dd!(-3.01);

assert!(f.ceil() == dd!(4));
assert!(g.ceil() == dd!(4));
assert!(h.ceil() == dd!(-3));

pub fn round(self) -> Double[src]

Returns the nearest integer value to the Double. Half-way cases are rounded away from 0.0, per the behavior of f64's round method.

Examples

let f = dd!(3.3);
let g = dd!(3.5);
let h = dd!(-3.3);

assert!(f.round() == dd!(3));
assert!(g.round() == dd!(4));
assert!(h.round() == dd!(-3));

pub fn trunc(self) -> Double[src]

Returns the integer part of the Double.

Examples

let f = dd!(3.3);
let g = dd!(-3.7);

assert!(f.trunc() == dd!(3));
assert!(g.trunc() == dd!(-3));

pub fn fract(self) -> Double[src]

Returns the fractional part of the Double.

Examples

let f = dd!(3.3);
let g = dd!(-3.7);

let fdiff = (f.fract() - dd!(0.3)).abs();
let gdiff = (g.fract() - dd!(-0.7)).abs();

assert!(fdiff < dd!(1e-30));
assert!(gdiff < dd!(1e-30));

pub fn signum(self) -> Double[src]

Returns a number that represents the sign of the Double.

  • 1.0 if the number is positive, including +0.0 and INFINITY
  • -1.0 if the number is negative, including -0.0 and NEG_INFINITY
  • NAN if the number is NAN

Examples

assert!(dd!(3.5).signum() == Double::ONE);
assert!(Double::NEG_INFINITY.signum() == Double::NEG_ONE);
assert!(Double::NAN.signum().is_nan());

pub fn classify(self) -> FpCategory[src]

Returns the floating point category of the Double.

The possible return values are the members of FpCategory, as follows:

  • FpCategory::Zero if the number is ±0;
  • FpCategory::Infinite if the number is ±∞;
  • FpCategory::Nan if the number is not a number;
  • FpCategory::Subnormal if the number is ±MIN_POSITIVE (numbers this small can be represented, but they lose some accuracy);
  • FpCategory::Normal if the number is anything else.

Examples

use std::num::FpCategory;

let num = dd!(12.4);
let inf = Double::INFINITY;

assert!(num.classify() == FpCategory::Normal);
assert!(inf.classify() == FpCategory::Infinite);

pub fn is_normal(self) -> bool[src]

Returns true if the Double is neither zero, infinite, subnormal, or NaN.

Examples

let min = Double::MIN_POSITIVE;
let max = Double::MAX;
let lower = dd!(1e-308);
let zero = Double::ZERO;

assert!(min.is_normal());
assert!(max.is_normal());

assert!(!zero.is_normal());
assert!(!Double::NAN.is_normal());
assert!(!Double::INFINITY.is_normal());
// Values between `0` and `MIN_POSITIVE` are subnormal.
assert!(!lower.is_normal());

pub fn is_zero(self) -> bool[src]

Returns true if the Double is either positive or negative zero.

Examples

assert!(Double::ZERO.is_zero());
assert!(Double::NEG_ZERO.is_zero());
assert!(!Double::PI.is_zero());

pub fn is_sign_negative(self) -> bool[src]

Returns true if the Double is negative, including negative zero, negative infinity, and NaN with a negative sign bit.

Examples

assert!(Double::NEG_ZERO.is_sign_negative());
assert!(Double::NEG_INFINITY.is_sign_negative());
assert!(dd!(-7.0).is_sign_negative());
assert!(!Double::ZERO.is_sign_negative());
assert!(!dd!(7.0).is_sign_negative());

pub fn is_sign_positive(self) -> bool[src]

Returns true if the Double is positive, including positive zero, positive infinity and NaN with a positive sign bit.

Examples

assert!(Double::ZERO.is_sign_positive());
assert!(Double::INFINITY.is_sign_positive());
assert!(dd!(7.0).is_sign_positive());
assert!(!Double::NEG_ZERO.is_sign_positive());
assert!(!dd!(-7.0).is_sign_positive());

pub fn is_nan(self) -> bool[src]

Returns true if the Double is NaN.

This is the proper way to test for NaN because it cannot be done with an equality test (since NaN is not equal to itself).

Examples

assert!(Double::NAN.is_nan());
assert!(!dd!(7.0).is_nan());

pub fn is_infinite(self) -> bool[src]

Returns true if the Double is positive or negative infinity.

Examples

assert!(Double::INFINITY.is_infinite());
assert!(Double::NEG_INFINITY.is_infinite());
assert!(!Double::NAN.is_infinite());
assert!(!dd!(7.0).is_infinite());

pub fn is_finite(self) -> bool[src]

Returns true if the Double is neither infinite nor NaN.

Examples

assert!(!Double::INFINITY.is_finite());
assert!(!Double::NEG_INFINITY.is_finite());
assert!(!Double::NAN.is_finite());
assert!(dd!(7.0).is_finite());

pub fn is_subnormal(self) -> bool[src]

Returns true if the Double has an absolute value of less than MIN_POSITIVE.

Numbers this small can be represented by floating point numbers, but they are not as accurate. This inaccuracy is inherent in the IEEE-754 format for 64-bit numbers; making a double-double out of an inaccurate number means the double-double is also going to be inaccurate.

Examples

assert!(!Double::PI.is_subnormal());
assert!(dd!(1e-308).is_subnormal());

impl Double[src]

pub fn exp(self) -> Double[src]

Computes the exponential function, ex, where x is this Double.

The result of this function grows rapidly. Once x exceeds 708, the result is too large to represent with a Double; at that point the function begins to return INFINITY. The limit on the low end is less due to the fact that the second component needs to fit in an f64 rather than the first, along with extra bits used in argument reduction; this function begins to return 0 at -600.

As x grows this function does lose a bit of precision. It's precise to at least 30 digits up to values of -140 <= x <= 150, and from then until the limits, it's precise to at least 29 digits.

Examples

let x = dd!(2).exp();
let expected = dd!("7.3890560989306502272304274605750057");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-29));

pub fn ln(self) -> Double[src]

Calculates the natural logarithm, loge, of the Double.

This calculation relies upon the exp calculation, in the opposite direction. A large positive logarithm, for example, will require the calculation of a large negative exponential.

For the same reasons that negative values of exp are limited to -600, the accurate results of this function are limited to the number whose logarithm is 600, which is around 2.65 × 10261. Take care with this; unlike in exp, INFINITY is not returned. In that function, exceeding the maximum refers to actually overflowing an f64, which is appropriate to call INFINITY; here, it means 601.

Examples

let x = dd!(7).ln();
let expected = dd!("1.9459101490553133051053527434432");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-29));

pub fn log10(self) -> Double[src]

Calculates the base-10 logarithm, log10, of the Double.

As with ln, this has an upper usable range less than the size of the numbers themselves. In this case, that upper limit is around 10261. Over this number, the output is not reliable, but it does not return INFINITY because the number 261 is so plainly not infinite.

Examples

let x = Double::E.log10();
let expected = dd!("0.434294481903251827651128918916605");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn log2(self) -> Double[src]

Calculates the base-2 logarithm, log2, of the Double.

Since 2 is smaller than e, this function is constrained even more than ln. It will start returning NEG_INFINITY at around 10-213 and will start to fail on the positive side at around 2.6 × 10180.

Examples

let x = dd!(10).log2();
let expected = dd!("3.32192809488736234787031942948939");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-29));

pub fn log(self, b: Double) -> Double[src]

Calculates the base b logarithm (logb) of the Double.

This function will have limits at extreme arguments like the other logarithm functions. The difference is that those limits will depend on the base argument.

If the goal is to calculate the base e, base 2, or base 10 logarithms of self, the specialized functions for those purposes(ln, log2, and log10 respectively) will be more efficient.

Examples

let x = dd!(10).log(dd!(7.0));
let expected = dd!("1.18329466245493832681792856164686");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-29));

impl Double[src]

pub fn sin_cos(self) -> (Double, Double)[src]

Simultaneously computes the sine (sin) and the cosine (cos) of the Double. This is more efficient than calling the separate sin and cos functions if you need both numbers.

Examples

let x = Double::PI / dd!(4);
let (sin_x, cos_x) = x.sin_cos();

let diff_sin = (sin_x - x.sin()).abs();
let diff_cos = (cos_x - x.cos()).abs();

assert!(diff_sin < dd!(1e-30));
assert!(diff_cos < dd!(1e-30));

pub fn sin(self) -> Double[src]

Computes the sine (sin) of the Double.

The domain of this function is (-∞, ∞), and the range is [-1, 1].

Examples

let x = (Double::PI / dd!(2)).sin();
let expected = dd!(1);

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn cos(self) -> Double[src]

Computes the cosine (cos) of the Double.

The domain of this function is (-∞, ∞), and the range is [-1, 1].

Examples

let x = (Double::PI / dd!(2)).cos();
let expected = dd!(0);

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn tan(self) -> Double[src]

Computes the tangent (tan) of the Double.

The domain and range of this function are both (-∞, ∞).

Examples

let x = (Double::PI / dd!(4)).tan();
let expected = dd!(1);

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn atan2(self, other: Double) -> Double[src]

Computes the 2-argument inverse tangent (tan-1) of this Double and another Double.

The single-argument atan function always returns values in either the first (0 to π/2) or fourth (0 to -π/2) quadrants. However, first-quadrant results repeat themselves in the third quadrant, and fourth-quadrant results repeat themselves in the second. For example, the tangent of π/4 is 1, but so is the tangent of -3π/4. Single-argument atan cannot distinguish between these two possibilities, so it always returns the one in the range [-π/2, π/2].

The double-argument atan2 can return either, depending on the arguments. It essentially returns the angle between the positive x-axis and the point (x, y), where y is the Double that atan2 is called on and x is the argument. Therefore Double::ONE.atan2(Double::ONE) is π/4 (first quadrant), but flipping both signs to (Double::NEG_ONE).atan2(Double::NEG_ONE) gives the -3π/4 result (third quadrant).

This function extends the range of the result to [-π, π].

Because this function deals with angles around the origin and Cartesian coordinates, it's very useful for converting between Cartesian and polar coordinates.

Examples

let pi = Double::PI;

// -π/4 radians (45 degrees clockwise)
let x1 = dd!(3);
let y1 = dd!(-3);
let expected1 = -Double::FRAC_PI_4;

// 3π/4 radians (135 degrees counter-clockwise)
let x2 = dd!(-3);
let y2 = dd!(3);
let expected2 = Double::FRAC_3_PI_4;

let diff1 = (y1.atan2(x1) - expected1).abs();
let diff2 = (y2.atan2(x2) - expected2).abs();

assert!(diff1 < dd!(1e-30));
assert!(diff2 < dd!(1e-30));

pub fn asin(self) -> Double[src]

Computes the inverse sine (sin-1) of the Double. The domain of this function is [-1, 1] while the range is [-π/2, π/2]. Arguments outside of this domain will result in NAN.

Examples

let x = dd!(1).asin();
let expected = Double::PI / dd!(2);  // π/2

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn acos(self) -> Double[src]

Computes the inverse cosine (cos-1) of the Double. The domain of this function is [-1, 1] and the range is [0, π]. Arguments outside of the domain will result in NAN.

Examples

let x = dd!(1).acos();
let expected = dd!(0);

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

pub fn atan(self) -> Double[src]

Computes the inverse tangent (tan-1) of the Double. The domain of this function is [-∞, ∞] and the range is [-π/2, π/2].

Examples

let x = dd!(1).atan();
let expected = Double::PI / dd!(4);  // π/4

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Double[src]

pub const fn new(a: f64, b: f64) -> Double[src]

Creates a Double with the two arguments as the internal components.

Be sure you know what you're doing if you use this function. It does not normalize its components, meaning that if they aren't already normalized by the caller, this number will not work the way one would expect (it'll fail equality tests that it should pass, it may be classified incorrectly, etc.).

This function is primarily for creating constants where the normalization is obviously unnecessary. For example, if a Double version of the number 10 is needed, Double::new(10.0, 0.0) is a good way to do it in order to save the cost of the normalization that is obviously not needed.

Examples

let d = Double::new(0.0, 0.0);
assert!(d.is_zero());

Trait Implementations

impl Add<&'_ Double> for &Double[src]

type Output = Double

The resulting type after applying the + operator.

fn add(self, other: &Double) -> Double[src]

Adds a reference to this Double to another, producing a new Double as a result.

This implements the + operator between two references to Doubles.

Examples

let x = &Double::E + &Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Add<&'_ Double> for Double[src]

type Output = Double

The resulting type after applying the + operator.

fn add(self, other: &Double) -> Double[src]

Adds this Double to a reference to another Double, producing a new Double as a result.

This implements the + operator between a Double and a reference to a Double.

Examples

let x = Double::E + &Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Add<Double> for Double[src]

type Output = Double

The resulting type after applying the + operator.

fn add(self, other: Double) -> Double[src]

Adds this Double to another, producing a new Double as a result.

This implements the + operator between two Doubles.

Examples

let x = Double::E + Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Add<Double> for &Double[src]

type Output = Double

The resulting type after applying the + operator.

fn add(self, other: Double) -> Double[src]

Adds a reference to this Double to another Double, producing a new Double as a result.

This implements the + operator between a refernce to a Double and a Double.

Examples

let x = &Double::E + Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl AddAssign<&'_ Double> for Double[src]

fn add_assign(&mut self, other: &Double)[src]

Adds a reference to another Double to this Double, modifying this one to equal the result.

This implements the += operator between a Double and a reference to a Double.

Examples

let mut x = Double::E;
x += &Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl AddAssign<Double> for Double[src]

fn add_assign(&mut self, other: Double)[src]

Adds another Double to this one, modifying this one to equal the result.

This implements the += operator between two Doubles.

Examples

let mut x = Double::E;
x += Double::PI;
let expected = dd!("5.859874482048838473822930854632");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Clone for Double[src]

impl Copy for Double[src]

impl Debug for Double[src]

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

Formats a Double for display when the "?" formatting option is specified.

See Display::fmt for more information.

impl Default for Double[src]

impl Display for Double[src]

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

Formats a Double for display.

All formatting options that are shown in std::fmt are supported except for ones that are typically meant only for integers (hexadecimal, binary, octal, and pointer formats). Because of this, the "alternate" (#) flag is only recognized along with ?, pretty-printing the Debug output.

By default, Doubles are printed with 31 digits but drop trailing zeros.

This function also provides the formatting for to_string, which renders the Double as if formatted with an empty format specifier ("{}").

Examples

assert!(format!("{}", dd!(1.5)) == "1.5");

// The next digit in π is 0, which is why it's one digit shorter than e
assert!(format!("{}", Double::PI) == "3.14159265358979323846264338328");
assert!(format!("{}", Double::E) == "2.718281828459045235360287471353");

// to_string renders as if formatted with "{}"
assert!(Double::PI.to_string() == "3.14159265358979323846264338328");

// debug
assert!(format!("{:?}", Double::PI) ==
    "Double(3.141592653589793e0, 1.2246467991473532e-16)");
assert!(format!("{:#?}", Double::PI) ==
"Double(
    3.141592653589793e0,
    1.2246467991473532e-16
)");

// precision and exponents
let value = dd!(0.016_777_216);
assert!(format!("{:.0}", value) == "0");
assert!(format!("{:.5}", value) == "0.01678");
assert!(format!("{:.12}", value) == "0.016777216000");
assert!(format!("{:.3e}", value) == "1.678e-2");
assert!(format!("{:.*e}", 3, value) == "1.678e-2");
assert!(format!("{0:.1$E}", value, 4) == "1.6777E-2");
assert!(format!("{:.prec$E}", value, prec = 10) == "1.6777216000E-2");

// width, alignment, and fill
let value = dd!(123_456);
assert!(format!("{:10}", value) == "    123456"); // right-align is the default
assert!(format!("{:>10}", value) == "    123456");
assert!(format!("{:<10}", value) == "123456    ");
assert!(format!("{:^10}", value) == "  123456  ");
assert!(format!("{:0>10}", value) == "0000123456");
assert!(format!("{:*<10}", value) == "123456****");
assert!(format!("{:'^10}", value) == "''123456''");

// plus sign and sign-aware zero fill
let value = dd!(123_456);
assert!(format!("{:+}", value) == "+123456");
assert!(format!("{:0>10}", -value) == "000-123456");
assert!(format!("{:010}", -value) == "-000123456");
assert!(format!("{:+012e}", value) == "+001.23456e5");

impl Div<&'_ Double> for &Double[src]

type Output = Double

The resulting type after applying the / operator.

fn div(self, other: &Double) -> Double[src]

Divides a reference to this Double by another, producing a new Double as a result.

This implements the / operator between two references to Doubles.

Examples

let x = &Double::E / &Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Div<&'_ Double> for Double[src]

type Output = Double

The resulting type after applying the / operator.

fn div(self, other: &Double) -> Double[src]

Divides this Double by a reference to another Double, producing a new Double as a result.

This implements the / operator between a Double and a reference to a Double.

Examples

let x = Double::E / &Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Div<Double> for Double[src]

type Output = Double

The resulting type after applying the / operator.

fn div(self, other: Double) -> Double[src]

Divides this Double by another, producing a new Double as a result.

This implements the / operator between two Doubles.

Examples

let x = Double::E / Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Div<Double> for &Double[src]

type Output = Double

The resulting type after applying the / operator.

fn div(self, other: Double) -> Double[src]

Divides a reference to this Double by another Double, producing a new Double as a result.

This implements the / operator between a reference to a Double and a Double.

Examples

let x = &Double::E / Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl DivAssign<&'_ Double> for Double[src]

fn div_assign(&mut self, other: &Double)[src]

Divides this Double by a reference to another, modifying this one to equal the result.

This implements the /= operator between a Double and a reference to a Double.

Examples

let mut x = Double::E;
x /= &Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl DivAssign<Double> for Double[src]

fn div_assign(&mut self, other: Double)[src]

Divides this Double by another, modifying this one to equal the result.

This implements the /= operator between two Doubles.

Examples

let mut x = Double::E;
x /= Double::PI;
let expected = dd!("0.8652559794322650872177747896461");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl From<&'_ str> for Double[src]

fn from(s: &str) -> Double[src]

Parses a string to create a Double.

The parser works pretty similarly to parsers for f32 and f64. It will fail if characters are present that are not digits, decimal points, signs, or exponent markers. It will also fail if there are multiples of these or if they're in the wrong places; two decimal points or a negative sign after the number will both be rejected, for instance.

Failure will return NAN. This can be an issue because parsing the string "nan" also produces NAN. For this reason it's suggested to use from_str (or its associated parse function) instead of this function if there is any chance that the parsed string will be legitimately NAN.

Examples

let expected = (dd!(3).powi(15) - dd!(1)) / dd!(3).powi(15);
let x = Double::from("0.9999999303082806237436760862691");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl From<(f64, f64)> for Double[src]

fn from((a, b): (f64, f64)) -> Double[src]

Generates a Double from a 2-tuple of f64s.

This conversion acts like new does: it assumes that if you're creating a Double out of a pair of numbers, you already know what you want those numbers to be. Therefore it neither renormalizes or accounts for rounding error.

No other From implementations are provided for tuples. There is no way to provide a pre-normalized pair of integers, and since tuple conversion doesn't adjust for rounding error, it's better to make the user explicity cast f32s first in the manner of their choosing.

Examples

// These are the components used to define Double::PI
let d = Double::from((3.141592653589793e0, 1.2246467991473532e-16));
assert!(d == Double::PI);

impl From<Double> for f64[src]

fn from(a: Double) -> f64[src]

Converts a Double into an f64.

This will lose precision if the second component of the Double is not 0, but it will not lose range.

No other conversions from Double to numeric types are provided, as every other one has the capability of losing range (for example, no other type could be used to represent dd!(1e308)). Casts can be made from the f64 provided by this function to other numeric types as needed.

Examples

let a = Double::PI;
let x = f64::from(a);

let diff = (x - std::f64::consts::PI).abs();
assert!(diff < 1e-15);

impl From<Double> for (f64, f64)[src]

fn from(a: Double) -> (f64, f64)[src]

Converts a Double into a tuple of f64s.

The components of the double become the components of the returned tuple. Note that, while the value of the first component is simply the f64 cast of the Double itself, the second component encodes the next digits of the Double plus the rounding error in the first component. For that reason, it's not likely to be very useful outside of a Double context.

Examples

let (a, b) = <(f64, f64)>::from(Double::PI);
assert!(a == 3.141592653589793e0);
assert!(b == 1.2246467991473532e-16); // *not* the next 16 digits of π

impl From<Double> for Quad[src]

fn from(a: Double) -> Quad[src]

Generates a Quad from a Double.

The new Quad's third and fourth components will be used to account for floating-point rounding error at the end of the Double, but it will of course otherwise only have the precision of the Double used to make it.

Examples

let expected = Quad::from("0.9999999303082806237436760862691");
let a = (dd!(3).powi(15) - dd!(1)) / dd!(3).powi(15);
let x = Quad::from(a);

let diff = (x - expected).abs();
assert!(diff < qd!(1e-60));

impl From<f32> for Double[src]

Generates a Double from an f32.

This function does account for floating point rounding error. Even though the first component of a Double is enough to fit an f32, if that f32 is not exactly representable in binary, then the second component of the Double will account for the rounding error.

Note that in order to do this, the f32 needs to be parsed digit by digit. While the parser does work quite fast with integers or any f32 that is represented perfectly in binary (any number that can be represented as a fraction with a power of 2 in the denominator), it's not a particularly fast operation otherwise.

Examples

// Exactly representable in binary
let x = 0.9921875f32;
let a = Double::from(x);
assert!(a.to_string() == "0.9921875");

// Xot exactly representable in binary
let x = 0.9921876f32;
let a = Double::from(x);
assert!(a.to_string() == "0.9921876");

impl From<f64> for Double[src]

Generates a Double from an f64.

This function does account for floating point rounding error. Even though the first component of a Double is enough to fit an f64, if that f64 is not exactly representable in binary, then the second component of the Double will account for the rounding error.

Note that in order to do this, the f64 needs to be parsed digit by digit. While the parser does work quite fast with integers or any f64 that is represented perfectly in binary (any number that can be represented as a fraction with a power of 2 in the denominator), it's not a particularly fast operation otherwise.

Examples

// Exactly representable in binary
let x = 0.999969482421875f64;
let a = Double::from(x);
assert!(a.to_string() == "0.999969482421875");

// Not exactly representable in binary
let x = 0.999969482421876f64;
let a = Double::from(x);
assert!(a.to_string() == "0.999969482421876");

impl From<i16> for Double[src]

Generates a Double from an i16.

Examples

let x = -32768i16;
let a = Double::from(x);
assert!(a.to_string() == "-32768");

impl From<i32> for Double[src]

Generates a Double from an i32.

Examples

let x = -2_147_483_648i32;
let a = Double::from(x);
assert!(a.to_string() == "-2147483648");

impl From<i64> for Double[src]

fn from(a: i64) -> Double[src]

Generates a Double from an i64.

Examples

let x = -9_223_372_036_854_775_808i64;
let a = Double::from(x);
assert!(a.to_string() == "-9223372036854775808");

impl From<i8> for Double[src]

Generates a Double from an i8.

Examples

let x = -128i8;
let a = Double::from(x);
assert!(a.to_string() == "-128");

impl From<u16> for Double[src]

Generates a Double from a u8.

Examples

let x = 65535u16;
let a = Double::from(x);
assert!(a.to_string() == "65535");

impl From<u32> for Double[src]

Generates a Double from a u32.

Examples

let x = 4_294_967_295u32;
let a = Double::from(x);
assert!(a.to_string() == "4294967295");

impl From<u64> for Double[src]

fn from(a: u64) -> Double[src]

Generates a Double from a u64.

Examples

let x = 18_446_744_073_709_551_615u64;
let a = Double::from(x);
assert!(a.to_string() == "18446744073709551615");

impl From<u8> for Double[src]

Generates a Double from a u8.

Examples

let x = 255u8;
let a = Double::from(x);
assert!(a.to_string() == "255");

impl FromStr for Double[src]

type Err = ParseDoubleError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Double, ParseDoubleError>[src]

Parses a string to create a Double.

The parser works pretty similarly to parsers for f32 and f64. It will fail if characters are present that are not digits, decimal points, signs, or exponent markers. It will also fail if there are multiples of these or if they're in the wrong places; two decimal points or a negative sign after the number will both be rejected, for instance.

Failure will return a ParseDoubleError of some kind.

Examples

use std::str::FromStr;

let expected = (dd!(3).powi(15) - dd!(1)) / dd!(3).powi(15);

let x1 = Double::from_str("0.9999999303082806237436760862691").unwrap();
// `parse` calls `from_str` in the background, so this is equivalent. In fact it's
// probably preferred because it doesn't require importing `FromStr`. The turbofish
// (or type annotation on x2, if you prefer) is required instead if the type can't
// otherwise be inferred.
let x2 = "0.9999999303082806237436760862691".parse::<Double>().unwrap();

let diff1 = (x1 - expected).abs();
assert!(diff1 < dd!(1e-30));

let diff2 = (x2 - expected).abs();
assert!(diff2 < dd!(1e-30));

impl Index<usize> for Double[src]

type Output = f64

The returned type after indexing.

fn index(&self, idx: usize) -> &f64[src]

Returns one of the components of the Double.

Using index 0 will return the first component and using index 1 will return the second.

One capability that is not provided is mutable indexing; ensuring that a Double is normalized would be impossible if they could be individually changed at will. Doubles are immutable like any other number; if you need a new value for a Double, you should simply create a new Double.

This is primarily provided for making certain mathematical algorithms easier to implement. There isn't a lot meaning to an individual component of a Double other than the first.

Examples

let d = Double::ONE;
assert!(d[0] == 1.0);
assert!(d[1] == 0.0);

impl LowerExp for Double[src]

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

Formats a Double for display when the "e" formatting option is specified.

See Display::fmt for more information.

impl Mul<&'_ Double> for &Double[src]

type Output = Double

The resulting type after applying the * operator.

fn mul(self, other: &Double) -> Double[src]

Multiplies a reference to this Double by another, producing a new Double as a result.

This implements the * operator between two references to Doubles.

Examples

let x = &Double::E * &Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Mul<&'_ Double> for Double[src]

type Output = Double

The resulting type after applying the * operator.

fn mul(self, other: &Double) -> Double[src]

Multiplies this Double by a reference to another, producing a new Double as a result.

This implements the * operator between a Double and a reference to a Double.

Examples

let x = Double::E * &Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Mul<Double> for Double[src]

type Output = Double

The resulting type after applying the * operator.

fn mul(self, other: Double) -> Double[src]

Multiplies this Double by another, producing a new Double as a result.

This implements the * operator between two Doubles.

Examples

let x = Double::E * Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Mul<Double> for &Double[src]

type Output = Double

The resulting type after applying the * operator.

fn mul(self, other: Double) -> Double[src]

Multiplies a reference to this Double by another Double, producing a new Double as a result.

This implements the * operator between a reference to a Double and a Double.

Examples

let x = &Double::E * Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl MulAssign<&'_ Double> for Double[src]

fn mul_assign(&mut self, other: &Double)[src]

Multiples this Double by a reference to another one, modifying this one to equal the result.

This implements the *= operator between a Double and a reference to a Double.

Examples

let mut x = Double::E;
x *= &Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl MulAssign<Double> for Double[src]

fn mul_assign(&mut self, other: Double)[src]

Multiples this Double by another one, modifying this one to equal the result.

This implements the *= operator between two Doubles.

Examples

let mut x = Double::E;
x *= Double::PI;
let expected = dd!("8.539734222673567065463550869547");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Neg for Double[src]

type Output = Double

The resulting type after applying the - operator.

fn neg(self) -> Double[src]

Negates this Double, producing a new Double.

This implements the unary - operator for Doubles.

Examples

let x = -Double::PI;
let expected = dd!("-3.1415926535897932384626433832795");

let diff = (x - expected).abs();
assert!(x < dd!(1e-30));

impl Neg for &Double[src]

type Output = Double

The resulting type after applying the - operator.

fn neg(self) -> Double[src]

Negates a reference to this Double, producing a new Double.

This implements the unary - operator for references to Doubles.

Examples

let x = -&Double::PI;
let expected = dd!("-3.1415926535897932384626433832795");

let diff = (x - expected).abs();
assert!(x < dd!(1e-30));

impl PartialEq<Double> for Double[src]

fn eq(&self, other: &Double) -> bool[src]

Implements the == and != operators, testing two Double`s for equality and inequality.

Equality works exactly the same as it does for system floating-point numbers (f64, etc.), including zero equalling negative zero, NaN equalling nothing (including itself), etc. Notably, equality should be used with care since floating-point rounding, even with the increased precision of Doubles, will still cause some numbers that should be equal to not be equal.

Examples

assert!(Double::PI == Double::PI);
assert!(Double::E != Double::PI);
assert!(dd!(0.0) == dd!(-0.0));
assert!(Double::NAN != Double::NAN);

impl PartialOrd<Double> for Double[src]

fn partial_cmp(&self, other: &Double) -> Option<Ordering>[src]

Implements the <, >, <=, and >= operators, testing two Doubles for ordering.

Ordering works the same as it does for system floating-point numbers, including NAN returning false for any of these operators (including when comparing it to itself).

Examples

assert!(Double::PI > Double::E);
assert!(dd!(0.0) <= dd!(-0.0));
assert!(!(Double::NAN >= Double::NAN));

impl<'a> Product<&'a Double> for Double[src]

fn product<I>(iter: I) -> Double where
    I: Iterator<Item = &'a Double>, 
[src]

Multiples all of the referenced values in an iterator of Doubles.

Examples

use std::iter::Product;

let expected = dd!(120);
let actual: Double = vec![dd!(1), dd!(2), dd!(3), dd!(4), dd!(5)].iter().product();
assert!(expected == actual);

impl Product<Double> for Double[src]

fn product<I>(iter: I) -> Double where
    I: Iterator<Item = Double>, 
[src]

Multiplies all of the values in an iterator of Doubles.

Examples

use std::iter::Product;

let expected = dd!(120);
let actual: Double = vec![dd!(1), dd!(2), dd!(3), dd!(4), dd!(5)].into_iter().product();
assert!(expected == actual);

impl Rem<&'_ Double> for &Double[src]

type Output = Double

The resulting type after applying the % operator.

fn rem(self, other: &Double) -> Double[src]

Divides a reference to this Double by another, producing a new Double of the remainder as a result. This operation uses floored division.

This implements the % operator between two references to Doubles.

Examples

let x = &Double::PI % &Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let y = &Double::PI % -Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl Rem<&'_ Double> for Double[src]

type Output = Double

The resulting type after applying the % operator.

fn rem(self, other: &Double) -> Double[src]

Divides this Double by a reference to another, producing a new Double of the remainder as a result. This operation uses floored division.

This implements the % operator between a Double and a reference to a Double.

Examples

let x = Double::PI % &Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let y = Double::PI % -&Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl Rem<Double> for Double[src]

type Output = Double

The resulting type after applying the % operator.

fn rem(self, other: Double) -> Double[src]

Divides this Double by another, producing a new Double of the remainder as a result. This operation uses floored division.

This implements the % operator between two Doubles.

Examples

let x = Double::PI % Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let y = Double::PI % -Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl Rem<Double> for &Double[src]

type Output = Double

The resulting type after applying the % operator.

fn rem(self, other: Double) -> Double[src]

Divides a reference to this Double by another Double, producing a new Double of the remainder as a result. This operation uses floored division.

This implements the % operator between a reference to a Doubles and a Double.

Examples

let x = &Double::PI % Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let y = &Double::PI % -&Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl RemAssign<&'_ Double> for Double[src]

fn rem_assign(&mut self, other: &Double)[src]

Divides this Double by a reference to another, modifying this one to equal the remainder. This operation uses floored division.

This implements the %= operator between a Double and a reference to a Double.

Examples

let mut x = Double::PI;
x %= &Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let mut y = Double::PI;
y %= -&Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl RemAssign<Double> for Double[src]

fn rem_assign(&mut self, other: Double)[src]

Divides this Double by another, modifying this one to equal the remainder. This operation uses floored division.

This implements the %= operator between two Doubles.

Examples

let mut x = Double::PI;
x %= Double::E;
let xpected = dd!("0.4233108251307480031023559119268");

let diffx = (x - xpected).abs();
assert!(diffx < dd!(1e-30));

let mut y = Double::PI;
y %= -Double::E;
let ypected = dd!("-2.2949710033282972322579315594258");

let diffy = (y - ypected).abs();
assert!(diffy < dd!(1e-30));

impl Sub<&'_ Double> for &Double[src]

type Output = Double

The resulting type after applying the - operator.

fn sub(self, other: &Double) -> Double[src]

Subtracts another reference to a Double from this one, producing a new Double as a result.

This implements the binary - operator between two references to Doubles.

Examples

let x = &Double::E - &Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Sub<&'_ Double> for Double[src]

type Output = Double

The resulting type after applying the - operator.

fn sub(self, other: &Double) -> Double[src]

Subtracts another reference to a Double from this Double, producing a new Double as a result.

This implements the binary - operator between a Double and a reference to a Double.

Examples

let x = Double::E - &Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Sub<Double> for Double[src]

type Output = Double

The resulting type after applying the - operator.

fn sub(self, other: Double) -> Double[src]

Subtracts another Double from this one, producing a new Double as a result.

This implements the binary - operator between two Doubles.

Examples

let x = Double::E - Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl Sub<Double> for &Double[src]

type Output = Double

The resulting type after applying the - operator.

fn sub(self, other: Double) -> Double[src]

Subtracts another Double from a reference to this one, producing a new Double as a result.

This implements the binary - operator between a reference to a Double and a Double.

Examples

let x = &Double::E - Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl SubAssign<&'_ Double> for Double[src]

fn sub_assign(&mut self, other: &Double)[src]

Subtracts a reference to another Double from this one, modifying this one to equal the result.

This implements the -= operator between a Double and a reference to a Double.

Examples

let mut x = Double::E;
x -= &Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl SubAssign<Double> for Double[src]

fn sub_assign(&mut self, other: Double)[src]

Subtracts another Double from this one, modifying this one to equal the result.

This implements the -= operator between two Doubles.

Examples

let mut x = Double::E;
x -= Double::PI;
let expected = dd!("-0.4233108251307480031023559119268");

let diff = (x - expected).abs();
assert!(diff < dd!(1e-30));

impl<'a> Sum<&'a Double> for Double[src]

fn sum<I>(iter: I) -> Double where
    I: Iterator<Item = &'a Double>, 
[src]

Sums all of the referenced values in an iterator of Doubles.

Examples

use std::iter::Sum;

let expected = dd!(15);
let actual: Double = vec![dd!(1), dd!(2), dd!(3), dd!(4), dd!(5)].iter().sum();
assert!(expected == actual);

impl Sum<Double> for Double[src]

fn sum<I>(iter: I) -> Double where
    I: Iterator<Item = Double>, 
[src]

Sums all of the values in an iterator of Doubles.

Examples

use std::iter::Sum;

let expected = dd!(15);
let actual: Double = vec![dd!(1), dd!(2), dd!(3), dd!(4), dd!(5)].into_iter().sum();
assert!(expected == actual);

impl UpperExp for Double[src]

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

Formats a Double for display when the "E" formatting option is specified.

See Display::fmt for more information.

Auto Trait Implementations

impl RefUnwindSafe for Double[src]

impl Send for Double[src]

impl Sync for Double[src]

impl Unpin for Double[src]

impl UnwindSafe for Double[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.