Skip to content

Commit

Permalink
integration tests for large prec, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
stencillogic committed Feb 22, 2023
1 parent 3c9de8e commit 00d5150
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions astro-float-num/src/ops/cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ impl BigFloatNumber {

// Reduction gives 2^(-p+1) per iteration.
// Restore gives 2^(-p+5) per iteration.
// First parts of the series for any e_eff >= 0 give 2^(-p+6) at most.
// The error of the remaining parts of the series is compensated (see doc/README.md).
// First terms of the series for any e_eff >= 0 give 2^(-p+6) at most.
// The error of the remaining terms of the series is compensated (see doc/README.md).
let add_prec = reduction_times as isize * 6 + 6 - e_eff as isize;
let p_arg = p + if add_prec > 0 { add_prec as usize } else { 0 };
self.set_precision(p_arg, rm)?;
Expand Down
4 changes: 2 additions & 2 deletions astro-float-num/src/ops/sin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ impl BigFloatNumber {

// Reduction gives 2^(-p+3) once.
// Restore gives 2^(-p+6) per iteration.
// First parts of the series for any e_eff >= 0 give 2^(-p+6) at most.
// The error of the remaining parts of the series is compensated (see doc/README.md).
// First terms of the series for any e_eff >= 0 give 2^(-p+6) at most.
// The error of the remaining terms of the series is compensated (see doc/README.md).
let add_prec = reduction_times as isize * 6 + 9 - e_eff as isize;
let p_arg = p + if add_prec > 0 { add_prec as usize } else { 0 };
self.set_precision(p_arg, rm)?;
Expand Down
21 changes: 20 additions & 1 deletion astro-float-num/tests/mpfr/compare_ops_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,29 @@ use rug::{
#[test]
fn mpfr_compare_ops() {
let run_cnt = 1000;

let p_rng = get_prec_rng();
let p_min = 1;

run_compare_ops(run_cnt, p_rng, p_min);

let run_cnt_large = 5;
let p_rng_large = 1;
let p_min_large;

#[cfg(not(debug_assertions))]
{
p_min_large = 1563;
}

#[cfg(debug_assertions)]
{
p_min_large = 156;
}

run_compare_ops(run_cnt_large, p_rng_large, p_min_large);
}

fn run_compare_ops(run_cnt: usize, p_rng: usize, p_min: usize) {
let mut cc = Consts::new().unwrap();

unsafe {
Expand Down
4 changes: 2 additions & 2 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Error `err = nroot(m * 2^e + 2^(e - p)) - nroot(m * 2^e)` <= (does not exceed) *

7. Error for series of sin, cos and sinh.

Error of Maclaurin series M(x) of a function f(x) for x < 1 in which absolute value of the function derivatives near 0 never exceeds 1 need to be estimated only for several first parts of the series.
Error of Maclaurin series M(x) of a function f(x) for x < 1 in which absolute value of the function derivatives near 0 never exceeds 1 need to be estimated only for several first terms of the series.

Proof.

Expand Down Expand Up @@ -78,7 +78,7 @@ follows `2^(n - p) / n! < 2^(n - p) * (e/n)^n = 2^(-p) * (2 * e / n)^n`.
The residual error of the series can be received from Lagrange's error bound,
and it is smaller than `2^(-p) * (2 * e / (n + 1))^(n + 1)`.

For n+1 parts of the series `err < 2^(-p) * sum((2 * e / k)^k), k=1..n+1`.
For n+1 terms of the series `err < 2^(-p) * sum((2 * e / k)^k), k=1..n+1`.

Starting from k = 6 `sum((2 * e / k)^k) < 1` and `err < 2^(-p)`.

Expand Down

0 comments on commit 00d5150

Please sign in to comment.