docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

core::num::impl f64

On this page

impl f64

  • pub const fn is_close(self, other: f64, rel: f64 = 1e-9, abs: f64 = 0.0, equal_nan: bool = false) -> bool§

    Source

    Whether self and other are equal or within a relative tolerance rel of the larger magnitude, or within abs: symmetric, Python's math.isclose. The default rel (1e-9) asks for about nine equal digits; near zero only abs helps, so pass it when comparing with 0. Infinities are close only to themselves, NaN to nothing (unless equal_nan).

    nabi
    assert((0.1 + 0.2).is_close(0.3));
    assert(!1e-12.is_close(0.0) && 1e-12.is_close(0.0, abs: 1e-9));
    assert(100.0.is_close(101.0, rel: 0.01));
    
  • pub const EPSILON: f64 = 2.2204460492503131e-16§

    Source

    The gap between 1.0 and the next larger value.

  • pub const MAX: f64 = 1.7976931348623157e308§

    Source

    The largest value.

  • pub const MIN: f64 = -1.7976931348623157e308§

    Source

    The smallest value.

  • pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308§

    Source

    The smallest positive normal value.

  • pub const NAN: f64 = f64::from_bits(0x7ff8_0000_0000_0000)§

    Source

    Not a number: the quiet NaN with the sign bit clear on every target.

  • pub const INFINITY: f64 = 1.0 / 0.0§

    Source

    Positive infinity.

  • pub const NEG_INFINITY: f64 = -1.0 / 0.0§

    Source

    Negative infinity.

  • pub const PI: f64 = 3.14159265358979323846264338327950288§

    Source

    Pi.

  • pub const TAU: f64 = 6.28318530717958647692528676655900577§

    Source

    tau = 2 pi.

  • pub const E: f64 = 2.71828182845904523536028747135266250§

    Source

    Euler's number e.

  • pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144§

    Source

    pi/2.

  • pub const FRAC_PI_4: f64 = 0.785398163397448309615660845819875721§

    Source

    pi/4.

  • pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724§

    Source

    1/pi.

  • pub const SQRT_2: f64 = 1.41421356237309504880168872420969808§

    Source

    sqrt(2).

  • pub const FRAC_1_SQRT_2: f64 = 0.707106781186547524400844362104849039§

    Source

    1/sqrt(2).

  • pub const LN_2: f64 = 0.693147180559945309417232121458176568§

    Source

    ln 2.

  • pub const LN_10: f64 = 2.30258509299404568401799145468436421§

    Source

    ln 10.

  • pub const LOG2_E: f64 = 1.44269504088896340735992468100189214§

    Source

    log2(e).

  • pub const LOG10_E: f64 = 0.434294481903251827651128918916605082§

    Source

    log10(e).

  • pub const fn sqrt(self) -> f64§

    Source

    The square root; NaN for a negative value (as √self).

  • pub const fn total_cmp(self, other: f64) -> core::cmp::Ordering§

    Source

    The IEEE 754 total order: -NaN < -inf < .. < -0 < +0 < .. < inf < NaN. Sorting by it never fails: xs.sort_by(f64::total_cmp).

  • pub const fn to_bits(self) -> u64§

    Source

    The IEEE 754 bit pattern.

  • pub const fn from_bits(bits: u64) -> f64§

    Source

    The f64 with the IEEE 754 bit pattern bits.

  • pub const fn is_nan(self) -> bool§

    Source

    true for NaN.

  • pub const fn is_infinite(self) -> bool§

    Source

    true for inf or -inf.

  • pub const fn is_finite(self) -> bool§

    Source

    true unless infinite or NaN.

  • pub const fn is_normal(self) -> bool§

    Source

    Neither zero, subnormal, infinite nor NaN.

  • pub const fn is_sign_positive(self) -> bool§

    Source

    true when the sign bit is clear (0.0, +inf, a positive NaN).

  • pub const fn is_sign_negative(self) -> bool§

    Source

    true when the sign bit is set (-0.0, -inf, a negative NaN).

  • pub const fn floor(self) -> f64§

    Source

    Largest integer <= self.

  • pub const fn ceil(self) -> f64§

    Source

    Smallest integer >= self.

  • pub const fn round(self) -> f64§

    Source

    Nearest integer, halves away from zero.

  • pub const fn trunc(self) -> f64§

    Source

    Integer part (toward zero).

  • pub const fn abs(self) -> f64§

    Source

    The magnitude (sign bit cleared).

  • pub fn cbrt(self) -> f64§

    Source

    Cube root.

  • pub fn exp(self) -> f64§

    Source

    e^self.

  • pub fn exp2(self) -> f64§

    Source

    2^self.

  • pub fn exp_m1(self) -> f64§

    Source

    e^self - 1, exact near zero.

  • pub fn ln(self) -> f64§

    Source

    Natural logarithm.

  • pub fn ln_1p(self) -> f64§

    Source

    ln(1 + self), exact near zero.

  • pub fn log2(self) -> f64§

    Source

    Base-2 logarithm.

  • pub fn log10(self) -> f64§

    Source

    Base-10 logarithm.

  • pub fn sin(self) -> f64§

    Source

    Sine of self in radians.

  • pub fn cos(self) -> f64§

    Source

    Cosine of self in radians.

  • pub fn tan(self) -> f64§

    Source

    Tangent of self in radians.

  • pub fn asin(self) -> f64§

    Source

    Arcsine in radians, in [-pi/2, pi/2]; NaN outside [-1, 1].

  • pub fn acos(self) -> f64§

    Source

    Arccosine in radians, in [0, pi]; NaN outside [-1, 1].

  • pub fn atan(self) -> f64§

    Source

    Arctangent in radians, in [-pi/2, pi/2].

  • pub fn sinh(self) -> f64§

    Source

    Hyperbolic sine.

  • pub fn cosh(self) -> f64§

    Source

    Hyperbolic cosine.

  • pub fn tanh(self) -> f64§

    Source

    Hyperbolic tangent.

  • pub fn asinh(self) -> f64§

    Source

    Inverse hyperbolic sine.

  • pub fn acosh(self) -> f64§

    Source

    Inverse hyperbolic cosine; NaN below 1.

  • pub fn atanh(self) -> f64§

    Source

    Inverse hyperbolic tangent; NaN outside [-1, 1].

  • pub const fn fract(self) -> f64§

    Source

    self - self.trunc().

  • pub const fn signum(self) -> f64§

    Source

    -1.0 / 1.0 by sign; zeros and NaN are returned as they are.

  • pub const fn recip(self) -> f64§

    Source

    1.0 / self.

  • pub const fn to_degrees(self) -> f64§

    Source

    Radians to degrees.

  • pub const fn to_radians(self) -> f64§

    Source

    Degrees to radians.

  • pub fn log(self, base: f64) -> f64§

    Source

    ln(self) / ln(base).

  • pub fn pow(self, exp: f64) -> f64§

    Source

    self^exp (powf in Rust).

  • pub fn atan2(self, other: f64) -> f64§

    Source

    Angle of the point (other, self).

  • pub fn hypot(self, other: f64) -> f64§

    Source

    sqrt(self^2 + other^2) without overflow.

  • pub const fn copysign(self, sign: f64) -> f64§

    Source

    self's magnitude with sign's sign.

  • pub const fn min(self, other: f64) -> f64§

    Source

    The smaller; a NaN operand loses to a number.

  • pub const fn max(self, other: f64) -> f64§

    Source

    The larger; a NaN operand loses to a number.

  • pub fn powi(self, n: i32) -> f64§

    Source

    self to an integer power, by repeated multiplication: may round differently from pow(n as f64).

  • pub const fn mul_add(self, a: f64, b: f64) -> f64§

    Source

    self * a + b with one rounding.

  • pub const fn clamp(self, lo: f64, hi: f64) -> f64§

    Source

    self limited to lo..=hi; NaN stays NaN. Panics if lo > hi.

  • pub const fn div_euclid(self, rhs: f64) -> f64§

    Source

    The quotient rounded so that rem_euclid is never negative.

  • pub const fn rem_euclid(self, rhs: f64) -> f64§

    Source

    The remainder in [0, |rhs|); NaN when rhs is 0.

  • pub const fn lerp(self, other: f64, t: f64) -> f64§

    Source

    self at t = 0, other at t = 1, a straight line between and past them: exact at both ends and monotonic in t (C++ std::lerp).

  • pub const fn next_after(self, toward: f64) -> f64§

    Source

    The next representable value after self in the direction of toward (C nextafter); toward itself when equal, NaN if either is.

  • pub const fn next_up(self) -> f64§

    Source

    The least value greater than self; infinity and NaN stay.

  • pub const fn next_down(self) -> f64§

    Source

    The greatest value less than self; -infinity and NaN stay.