Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? This test should not change at all.

Copy link
Copy Markdown
Contributor Author

@djrodgerspryor djrodgerspryor Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of these lines in the run-test script:

    let d128_env = Environment {
        precision: Some(34),
        rounding: Some(Rounding::HalfEven),
        max_exponent: Some(6144),
        min_exponent: Some(-6143),
        extended: true,
        clamp: true,
    };

    if *env != d128_env {
        return TestResult::Ignored(test);
    }

Without that change, the tests were silently skipped (and none of the other matched either).

Maybe I should have gone in the other direction and defined a different Environment just for these tests? I assume that the check is there to make sure that it only runs applicable tests, but since the exp tests pass with the different clamping mode, I assume that all of those test cases are still valid with the different clamping mode.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to change run_test() to run ops with the specified environment which will make this change unnecessary and increase test coverage?

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());
}
}