Skip to content

Commit 77719cd

Browse files
Fix exp function to actually work
It was calling into decNumberExp with the wrong signature, so it didn't work at all. I also fixed the decNumber tests for exp so that they'll actually ru if point at the exp.decTest file, and I added a super basic test for ln and exp. 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?
1 parent 5577a60 commit 77719cd

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

decTest/exp.decTest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ expx1200 exp 1 -> 2.718281828459045235360287471352662 Inexact Rounded
540540
Precision: 34
541541
maxExponent: 6144
542542
minExponent: -6143
543+
clamp: 1
543544
expx1201 exp 309.5948855821510212996700645087188 -> 2.853319692901387521201738015050724E+134 Inexact Rounded
544545
expx1202 exp 9.936543068706211420422803962680164 -> 20672.15839203171877476511093276022 Inexact Rounded
545546
expx1203 exp 6.307870323881505684429839491707908 -> 548.8747777054637296137277391754665 Inexact Rounded

src/bin/run-test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ fn run_test<'a>(env: &Environment, test: Test<'a>) -> TestResult<'a> {
494494
&test);
495495
}
496496
Op::Divide(a, b) => simple_op!(test, value = div(a, b)),
497+
Op::Exp(a) => simple_op!(test, value = exp(a)),
497498
Op::Fma(a, b, c) => simple_op!(test, value = mul_add(a, b, c)),
498499
Op::Invert(a) => simple_op!(test, value = not(a)),
499500
Op::LogB(a) => simple_op!(test, value = logb(a)),

src/dec128.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,11 @@ impl d128 {
617617
/// respectively). Inexact results will almost always be correctly rounded, but may be up to 1
618618
/// ulp (unit in last place) in error in rare cases. This is a mathematical function; the
619619
/// 10<sup>6</sup> restrictions on precision and range apply as described above.
620-
pub fn exp<O: AsRef<d128>>(mut self, exp: O) -> d128 {
620+
pub fn exp(mut self) -> d128 {
621621
d128::with_context(|ctx| unsafe {
622622
let mut num_self: decNumber = uninitialized();
623-
let mut num_exp: decNumber = uninitialized();
624623
decimal128ToNumber(&self, &mut num_self);
625-
decimal128ToNumber(exp.as_ref(), &mut num_exp);
626-
decNumberExp(&mut num_self, &num_self, &num_exp, ctx);
624+
decNumberExp(&mut num_self, &num_self, ctx);
627625
*decimal128FromNumber(&mut self, &num_self, ctx)
628626
})
629627
}
@@ -948,7 +946,6 @@ extern "C" {
948946
ctx: *mut Context)
949947
-> *mut decNumber;
950948
fn decNumberExp(res: *mut decNumber,
951-
lhs: *const decNumber,
952949
rhs: *const decNumber,
953950
ctx: *mut Context)
954951
-> *mut decNumber;
@@ -1093,4 +1090,9 @@ mod tests {
10931090
assert_eq!(d128::from_str(&(::std::u64::MIN).to_string()).unwrap(),
10941091
d128::from(::std::u64::MIN));
10951092
}
1093+
1094+
#[test]
1095+
fn math_op() {
1096+
assert_eq!(d128!(1), d128!(1).ln().exp());
1097+
}
10961098
}

0 commit comments

Comments
 (0)