Correct fns exp2 that were calling exp

Fixes #22080.
This commit is contained in:
Carol Nichols 2015-02-07 20:02:24 -05:00
parent 725cc06464
commit 8379062be5
2 changed files with 56 additions and 2 deletions

View File

@ -173,7 +173,7 @@ impl Float for f32 {
#[inline]
fn exp(self) -> f32 { num::Float::exp(self) }
#[inline]
fn exp2(self) -> f32 { num::Float::exp(self) }
fn exp2(self) -> f32 { num::Float::exp2(self) }
#[inline]
fn ln(self) -> f32 { num::Float::ln(self) }
#[inline]
@ -554,6 +554,33 @@ mod tests {
assert_approx_eq!((-1.7f32).fract(), -0.7f32);
}
#[test]
fn test_exp() {
assert_eq!(1.0, 0.0f32.exp());
assert_approx_eq!(2.718282, 1.0f32.exp());
assert_approx_eq!(148.413162, 5.0f32.exp());
let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::nan();
assert_eq!(inf, inf.exp());
assert_eq!(0.0, neg_inf.exp());
assert!(nan.exp().is_nan());
}
#[test]
fn test_exp2() {
assert_eq!(32.0, 5.0f32.exp2());
assert_eq!(1.0, 0.0f32.exp2());
let inf: f32 = Float::infinity();
let neg_inf: f32 = Float::neg_infinity();
let nan: f32 = Float::nan();
assert_eq!(inf, inf.exp2());
assert_eq!(0.0, neg_inf.exp2());
assert!(nan.exp2().is_nan());
}
#[test]
fn test_asinh() {
assert_eq!(0.0f32.asinh(), 0.0f32);

View File

@ -183,7 +183,7 @@ impl Float for f64 {
#[inline]
fn exp(self) -> f64 { num::Float::exp(self) }
#[inline]
fn exp2(self) -> f64 { num::Float::exp(self) }
fn exp2(self) -> f64 { num::Float::exp2(self) }
#[inline]
fn ln(self) -> f64 { num::Float::ln(self) }
#[inline]
@ -563,6 +563,33 @@ mod tests {
assert_approx_eq!((-1.7f64).fract(), -0.7f64);
}
#[test]
fn test_exp() {
assert_eq!(1.0, 0.0f64.exp());
assert_approx_eq!(2.718282, 1.0f64.exp());
assert_approx_eq!(148.413159, 5.0f64.exp());
let inf: f64 = Float::infinity();
let neg_inf: f64 = Float::neg_infinity();
let nan: f64 = Float::nan();
assert_eq!(inf, inf.exp());
assert_eq!(0.0, neg_inf.exp());
assert!(nan.exp().is_nan());
}
#[test]
fn test_exp2() {
assert_eq!(32.0, 5.0f64.exp2());
assert_eq!(1.0, 0.0f64.exp2());
let inf: f64 = Float::infinity();
let neg_inf: f64 = Float::neg_infinity();
let nan: f64 = Float::nan();
assert_eq!(inf, inf.exp2());
assert_eq!(0.0, neg_inf.exp2());
assert!(nan.exp2().is_nan());
}
#[test]
fn test_asinh() {
assert_eq!(0.0f64.asinh(), 0.0f64);