unsafe { intrinsics::fabsf32(*self) }
}
- /// The positive difference of two numbers. Returns `0.0` if the number is less than or
- /// equal to `other`, otherwise the difference between`self` and `other` is returned.
+ /// The positive difference of two numbers. Returns `0.0` if the number is
+ /// less than or equal to `other`, otherwise the difference between`self`
+ /// and `other` is returned.
#[inline]
fn abs_sub(&self, other: &f32) -> f32 {
unsafe { cmath::fdimf(*self, *other) }
impl Primitive for f32 {}
impl Float for f32 {
- fn powi(self, n: i32) -> f32 {
- unsafe { intrinsics::powif32(self, n) }
- }
-
- #[inline]
- fn max(self, other: f32) -> f32 {
- unsafe { cmath::fmaxf(self, other) }
- }
-
- #[inline]
- fn min(self, other: f32) -> f32 {
- unsafe { cmath::fminf(self, other) }
- }
-
#[inline]
fn nan() -> f32 { 0.0 / 0.0 }
self.classify() == FPNormal
}
- /// Returns the floating point category of the number. If only one property is going to
- /// be tested, it is generally faster to use the specific predicate instead.
+ /// Returns the floating point category of the number. If only one property
+ /// is going to be tested, it is generally faster to use the specific
+ /// predicate instead.
fn classify(self) -> FPCategory {
static EXP_MASK: u32 = 0x7f800000;
static MAN_MASK: u32 = 0x007fffff;
#[inline]
fn max_10_exp(_: Option<f32>) -> int { 38 }
- /// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
+ /// Constructs a floating point number by multiplying `x` by 2 raised to the
+ /// power of `exp`
#[inline]
fn ldexp(x: f32, exp: int) -> f32 {
unsafe { cmath::ldexpf(x, exp as c_int) }
}
- /// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
+ /// Breaks the number into a normalized fraction and a base-2 exponent,
+ /// satisfying:
///
/// - `self = x * pow(2, exp)`
/// - `0.5 <= abs(x) < 1.0`
}
}
- /// Returns the exponential of the number, minus `1`, in a way that is accurate
- /// even if the number is close to zero
- #[inline]
- fn exp_m1(self) -> f32 {
- unsafe { cmath::expm1f(self) }
- }
-
- /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
- /// than if the operations were performed separately
- #[inline]
- fn ln_1p(self) -> f32 {
- unsafe { cmath::log1pf(self) }
- }
-
- /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
- /// produces a more accurate result with better performance than a separate multiplication
- /// operation followed by an add.
- #[inline]
- fn mul_add(self, a: f32, b: f32) -> f32 {
- unsafe { intrinsics::fmaf32(self, a, b) }
- }
-
- /// Returns the next representable floating-point value in the direction of `other`
- #[inline]
- fn next_after(self, other: f32) -> f32 {
- unsafe { cmath::nextafterf(self, other) }
- }
-
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u32 = unsafe { cast::transmute(self) };
(mantissa as u64, exponent, sign)
}
+ /// Returns the next representable floating-point value in the direction of
+ /// `other`.
+ #[inline]
+ fn next_after(self, other: f32) -> f32 {
+ unsafe { cmath::nextafterf(self, other) }
+ }
+
/// Round half-way cases toward `NEG_INFINITY`
#[inline]
fn floor(self) -> f32 {
#[inline]
fn fract(self) -> f32 { self - self.trunc() }
- /// Archimedes' constant
- #[inline]
- fn pi() -> f32 { 3.14159265358979323846264338327950288 }
-
- /// 2.0 * pi
#[inline]
- fn two_pi() -> f32 { 6.28318530717958647692528676655900576 }
+ fn max(self, other: f32) -> f32 {
+ unsafe { cmath::fmaxf(self, other) }
+ }
- /// pi / 2.0
#[inline]
- fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144 }
+ fn min(self, other: f32) -> f32 {
+ unsafe { cmath::fminf(self, other) }
+ }
- /// pi / 3.0
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
+ /// error. This produces a more accurate result with better performance than
+ /// a separate multiplication operation followed by an add.
#[inline]
- fn frac_pi_3() -> f32 { 1.04719755119659774615421446109316763 }
+ fn mul_add(self, a: f32, b: f32) -> f32 {
+ unsafe { intrinsics::fmaf32(self, a, b) }
+ }
- /// pi / 4.0
+ /// The reciprocal (multiplicative inverse) of the number
#[inline]
- fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721 }
+ fn recip(self) -> f32 { 1.0 / self }
- /// pi / 6.0
- #[inline]
- fn frac_pi_6() -> f32 { 0.52359877559829887307710723054658381 }
+ fn powi(self, n: i32) -> f32 {
+ unsafe { intrinsics::powif32(self, n) }
+ }
- /// pi / 8.0
#[inline]
- fn frac_pi_8() -> f32 { 0.39269908169872415480783042290993786 }
+ fn powf(self, n: f32) -> f32 {
+ unsafe { intrinsics::powf32(self, n) }
+ }
- /// 1 .0/ pi
+ /// sqrt(2.0)
#[inline]
- fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724 }
+ fn sqrt2() -> f32 { 1.41421356237309504880168872420969808 }
- /// 2.0 / pi
+ /// 1.0 / sqrt(2.0)
#[inline]
- fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448 }
+ fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039 }
- /// 2.0 / sqrt(pi)
#[inline]
- fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517 }
+ fn sqrt(self) -> f32 {
+ unsafe { intrinsics::sqrtf32(self) }
+ }
- /// sqrt(2.0)
#[inline]
- fn sqrt2() -> f32 { 1.41421356237309504880168872420969808 }
+ fn rsqrt(self) -> f32 { self.sqrt().recip() }
- /// 1.0 / sqrt(2.0)
#[inline]
- fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039 }
+ fn cbrt(self) -> f32 {
+ unsafe { cmath::cbrtf(self) }
+ }
- /// Euler's number
#[inline]
- fn e() -> f32 { 2.71828182845904523536028747135266250 }
+ fn hypot(self, other: f32) -> f32 {
+ unsafe { cmath::hypotf(self, other) }
+ }
- /// log2(e)
+ /// Archimedes' constant
#[inline]
- fn log2_e() -> f32 { 1.44269504088896340735992468100189214 }
+ fn pi() -> f32 { 3.14159265358979323846264338327950288 }
- /// log10(e)
+ /// 2.0 * pi
#[inline]
- fn log10_e() -> f32 { 0.434294481903251827651128918916605082 }
+ fn two_pi() -> f32 { 6.28318530717958647692528676655900576 }
- /// ln(2.0)
+ /// pi / 2.0
#[inline]
- fn ln_2() -> f32 { 0.693147180559945309417232121458176568 }
+ fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144 }
- /// ln(10.0)
+ /// pi / 3.0
#[inline]
- fn ln_10() -> f32 { 2.30258509299404568401799145468436421 }
+ fn frac_pi_3() -> f32 { 1.04719755119659774615421446109316763 }
- /// The reciprocal (multiplicative inverse) of the number
+ /// pi / 4.0
#[inline]
- fn recip(self) -> f32 { 1.0 / self }
+ fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721 }
+ /// pi / 6.0
#[inline]
- fn powf(self, n: f32) -> f32 {
- unsafe { intrinsics::powf32(self, n) }
- }
+ fn frac_pi_6() -> f32 { 0.52359877559829887307710723054658381 }
+ /// pi / 8.0
#[inline]
- fn sqrt(self) -> f32 {
- unsafe { intrinsics::sqrtf32(self) }
- }
+ fn frac_pi_8() -> f32 { 0.39269908169872415480783042290993786 }
+ /// 1 .0/ pi
#[inline]
- fn rsqrt(self) -> f32 { self.sqrt().recip() }
+ fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724 }
+ /// 2.0 / pi
#[inline]
- fn cbrt(self) -> f32 {
- unsafe { cmath::cbrtf(self) }
- }
+ fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448 }
+ /// 2.0 / sqrt(pi)
#[inline]
- fn hypot(self, other: f32) -> f32 {
- unsafe { cmath::hypotf(self, other) }
- }
+ fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517 }
#[inline]
fn sin(self) -> f32 {
(self.sin(), self.cos())
}
+ /// Euler's number
+ #[inline]
+ fn e() -> f32 { 2.71828182845904523536028747135266250 }
+
+ /// log2(e)
+ #[inline]
+ fn log2_e() -> f32 { 1.44269504088896340735992468100189214 }
+
+ /// log10(e)
+ #[inline]
+ fn log10_e() -> f32 { 0.434294481903251827651128918916605082 }
+
+ /// ln(2.0)
+ #[inline]
+ fn ln_2() -> f32 { 0.693147180559945309417232121458176568 }
+
+ /// ln(10.0)
+ #[inline]
+ fn ln_10() -> f32 { 2.30258509299404568401799145468436421 }
+
/// Returns the exponential of the number
#[inline]
fn exp(self) -> f32 {
unsafe { intrinsics::exp2f32(self) }
}
+ /// Returns the exponential of the number, minus `1`, in a way that is
+ /// accurate even if the number is close to zero
+ #[inline]
+ fn exp_m1(self) -> f32 {
+ unsafe { cmath::expm1f(self) }
+ }
+
/// Returns the natural logarithm of the number
#[inline]
fn ln(self) -> f32 {
unsafe { intrinsics::log10f32(self) }
}
+ /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more
+ /// accurately than if the operations were performed separately
+ #[inline]
+ fn ln_1p(self) -> f32 {
+ unsafe { cmath::log1pf(self) }
+ }
+
#[inline]
fn sinh(self) -> f32 {
unsafe { cmath::sinhf(self) }
impl Primitive for f64 {}
impl Float for f64 {
- #[inline]
- fn max(self, other: f64) -> f64 {
- unsafe { cmath::fmax(self, other) }
- }
-
- #[inline]
- fn min(self, other: f64) -> f64 {
- unsafe { cmath::fmin(self, other) }
- }
-
#[inline]
fn nan() -> f64 { 0.0 / 0.0 }
self.classify() == FPNormal
}
- /// Returns the floating point category of the number. If only one property is going to
- /// be tested, it is generally faster to use the specific predicate instead.
+ /// Returns the floating point category of the number. If only one property
+ /// is going to be tested, it is generally faster to use the specific
+ /// predicate instead.
fn classify(self) -> FPCategory {
static EXP_MASK: u64 = 0x7ff0000000000000;
static MAN_MASK: u64 = 0x000fffffffffffff;
#[inline]
fn max_10_exp(_: Option<f64>) -> int { 308 }
- /// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
+ /// Constructs a floating point number by multiplying `x` by 2 raised to the
+ /// power of `exp`
#[inline]
fn ldexp(x: f64, exp: int) -> f64 {
unsafe { cmath::ldexp(x, exp as c_int) }
}
- /// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
+ /// Breaks the number into a normalized fraction and a base-2 exponent,
+ /// satisfying:
///
/// - `self = x * pow(2, exp)`
/// - `0.5 <= abs(x) < 1.0`
}
}
- /// Returns the exponential of the number, minus `1`, in a way that is accurate
- /// even if the number is close to zero
- #[inline]
- fn exp_m1(self) -> f64 {
- unsafe { cmath::expm1(self) }
- }
-
- /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
- /// than if the operations were performed separately
- #[inline]
- fn ln_1p(self) -> f64 {
- unsafe { cmath::log1p(self) }
- }
-
- /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
- /// produces a more accurate result with better performance than a separate multiplication
- /// operation followed by an add.
- #[inline]
- fn mul_add(self, a: f64, b: f64) -> f64 {
- unsafe { intrinsics::fmaf64(self, a, b) }
- }
-
- /// Returns the next representable floating-point value in the direction of `other`
- #[inline]
- fn next_after(self, other: f64) -> f64 {
- unsafe { cmath::nextafter(self, other) }
- }
-
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u64 = unsafe { cast::transmute(self) };
(mantissa, exponent, sign)
}
+ /// Returns the next representable floating-point value in the direction of
+ /// `other`.
+ #[inline]
+ fn next_after(self, other: f64) -> f64 {
+ unsafe { cmath::nextafter(self, other) }
+ }
+
/// Round half-way cases toward `NEG_INFINITY`
#[inline]
fn floor(self) -> f64 {
#[inline]
fn fract(self) -> f64 { self - self.trunc() }
- /// Archimedes' constant
- #[inline]
- fn pi() -> f64 { 3.14159265358979323846264338327950288 }
-
- /// 2.0 * pi
- #[inline]
- fn two_pi() -> f64 { 6.28318530717958647692528676655900576 }
-
- /// pi / 2.0
- #[inline]
- fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144 }
-
- /// pi / 3.0
#[inline]
- fn frac_pi_3() -> f64 { 1.04719755119659774615421446109316763 }
-
- /// pi / 4.0
- #[inline]
- fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721 }
+ fn max(self, other: f64) -> f64 {
+ unsafe { cmath::fmax(self, other) }
+ }
- /// pi / 6.0
#[inline]
- fn frac_pi_6() -> f64 { 0.52359877559829887307710723054658381 }
+ fn min(self, other: f64) -> f64 {
+ unsafe { cmath::fmin(self, other) }
+ }
- /// pi / 8.0
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
+ /// error. This produces a more accurate result with better performance than
+ /// a separate multiplication operation followed by an add.
#[inline]
- fn frac_pi_8() -> f64 { 0.39269908169872415480783042290993786 }
+ fn mul_add(self, a: f64, b: f64) -> f64 {
+ unsafe { intrinsics::fmaf64(self, a, b) }
+ }
- /// 1.0 / pi
+ /// The reciprocal (multiplicative inverse) of the number
#[inline]
- fn frac_1_pi() -> f64 { 0.318309886183790671537767526745028724 }
+ fn recip(self) -> f64 { 1.0 / self }
- /// 2.0 / pi
#[inline]
- fn frac_2_pi() -> f64 { 0.636619772367581343075535053490057448 }
+ fn powf(self, n: f64) -> f64 {
+ unsafe { intrinsics::powf64(self, n) }
+ }
- /// 2.0 / sqrt(pi)
#[inline]
- fn frac_2_sqrtpi() -> f64 { 1.12837916709551257389615890312154517 }
+ fn powi(self, n: i32) -> f64 {
+ unsafe { intrinsics::powif64(self, n) }
+ }
/// sqrt(2.0)
#[inline]
#[inline]
fn frac_1_sqrt2() -> f64 { 0.707106781186547524400844362104849039 }
- /// Euler's number
#[inline]
- fn e() -> f64 { 2.71828182845904523536028747135266250 }
+ fn sqrt(self) -> f64 {
+ unsafe { intrinsics::sqrtf64(self) }
+ }
- /// log2(e)
#[inline]
- fn log2_e() -> f64 { 1.44269504088896340735992468100189214 }
+ fn rsqrt(self) -> f64 { self.sqrt().recip() }
- /// log10(e)
#[inline]
- fn log10_e() -> f64 { 0.434294481903251827651128918916605082 }
+ fn cbrt(self) -> f64 {
+ unsafe { cmath::cbrt(self) }
+ }
- /// ln(2.0)
#[inline]
- fn ln_2() -> f64 { 0.693147180559945309417232121458176568 }
+ fn hypot(self, other: f64) -> f64 {
+ unsafe { cmath::hypot(self, other) }
+ }
- /// ln(10.0)
+ /// Archimedes' constant
#[inline]
- fn ln_10() -> f64 { 2.30258509299404568401799145468436421 }
+ fn pi() -> f64 { 3.14159265358979323846264338327950288 }
- /// The reciprocal (multiplicative inverse) of the number
+ /// 2.0 * pi
#[inline]
- fn recip(self) -> f64 { 1.0 / self }
+ fn two_pi() -> f64 { 6.28318530717958647692528676655900576 }
+ /// pi / 2.0
#[inline]
- fn powf(self, n: f64) -> f64 {
- unsafe { intrinsics::powf64(self, n) }
- }
+ fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144 }
+ /// pi / 3.0
#[inline]
- fn powi(self, n: i32) -> f64 {
- unsafe { intrinsics::powif64(self, n) }
- }
+ fn frac_pi_3() -> f64 { 1.04719755119659774615421446109316763 }
+ /// pi / 4.0
#[inline]
- fn sqrt(self) -> f64 {
- unsafe { intrinsics::sqrtf64(self) }
- }
+ fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721 }
+ /// pi / 6.0
#[inline]
- fn rsqrt(self) -> f64 { self.sqrt().recip() }
+ fn frac_pi_6() -> f64 { 0.52359877559829887307710723054658381 }
+ /// pi / 8.0
#[inline]
- fn cbrt(self) -> f64 {
- unsafe { cmath::cbrt(self) }
- }
+ fn frac_pi_8() -> f64 { 0.39269908169872415480783042290993786 }
+ /// 1.0 / pi
#[inline]
- fn hypot(self, other: f64) -> f64 {
- unsafe { cmath::hypot(self, other) }
- }
+ fn frac_1_pi() -> f64 { 0.318309886183790671537767526745028724 }
+
+ /// 2.0 / pi
+ #[inline]
+ fn frac_2_pi() -> f64 { 0.636619772367581343075535053490057448 }
+
+ /// 2.0 / sqrt(pi)
+ #[inline]
+ fn frac_2_sqrtpi() -> f64 { 1.12837916709551257389615890312154517 }
#[inline]
fn sin(self) -> f64 {
(self.sin(), self.cos())
}
+ /// Euler's number
+ #[inline]
+ fn e() -> f64 { 2.71828182845904523536028747135266250 }
+
+ /// log2(e)
+ #[inline]
+ fn log2_e() -> f64 { 1.44269504088896340735992468100189214 }
+
+ /// log10(e)
+ #[inline]
+ fn log10_e() -> f64 { 0.434294481903251827651128918916605082 }
+
+ /// ln(2.0)
+ #[inline]
+ fn ln_2() -> f64 { 0.693147180559945309417232121458176568 }
+
+ /// ln(10.0)
+ #[inline]
+ fn ln_10() -> f64 { 2.30258509299404568401799145468436421 }
+
/// Returns the exponential of the number
#[inline]
fn exp(self) -> f64 {
unsafe { intrinsics::exp2f64(self) }
}
+ /// Returns the exponential of the number, minus `1`, in a way that is
+ /// accurate even if the number is close to zero
+ #[inline]
+ fn exp_m1(self) -> f64 {
+ unsafe { cmath::expm1(self) }
+ }
+
/// Returns the natural logarithm of the number
#[inline]
fn ln(self) -> f64 {
unsafe { intrinsics::log10f64(self) }
}
+ /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more
+ /// accurately than if the operations were performed separately
+ #[inline]
+ fn ln_1p(self) -> f64 {
+ unsafe { cmath::log1p(self) }
+ }
+
#[inline]
fn sinh(self) -> f64 {
unsafe { cmath::sinh(self) }
// FIXME(#8888): Several of these functions have a parameter named
// `unused_self`. Removing it requires #8888 to be fixed.
pub trait Float: Signed + Primitive {
- /// Returns the maximum of the two numbers.
- fn max(self, other: Self) -> Self;
- /// Returns the minimum of the two numbers.
- fn min(self, other: Self) -> Self;
-
/// Returns the NaN value.
fn nan() -> Self;
-
/// Returns the infinite value.
fn infinity() -> Self;
-
/// Returns the negative infinite value.
fn neg_infinity() -> Self;
-
/// Returns -0.0.
fn neg_zero() -> Self;
/// Returns true if this value is NaN and false otherwise.
fn is_nan(self) -> bool;
-
- /// Returns true if this value is positive infinity or negative infinity and false otherwise.
+ /// Returns true if this value is positive infinity or negative infinity and
+ /// false otherwise.
fn is_infinite(self) -> bool;
-
/// Returns true if this number is neither infinite nor NaN.
fn is_finite(self) -> bool;
-
/// Returns true if this number is neither zero, infinite, denormal, or NaN.
fn is_normal(self) -> bool;
-
/// Returns the category that this number falls into.
fn classify(self) -> FPCategory;
/// Returns the number of binary digits of mantissa that this type supports.
fn mantissa_digits(unused_self: Option<Self>) -> uint;
-
/// Returns the number of binary digits of exponent that this type supports.
fn digits(unused_self: Option<Self>) -> uint;
-
/// Returns the smallest positive number that this type can represent.
fn epsilon() -> Self;
-
/// Returns the minimum binary exponent that this type can represent.
fn min_exp(unused_self: Option<Self>) -> int;
-
/// Returns the maximum binary exponent that this type can represent.
fn max_exp(unused_self: Option<Self>) -> int;
-
/// Returns the minimum base-10 exponent that this type can represent.
fn min_10_exp(unused_self: Option<Self>) -> int;
-
/// Returns the maximum base-10 exponent that this type can represent.
fn max_10_exp(unused_self: Option<Self>) -> int;
- /// Constructs a floating point number created by multiplying `x` by 2 raised to the power of
- /// `exp`.
+ /// Constructs a floating point number created by multiplying `x` by 2
+ /// raised to the power of `exp`.
fn ldexp(x: Self, exp: int) -> Self;
-
- /// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
+ /// Breaks the number into a normalized fraction and a base-2 exponent,
+ /// satisfying:
///
/// * `self = x * pow(2, exp)`
///
/// * `0.5 <= abs(x) < 1.0`
fn frexp(self) -> (Self, int);
-
- /// Returns the exponential of the number, minus 1, in a way that is accurate even if the
- /// number is close to zero.
- fn exp_m1(self) -> Self;
-
- /// Returns the natural logarithm of the number plus 1 (`ln(1+n)`) more accurately than if the
- /// operations were performed separately.
- fn ln_1p(self) -> Self;
-
- /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This produces a
- /// more accurate result with better performance than a separate multiplication operation
- /// followed by an add.
- fn mul_add(self, a: Self, b: Self) -> Self;
-
- /// Returns the next representable floating-point value in the direction of `other`.
- fn next_after(self, other: Self) -> Self;
-
/// Returns the mantissa, exponent and sign as integers, respectively.
fn integer_decode(self) -> (u64, i16, i8);
+ /// Returns the next representable floating-point value in the direction of
+ /// `other`.
+ fn next_after(self, other: Self) -> Self;
+
/// Return the largest integer less than or equal to a number.
fn floor(self) -> Self;
-
/// Return the smallest integer greater than or equal to a number.
fn ceil(self) -> Self;
-
/// Return the nearest integer to a number. Round half-way cases away from
/// `0.0`.
fn round(self) -> Self;
-
/// Return the integer part of a number.
fn trunc(self) -> Self;
-
/// Return the fractional part of a number.
fn fract(self) -> Self;
+ /// Returns the maximum of the two numbers.
+ fn max(self, other: Self) -> Self;
+ /// Returns the minimum of the two numbers.
+ fn min(self, other: Self) -> Self;
+
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
+ /// error. This produces a more accurate result with better performance than
+ /// a separate multiplication operation followed by an add.
+ fn mul_add(self, a: Self, b: Self) -> Self;
+ /// Take the reciprocal (inverse) of a number, `1/x`.
+ fn recip(self) -> Self;
+
+ /// Raise a number to an integer power.
+ ///
+ /// Using this function is generally faster than using `powf`
+ fn powi(self, n: i32) -> Self;
+ /// Raise a number to a floating point power.
+ fn powf(self, n: Self) -> Self;
+
+ /// sqrt(2.0).
+ fn sqrt2() -> Self;
+ /// 1.0 / sqrt(2.0).
+ fn frac_1_sqrt2() -> Self;
+
+ /// Take the square root of a number.
+ fn sqrt(self) -> Self;
+ /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
+ fn rsqrt(self) -> Self;
+ /// Take the cubic root of a number.
+ fn cbrt(self) -> Self;
+ /// Calculate the length of the hypotenuse of a right-angle triangle given
+ /// legs of length `x` and `y`.
+ fn hypot(self, other: Self) -> Self;
+
/// Archimedes' constant.
fn pi() -> Self;
-
/// 2.0 * pi.
fn two_pi() -> Self;
-
/// pi / 2.0.
fn frac_pi_2() -> Self;
-
/// pi / 3.0.
fn frac_pi_3() -> Self;
-
/// pi / 4.0.
fn frac_pi_4() -> Self;
-
/// pi / 6.0.
fn frac_pi_6() -> Self;
-
/// pi / 8.0.
fn frac_pi_8() -> Self;
-
/// 1.0 / pi.
fn frac_1_pi() -> Self;
-
/// 2.0 / pi.
fn frac_2_pi() -> Self;
-
/// 2.0 / sqrt(pi).
fn frac_2_sqrtpi() -> Self;
- /// sqrt(2.0).
- fn sqrt2() -> Self;
-
- /// 1.0 / sqrt(2.0).
- fn frac_1_sqrt2() -> Self;
-
- /// Euler's number.
- fn e() -> Self;
-
- /// log2(e).
- fn log2_e() -> Self;
-
- /// log10(e).
- fn log10_e() -> Self;
-
- /// ln(2.0).
- fn ln_2() -> Self;
-
- /// ln(10.0).
- fn ln_10() -> Self;
-
- /// Take the reciprocal (inverse) of a number, `1/x`.
- fn recip(self) -> Self;
-
- /// Raise a number to a power.
- fn powf(self, n: Self) -> Self;
-
- /// Raise a number to an integer power.
- ///
- /// Using this function is generally faster than using `powf`
- fn powi(self, n: i32) -> Self;
-
- /// Take the square root of a number.
- fn sqrt(self) -> Self;
- /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
- fn rsqrt(self) -> Self;
- /// Take the cubic root of a number.
- fn cbrt(self) -> Self;
- /// Calculate the length of the hypotenuse of a right-angle triangle given
- /// legs of length `x` and `y`.
- fn hypot(self, other: Self) -> Self;
-
/// Computes the sine of a number (in radians).
fn sin(self) -> Self;
/// Computes the cosine of a number (in radians).
/// `(sin(x), cos(x))`.
fn sin_cos(self) -> (Self, Self);
+ /// Euler's number.
+ fn e() -> Self;
+ /// log2(e).
+ fn log2_e() -> Self;
+ /// log10(e).
+ fn log10_e() -> Self;
+ /// ln(2.0).
+ fn ln_2() -> Self;
+ /// ln(10.0).
+ fn ln_10() -> Self;
+
/// Returns `e^(self)`, (the exponential function).
fn exp(self) -> Self;
/// Returns 2 raised to the power of the number, `2^(self)`.
fn exp2(self) -> Self;
+ /// Returns the exponential of the number, minus 1, in a way that is
+ /// accurate even if the number is close to zero.
+ fn exp_m1(self) -> Self;
/// Returns the natural logarithm of the number.
fn ln(self) -> Self;
/// Returns the logarithm of the number with respect to an arbitrary base.
fn log2(self) -> Self;
/// Returns the base 10 logarithm of the number.
fn log10(self) -> Self;
+ /// Returns the natural logarithm of the number plus 1 (`ln(1+n)`) more
+ /// accurately than if the operations were performed separately.
+ fn ln_1p(self) -> Self;
/// Hyperbolic sine function.
fn sinh(self) -> Self;