Fix formatting in float implementations
This commit is contained in:
parent
bed70a42ec
commit
42450ef022
2 changed files with 198 additions and 72 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
|
use cast;
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use from_str::FromStr;
|
use from_str::FromStr;
|
||||||
use libc::{c_int};
|
use libc::{c_int};
|
||||||
|
@ -213,12 +214,16 @@ impl Neg<f32> for f32 {
|
||||||
impl Signed for f32 {
|
impl Signed for f32 {
|
||||||
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
|
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn abs(&self) -> f32 { unsafe{intrinsics::fabsf32(*self)} }
|
fn abs(&self) -> f32 {
|
||||||
|
unsafe { intrinsics::fabsf32(*self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
|
/// 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.
|
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn abs_sub(&self, other: &f32) -> f32 { unsafe{cmath::fdimf(*self, *other)} }
|
fn abs_sub(&self, other: &f32) -> f32 {
|
||||||
|
unsafe { cmath::fdimf(*self, *other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
|
@ -227,7 +232,9 @@ impl Signed for f32 {
|
||||||
/// - `NAN` if the number is NaN
|
/// - `NAN` if the number is NaN
|
||||||
#[inline]
|
#[inline]
|
||||||
fn signum(&self) -> f32 {
|
fn signum(&self) -> f32 {
|
||||||
if self.is_nan() { NAN } else { unsafe{intrinsics::copysignf32(1.0, *self)} }
|
if self.is_nan() { NAN } else {
|
||||||
|
unsafe { intrinsics::copysignf32(1.0, *self) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
||||||
|
@ -250,7 +257,9 @@ impl Bounded for f32 {
|
||||||
impl Primitive for f32 {}
|
impl Primitive for f32 {}
|
||||||
|
|
||||||
impl Float for f32 {
|
impl Float for f32 {
|
||||||
fn powi(self, n: i32) -> f32 { unsafe{intrinsics::powif32(self, n)} }
|
fn powi(self, n: i32) -> f32 {
|
||||||
|
unsafe { intrinsics::powif32(self, n) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn max(self, other: f32) -> f32 {
|
fn max(self, other: f32) -> f32 {
|
||||||
|
@ -302,7 +311,7 @@ impl Float for f32 {
|
||||||
static EXP_MASK: u32 = 0x7f800000;
|
static EXP_MASK: u32 = 0x7f800000;
|
||||||
static MAN_MASK: u32 = 0x007fffff;
|
static MAN_MASK: u32 = 0x007fffff;
|
||||||
|
|
||||||
let bits: u32 = unsafe {::cast::transmute(self)};
|
let bits: u32 = unsafe { cast::transmute(self) };
|
||||||
match (bits & MAN_MASK, bits & EXP_MASK) {
|
match (bits & MAN_MASK, bits & EXP_MASK) {
|
||||||
(0, 0) => FPZero,
|
(0, 0) => FPZero,
|
||||||
(_, 0) => FPSubnormal,
|
(_, 0) => FPSubnormal,
|
||||||
|
@ -335,7 +344,9 @@ impl Float for f32 {
|
||||||
|
|
||||||
/// 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]
|
#[inline]
|
||||||
fn ldexp(x: f32, exp: int) -> f32 { unsafe{cmath::ldexpf(x, exp as c_int)} }
|
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:
|
||||||
///
|
///
|
||||||
|
@ -353,28 +364,34 @@ impl Float for f32 {
|
||||||
/// Returns the exponential of the number, minus `1`, in a way that is accurate
|
/// Returns the exponential of the number, minus `1`, in a way that is accurate
|
||||||
/// even if the number is close to zero
|
/// even if the number is close to zero
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp_m1(self) -> f32 { unsafe{cmath::expm1f(self)} }
|
fn exp_m1(self) -> f32 {
|
||||||
|
unsafe { cmath::expm1f(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
|
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
|
||||||
/// than if the operations were performed separately
|
/// than if the operations were performed separately
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ln_1p(self) -> f32 { unsafe{cmath::log1pf(self)} }
|
fn ln_1p(self) -> f32 {
|
||||||
|
unsafe { cmath::log1pf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
|
/// 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
|
/// produces a more accurate result with better performance than a separate multiplication
|
||||||
/// operation followed by an add.
|
/// operation followed by an add.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul_add(self, a: f32, b: f32) -> f32 { unsafe{intrinsics::fmaf32(self, a, b)} }
|
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`
|
/// Returns the next representable floating-point value in the direction of `other`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_after(self, other: f32) -> f32 { unsafe{cmath::nextafterf(self, other)} }
|
fn next_after(self, other: f32) -> f32 {
|
||||||
|
unsafe { cmath::nextafterf(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the mantissa, exponent and sign as integers.
|
/// Returns the mantissa, exponent and sign as integers.
|
||||||
fn integer_decode(self) -> (u64, i16, i8) {
|
fn integer_decode(self) -> (u64, i16, i8) {
|
||||||
let bits: u32 = unsafe {
|
let bits: u32 = unsafe { cast::transmute(self) };
|
||||||
::cast::transmute(self)
|
|
||||||
};
|
|
||||||
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
|
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
|
||||||
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
|
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
|
||||||
let mantissa = if exponent == 0 {
|
let mantissa = if exponent == 0 {
|
||||||
|
@ -389,19 +406,27 @@ impl Float for f32 {
|
||||||
|
|
||||||
/// Round half-way cases toward `NEG_INFINITY`
|
/// Round half-way cases toward `NEG_INFINITY`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn floor(self) -> f32 { unsafe{intrinsics::floorf32(self)} }
|
fn floor(self) -> f32 {
|
||||||
|
unsafe { intrinsics::floorf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Round half-way cases toward `INFINITY`
|
/// Round half-way cases toward `INFINITY`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ceil(self) -> f32 { unsafe{intrinsics::ceilf32(self)} }
|
fn ceil(self) -> f32 {
|
||||||
|
unsafe { intrinsics::ceilf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Round half-way cases away from `0.0`
|
/// Round half-way cases away from `0.0`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn round(self) -> f32 { unsafe{intrinsics::roundf32(self)} }
|
fn round(self) -> f32 {
|
||||||
|
unsafe { intrinsics::roundf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The integer part of the number (rounds towards `0.0`)
|
/// The integer part of the number (rounds towards `0.0`)
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trunc(self) -> f32 { unsafe{intrinsics::truncf32(self)} }
|
fn trunc(self) -> f32 {
|
||||||
|
unsafe { intrinsics::truncf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The fractional part of the number, satisfying:
|
/// The fractional part of the number, satisfying:
|
||||||
///
|
///
|
||||||
|
@ -485,40 +510,62 @@ impl Float for f32 {
|
||||||
fn recip(self) -> f32 { 1.0 / self }
|
fn recip(self) -> f32 { 1.0 / self }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn powf(self, n: f32) -> f32 { unsafe{intrinsics::powf32(self, n)} }
|
fn powf(self, n: f32) -> f32 {
|
||||||
|
unsafe { intrinsics::powf32(self, n) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sqrt(self) -> f32 { unsafe{intrinsics::sqrtf32(self)} }
|
fn sqrt(self) -> f32 {
|
||||||
|
unsafe { intrinsics::sqrtf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rsqrt(self) -> f32 { self.sqrt().recip() }
|
fn rsqrt(self) -> f32 { self.sqrt().recip() }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cbrt(self) -> f32 { unsafe{cmath::cbrtf(self)} }
|
fn cbrt(self) -> f32 {
|
||||||
|
unsafe { cmath::cbrtf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hypot(self, other: f32) -> f32 { unsafe{cmath::hypotf(self, other)} }
|
fn hypot(self, other: f32) -> f32 {
|
||||||
|
unsafe { cmath::hypotf(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sin(self) -> f32 { unsafe{intrinsics::sinf32(self)} }
|
fn sin(self) -> f32 {
|
||||||
|
unsafe { intrinsics::sinf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cos(self) -> f32 { unsafe{intrinsics::cosf32(self)} }
|
fn cos(self) -> f32 {
|
||||||
|
unsafe { intrinsics::cosf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tan(self) -> f32 { unsafe{cmath::tanf(self)} }
|
fn tan(self) -> f32 {
|
||||||
|
unsafe { cmath::tanf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn asin(self) -> f32 { unsafe{cmath::asinf(self)} }
|
fn asin(self) -> f32 {
|
||||||
|
unsafe { cmath::asinf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn acos(self) -> f32 { unsafe{cmath::acosf(self)} }
|
fn acos(self) -> f32 {
|
||||||
|
unsafe { cmath::acosf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn atan(self) -> f32 { unsafe{cmath::atanf(self)} }
|
fn atan(self) -> f32 {
|
||||||
|
unsafe { cmath::atanf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn atan2(self, other: f32) -> f32 { unsafe{cmath::atan2f(self, other)} }
|
fn atan2(self, other: f32) -> f32 {
|
||||||
|
unsafe { cmath::atan2f(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Simultaneously computes the sine and cosine of the number
|
/// Simultaneously computes the sine and cosine of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -528,15 +575,21 @@ impl Float for f32 {
|
||||||
|
|
||||||
/// Returns the exponential of the number
|
/// Returns the exponential of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp(self) -> f32 { unsafe{intrinsics::expf32(self)} }
|
fn exp(self) -> f32 {
|
||||||
|
unsafe { intrinsics::expf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns 2 raised to the power of the number
|
/// Returns 2 raised to the power of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp2(self) -> f32 { unsafe{intrinsics::exp2f32(self)} }
|
fn exp2(self) -> f32 {
|
||||||
|
unsafe { intrinsics::exp2f32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the natural logarithm of the number
|
/// Returns the natural logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ln(self) -> f32 { unsafe{intrinsics::logf32(self)} }
|
fn ln(self) -> f32 {
|
||||||
|
unsafe { intrinsics::logf32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the logarithm of the number with respect to an arbitrary base
|
/// Returns the logarithm of the number with respect to an arbitrary base
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -544,20 +597,30 @@ impl Float for f32 {
|
||||||
|
|
||||||
/// Returns the base 2 logarithm of the number
|
/// Returns the base 2 logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn log2(self) -> f32 { unsafe{intrinsics::log2f32(self)} }
|
fn log2(self) -> f32 {
|
||||||
|
unsafe { intrinsics::log2f32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the base 10 logarithm of the number
|
/// Returns the base 10 logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn log10(self) -> f32 { unsafe{intrinsics::log10f32(self)} }
|
fn log10(self) -> f32 {
|
||||||
|
unsafe { intrinsics::log10f32(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sinh(self) -> f32 { unsafe{cmath::sinhf(self)} }
|
fn sinh(self) -> f32 {
|
||||||
|
unsafe { cmath::sinhf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cosh(self) -> f32 { unsafe{cmath::coshf(self)} }
|
fn cosh(self) -> f32 {
|
||||||
|
unsafe { cmath::coshf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tanh(self) -> f32 { unsafe{cmath::tanhf(self)} }
|
fn tanh(self) -> f32 {
|
||||||
|
unsafe { cmath::tanhf(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Inverse hyperbolic sine
|
/// Inverse hyperbolic sine
|
||||||
///
|
///
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
|
use cast;
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use from_str::FromStr;
|
use from_str::FromStr;
|
||||||
use libc::{c_int};
|
use libc::{c_int};
|
||||||
|
@ -221,12 +222,16 @@ impl Neg<f64> for f64 {
|
||||||
impl Signed for f64 {
|
impl Signed for f64 {
|
||||||
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
|
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn abs(&self) -> f64 { unsafe{intrinsics::fabsf64(*self)} }
|
fn abs(&self) -> f64 {
|
||||||
|
unsafe { intrinsics::fabsf64(*self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
|
/// 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.
|
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn abs_sub(&self, other: &f64) -> f64 { unsafe{cmath::fdim(*self, *other)} }
|
fn abs_sub(&self, other: &f64) -> f64 {
|
||||||
|
unsafe { cmath::fdim(*self, *other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
|
@ -235,7 +240,9 @@ impl Signed for f64 {
|
||||||
/// - `NAN` if the number is NaN
|
/// - `NAN` if the number is NaN
|
||||||
#[inline]
|
#[inline]
|
||||||
fn signum(&self) -> f64 {
|
fn signum(&self) -> f64 {
|
||||||
if self.is_nan() { NAN } else { unsafe{intrinsics::copysignf64(1.0, *self)} }
|
if self.is_nan() { NAN } else {
|
||||||
|
unsafe { intrinsics::copysignf64(1.0, *self) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
||||||
|
@ -308,7 +315,7 @@ impl Float for f64 {
|
||||||
static EXP_MASK: u64 = 0x7ff0000000000000;
|
static EXP_MASK: u64 = 0x7ff0000000000000;
|
||||||
static MAN_MASK: u64 = 0x000fffffffffffff;
|
static MAN_MASK: u64 = 0x000fffffffffffff;
|
||||||
|
|
||||||
let bits: u64 = unsafe {::cast::transmute(self)};
|
let bits: u64 = unsafe { cast::transmute(self) };
|
||||||
match (bits & MAN_MASK, bits & EXP_MASK) {
|
match (bits & MAN_MASK, bits & EXP_MASK) {
|
||||||
(0, 0) => FPZero,
|
(0, 0) => FPZero,
|
||||||
(_, 0) => FPSubnormal,
|
(_, 0) => FPSubnormal,
|
||||||
|
@ -341,7 +348,9 @@ impl Float for f64 {
|
||||||
|
|
||||||
/// 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]
|
#[inline]
|
||||||
fn ldexp(x: f64, exp: int) -> f64 { unsafe{cmath::ldexp(x, exp as c_int)} }
|
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:
|
||||||
///
|
///
|
||||||
|
@ -359,28 +368,34 @@ impl Float for f64 {
|
||||||
/// Returns the exponential of the number, minus `1`, in a way that is accurate
|
/// Returns the exponential of the number, minus `1`, in a way that is accurate
|
||||||
/// even if the number is close to zero
|
/// even if the number is close to zero
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp_m1(self) -> f64 { unsafe{cmath::expm1(self)} }
|
fn exp_m1(self) -> f64 {
|
||||||
|
unsafe { cmath::expm1(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
|
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
|
||||||
/// than if the operations were performed separately
|
/// than if the operations were performed separately
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ln_1p(self) -> f64 { unsafe{cmath::log1p(self)} }
|
fn ln_1p(self) -> f64 {
|
||||||
|
unsafe { cmath::log1p(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
|
/// 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
|
/// produces a more accurate result with better performance than a separate multiplication
|
||||||
/// operation followed by an add.
|
/// operation followed by an add.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul_add(self, a: f64, b: f64) -> f64 { unsafe{intrinsics::fmaf64(self, a, b)} }
|
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`
|
/// Returns the next representable floating-point value in the direction of `other`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_after(self, other: f64) -> f64 { unsafe{cmath::nextafter(self, other)} }
|
fn next_after(self, other: f64) -> f64 {
|
||||||
|
unsafe { cmath::nextafter(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the mantissa, exponent and sign as integers.
|
/// Returns the mantissa, exponent and sign as integers.
|
||||||
fn integer_decode(self) -> (u64, i16, i8) {
|
fn integer_decode(self) -> (u64, i16, i8) {
|
||||||
let bits: u64 = unsafe {
|
let bits: u64 = unsafe { cast::transmute(self) };
|
||||||
::cast::transmute(self)
|
|
||||||
};
|
|
||||||
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
|
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
|
||||||
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
|
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
|
||||||
let mantissa = if exponent == 0 {
|
let mantissa = if exponent == 0 {
|
||||||
|
@ -395,19 +410,27 @@ impl Float for f64 {
|
||||||
|
|
||||||
/// Round half-way cases toward `NEG_INFINITY`
|
/// Round half-way cases toward `NEG_INFINITY`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn floor(self) -> f64 { unsafe{intrinsics::floorf64(self)} }
|
fn floor(self) -> f64 {
|
||||||
|
unsafe { intrinsics::floorf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Round half-way cases toward `INFINITY`
|
/// Round half-way cases toward `INFINITY`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ceil(self) -> f64 { unsafe{intrinsics::ceilf64(self)} }
|
fn ceil(self) -> f64 {
|
||||||
|
unsafe { intrinsics::ceilf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Round half-way cases away from `0.0`
|
/// Round half-way cases away from `0.0`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn round(self) -> f64 { unsafe{intrinsics::roundf64(self)} }
|
fn round(self) -> f64 {
|
||||||
|
unsafe { intrinsics::roundf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The integer part of the number (rounds towards `0.0`)
|
/// The integer part of the number (rounds towards `0.0`)
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trunc(self) -> f64 { unsafe{intrinsics::truncf64(self)} }
|
fn trunc(self) -> f64 {
|
||||||
|
unsafe { intrinsics::truncf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// The fractional part of the number, satisfying:
|
/// The fractional part of the number, satisfying:
|
||||||
///
|
///
|
||||||
|
@ -491,43 +514,67 @@ impl Float for f64 {
|
||||||
fn recip(self) -> f64 { 1.0 / self }
|
fn recip(self) -> f64 { 1.0 / self }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn powf(self, n: f64) -> f64 { unsafe{intrinsics::powf64(self, n)} }
|
fn powf(self, n: f64) -> f64 {
|
||||||
|
unsafe { intrinsics::powf64(self, n) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn powi(self, n: i32) -> f64 { unsafe{intrinsics::powif64(self, n)} }
|
fn powi(self, n: i32) -> f64 {
|
||||||
|
unsafe { intrinsics::powif64(self, n) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sqrt(self) -> f64 { unsafe{intrinsics::sqrtf64(self)} }
|
fn sqrt(self) -> f64 {
|
||||||
|
unsafe { intrinsics::sqrtf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rsqrt(self) -> f64 { self.sqrt().recip() }
|
fn rsqrt(self) -> f64 { self.sqrt().recip() }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cbrt(self) -> f64 { unsafe{cmath::cbrt(self)} }
|
fn cbrt(self) -> f64 {
|
||||||
|
unsafe { cmath::cbrt(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hypot(self, other: f64) -> f64 { unsafe{cmath::hypot(self, other)} }
|
fn hypot(self, other: f64) -> f64 {
|
||||||
|
unsafe { cmath::hypot(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sin(self) -> f64 { unsafe{intrinsics::sinf64(self)} }
|
fn sin(self) -> f64 {
|
||||||
|
unsafe { intrinsics::sinf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cos(self) -> f64 { unsafe{intrinsics::cosf64(self)} }
|
fn cos(self) -> f64 {
|
||||||
|
unsafe { intrinsics::cosf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tan(self) -> f64 { unsafe{cmath::tan(self)} }
|
fn tan(self) -> f64 {
|
||||||
|
unsafe { cmath::tan(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn asin(self) -> f64 { unsafe{cmath::asin(self)} }
|
fn asin(self) -> f64 {
|
||||||
|
unsafe { cmath::asin(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn acos(self) -> f64 { unsafe{cmath::acos(self)} }
|
fn acos(self) -> f64 {
|
||||||
|
unsafe { cmath::acos(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn atan(self) -> f64 { unsafe{cmath::atan(self)} }
|
fn atan(self) -> f64 {
|
||||||
|
unsafe { cmath::atan(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn atan2(self, other: f64) -> f64 { unsafe{cmath::atan2(self, other)} }
|
fn atan2(self, other: f64) -> f64 {
|
||||||
|
unsafe { cmath::atan2(self, other) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Simultaneously computes the sine and cosine of the number
|
/// Simultaneously computes the sine and cosine of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -537,15 +584,21 @@ impl Float for f64 {
|
||||||
|
|
||||||
/// Returns the exponential of the number
|
/// Returns the exponential of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp(self) -> f64 { unsafe{intrinsics::expf64(self)} }
|
fn exp(self) -> f64 {
|
||||||
|
unsafe { intrinsics::expf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns 2 raised to the power of the number
|
/// Returns 2 raised to the power of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn exp2(self) -> f64 { unsafe{intrinsics::exp2f64(self)} }
|
fn exp2(self) -> f64 {
|
||||||
|
unsafe { intrinsics::exp2f64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the natural logarithm of the number
|
/// Returns the natural logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ln(self) -> f64 { unsafe{intrinsics::logf64(self)} }
|
fn ln(self) -> f64 {
|
||||||
|
unsafe { intrinsics::logf64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the logarithm of the number with respect to an arbitrary base
|
/// Returns the logarithm of the number with respect to an arbitrary base
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -553,20 +606,30 @@ impl Float for f64 {
|
||||||
|
|
||||||
/// Returns the base 2 logarithm of the number
|
/// Returns the base 2 logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn log2(self) -> f64 { unsafe{intrinsics::log2f64(self)} }
|
fn log2(self) -> f64 {
|
||||||
|
unsafe { intrinsics::log2f64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the base 10 logarithm of the number
|
/// Returns the base 10 logarithm of the number
|
||||||
#[inline]
|
#[inline]
|
||||||
fn log10(self) -> f64 { unsafe{intrinsics::log10f64(self)} }
|
fn log10(self) -> f64 {
|
||||||
|
unsafe { intrinsics::log10f64(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sinh(self) -> f64 { unsafe{cmath::sinh(self)} }
|
fn sinh(self) -> f64 {
|
||||||
|
unsafe { cmath::sinh(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cosh(self) -> f64 { unsafe{cmath::cosh(self)} }
|
fn cosh(self) -> f64 {
|
||||||
|
unsafe { cmath::cosh(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tanh(self) -> f64 { unsafe{cmath::tanh(self)} }
|
fn tanh(self) -> f64 {
|
||||||
|
unsafe { cmath::tanh(self) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Inverse hyperbolic sine
|
/// Inverse hyperbolic sine
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue