pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32;
}
-#[inline(always)]
-pub fn logarithm(n: f32, b: f32) -> f32 {
- return log2(n) / log2(b);
-}
-
impl Num for f32 {}
#[cfg(notest)]
#[inline(always)]
fn expm1(&self) -> f32 { expm1(*self) }
+ /// Returns the natural logarithm of the number
#[inline(always)]
- fn log(&self) -> f32 { ln(*self) }
+ fn ln(&self) -> f32 { ln(*self) }
+ /// Returns the logarithm of the number with respect to an arbitrary base
+ #[inline(always)]
+ fn log(&self, base: f32) -> f32 { self.ln() / base.ln() }
+
+ /// Returns the base 2 logarithm of the number
#[inline(always)]
fn log2(&self) -> f32 { log2(*self) }
+ /// Returns the base 10 logarithm of the number
#[inline(always)]
fn log10(&self) -> f32 { log10(*self) }
}
#[inline(always)]
fn log10_e() -> f32 { 0.434294481903251827651128918916605082 }
- /// log(2.0)
+ /// ln(2.0)
#[inline(always)]
- fn log_2() -> f32 { 0.693147180559945309417232121458176568 }
+ fn ln_2() -> f32 { 0.693147180559945309417232121458176568 }
- /// log(10.0)
+ /// ln(10.0)
#[inline(always)]
- fn log_10() -> f32 { 2.30258509299404568401799145468436421 }
+ fn ln_10() -> f32 { 2.30258509299404568401799145468436421 }
/// Converts to degrees, assuming the number is in radians
#[inline(always)]
assert_approx_eq!(Real::frac_1_sqrt2::<f32>(), 1f32 / 2f32.sqrt());
assert_approx_eq!(Real::log2_e::<f32>(), Real::e::<f32>().log2());
assert_approx_eq!(Real::log10_e::<f32>(), Real::e::<f32>().log10());
- assert_approx_eq!(Real::log_2::<f32>(), 2f32.log());
- assert_approx_eq!(Real::log_10::<f32>(), 10f32.log());
+ assert_approx_eq!(Real::ln_2::<f32>(), 2f32.ln());
+ assert_approx_eq!(Real::ln_10::<f32>(), 10f32.ln());
}
#[test]
pub static ln_10: f64 = 2.30258509299404568401799145468436421_f64;
}
-#[inline(always)]
-pub fn logarithm(n: f64, b: f64) -> f64 {
- return log2(n) / log2(b);
-}
-
impl Num for f64 {}
#[cfg(notest)]
#[inline(always)]
fn expm1(&self) -> f64 { expm1(*self) }
+ /// Returns the natural logarithm of the number
#[inline(always)]
- fn log(&self) -> f64 { ln(*self) }
+ fn ln(&self) -> f64 { ln(*self) }
+ /// Returns the logarithm of the number with respect to an arbitrary base
+ #[inline(always)]
+ fn log(&self, base: f64) -> f64 { self.ln() / base.ln() }
+
+ /// Returns the base 2 logarithm of the number
#[inline(always)]
fn log2(&self) -> f64 { log2(*self) }
+ /// Returns the base 10 logarithm of the number
#[inline(always)]
fn log10(&self) -> f64 { log10(*self) }
}
#[inline(always)]
fn log10_e() -> f64 { 0.434294481903251827651128918916605082 }
- /// log(2.0)
+ /// ln(2.0)
#[inline(always)]
- fn log_2() -> f64 { 0.693147180559945309417232121458176568 }
+ fn ln_2() -> f64 { 0.693147180559945309417232121458176568 }
- /// log(10.0)
+ /// ln(10.0)
#[inline(always)]
- fn log_10() -> f64 { 2.30258509299404568401799145468436421 }
+ fn ln_10() -> f64 { 2.30258509299404568401799145468436421 }
/// Converts to degrees, assuming the number is in radians
#[inline(always)]
assert_approx_eq!(Real::frac_1_sqrt2::<f64>(), 1f64 / 2f64.sqrt());
assert_approx_eq!(Real::log2_e::<f64>(), Real::e::<f64>().log2());
assert_approx_eq!(Real::log10_e::<f64>(), Real::e::<f64>().log10());
- assert_approx_eq!(Real::log_2::<f64>(), 2f64.log());
- assert_approx_eq!(Real::log_10::<f64>(), 10f64.log());
+ assert_approx_eq!(Real::ln_2::<f64>(), 2f64.ln());
+ assert_approx_eq!(Real::ln_10::<f64>(), 10f64.ln());
}
#[test]
use prelude::*;
pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
-pub use f64::logarithm;
pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor};
pub use f64::{erf, erfc, exp, expm1, exp2, abs_sub};
pub use f64::{mul_add, fmax, fmin, next_after, frexp, hypot, ldexp};
(*self as f64).expm1() as float
}
+ /// Returns the natural logarithm of the number
#[inline(always)]
- fn log(&self) -> float {
- (*self as f64).log() as float
+ fn ln(&self) -> float {
+ (*self as f64).ln() as float
}
+ /// Returns the logarithm of the number with respect to an arbitrary base
+ #[inline(always)]
+ fn log(&self, base: float) -> float {
+ (*self as f64).log(base as f64) as float
+ }
+
+ /// Returns the base 2 logarithm of the number
#[inline(always)]
fn log2(&self) -> float {
(*self as f64).log2() as float
}
+ /// Returns the base 10 logarithm of the number
#[inline(always)]
fn log10(&self) -> float {
(*self as f64).log10() as float
#[inline(always)]
fn log10_e() -> float { 0.434294481903251827651128918916605082 }
- /// log(2.0)
+ /// ln(2.0)
#[inline(always)]
- fn log_2() -> float { 0.693147180559945309417232121458176568 }
+ fn ln_2() -> float { 0.693147180559945309417232121458176568 }
- /// log(10.0)
+ /// ln(10.0)
#[inline(always)]
- fn log_10() -> float { 2.30258509299404568401799145468436421 }
+ fn ln_10() -> float { 2.30258509299404568401799145468436421 }
/// Converts to degrees, assuming the number is in radians
#[inline(always)]
assert_approx_eq!(Real::frac_1_sqrt2::<float>(), 1f / 2f.sqrt());
assert_approx_eq!(Real::log2_e::<float>(), Real::e::<float>().log2());
assert_approx_eq!(Real::log10_e::<float>(), Real::e::<float>().log10());
- assert_approx_eq!(Real::log_2::<float>(), 2f.log());
- assert_approx_eq!(Real::log_10::<float>(), 10f.log());
+ assert_approx_eq!(Real::ln_2::<float>(), 2f.ln());
+ assert_approx_eq!(Real::ln_10::<float>(), 10f.ln());
}
#[test]
fn exp(&self) -> Self;
fn exp2(&self) -> Self;
fn expm1(&self) -> Self;
- fn log(&self) -> Self;
+ fn ln(&self) -> Self;
+ fn log(&self, base: Self) -> Self;
fn log2(&self) -> Self;
fn log10(&self) -> Self;
}
fn e() -> Self;
fn log2_e() -> Self;
fn log10_e() -> Self;
- fn log_2() -> Self;
- fn log_10() -> Self;
+ fn ln_2() -> Self;
+ fn ln_10() -> Self;
// Angular conversions
fn to_degrees(&self) -> Self;