Skip to content

Commit

Permalink
Fix exp function to actually work
Browse files Browse the repository at this point in the history
It was calling into decNumberExp with the wrong signature, so it didn't work at all.

Also, I fixed the tests for exp so that they'll actually run.

It seems a bit too easy to not run some tests by accident right now; maybe it would be good to expect every test file to have some non-igored tests, and then just delete the test files for actually unimplemented functionality?
  • Loading branch information
djrodgerspryor committed Dec 24, 2017
1 parent 5577a60 commit aa10eb8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions decTest/exp.decTest
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ expx1200 exp 1 -> 2.718281828459045235360287471352662 Inexact Rounded
Precision: 34
maxExponent: 6144
minExponent: -6143
clamp: 1
expx1201 exp 309.5948855821510212996700645087188 -> 2.853319692901387521201738015050724E+134 Inexact Rounded
expx1202 exp 9.936543068706211420422803962680164 -> 20672.15839203171877476511093276022 Inexact Rounded
expx1203 exp 6.307870323881505684429839491707908 -> 548.8747777054637296137277391754665 Inexact Rounded
Expand Down
1 change: 1 addition & 0 deletions src/bin/run-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ fn run_test<'a>(env: &Environment, test: Test<'a>) -> TestResult<'a> {
&test);
}
Op::Divide(a, b) => simple_op!(test, value = div(a, b)),
Op::Exp(a) => simple_op!(test, value = exp(a)),
Op::Fma(a, b, c) => simple_op!(test, value = mul_add(a, b, c)),
Op::Invert(a) => simple_op!(test, value = not(a)),
Op::LogB(a) => simple_op!(test, value = logb(a)),
Expand Down
12 changes: 7 additions & 5 deletions src/dec128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,11 @@ impl d128 {
/// respectively). Inexact results will almost always be correctly rounded, but may be up to 1
/// ulp (unit in last place) in error in rare cases. This is a mathematical function; the
/// 10<sup>6</sup> restrictions on precision and range apply as described above.
pub fn exp<O: AsRef<d128>>(mut self, exp: O) -> d128 {
pub fn exp(mut self) -> d128 {
d128::with_context(|ctx| unsafe {
let mut num_self: decNumber = uninitialized();
let mut num_exp: decNumber = uninitialized();
decimal128ToNumber(&self, &mut num_self);
decimal128ToNumber(exp.as_ref(), &mut num_exp);
decNumberExp(&mut num_self, &num_self, &num_exp, ctx);
decNumberExp(&mut num_self, &num_self, ctx);
*decimal128FromNumber(&mut self, &num_self, ctx)
})
}
Expand Down Expand Up @@ -948,7 +946,6 @@ extern "C" {
ctx: *mut Context)
-> *mut decNumber;
fn decNumberExp(res: *mut decNumber,
lhs: *const decNumber,
rhs: *const decNumber,
ctx: *mut Context)
-> *mut decNumber;
Expand Down Expand Up @@ -1093,4 +1090,9 @@ mod tests {
assert_eq!(d128::from_str(&(::std::u64::MIN).to_string()).unwrap(),
d128::from(::std::u64::MIN));
}

#[test]
fn math_op() {
assert_eq!(d128!(1), d128!(1).ln().exp());
}
}

0 comments on commit aa10eb8

Please sign in to comment.