Skip to content

Commit

Permalink
use arrays instead of vectors
Browse files Browse the repository at this point in the history
which makes the li2() and li3() functions ~ 7% faster.
  • Loading branch information
Expander committed Sep 27, 2018
1 parent fc1bb68 commit ed8d8a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/li2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Li2<f64> for f64 {
let pi2 = pi*pi;
let pi3 = pi2/3.;
let pi6 = pi2/6.;
let coeffs = vec![0.42996693560813697, 0.40975987533077105,
let coeffs = [0.42996693560813697, 0.40975987533077105,
-0.01858843665014592, 0.00145751084062268,-0.00014304184442340,
0.00001588415541880,-0.00000190784959387, 0.00000024195180854,
-0.00000003193341274, 0.00000000434545063,-0.00000000060578480,
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Li2<Complex<f64>> for Complex<f64> {

// bf[1..N-1] are the even Bernoulli numbers / (2 n + 1)!
// generated by: Table[BernoulliB[2 n]/(2 n + 1)!, {n, 1, 19}]
let bf = vec![
let bf = [
- 1./4.,
1./36.,
- 1./36.0e2,
Expand Down
4 changes: 2 additions & 2 deletions src/li3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Li3<Complex<f64>> for Complex<f64> {
let pi2 = pi*pi;
let eps = std::f64::EPSILON;
let z3 = 1.2020569031595942853997381615114;
let bf = vec![
let bf = [
1., -3./8., 17./216., -5./576.,
0.00012962962962962962962962962962963, 0.000081018518518518518518518518518519,
-3.4193571608537594932152755282007e-06, -1.3286564625850340136054421768707e-06 ,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Li3<Complex<f64>> for Complex<f64> {

let mut p = Complex::new(1.,0.);

for b in bf {
for b in bf.iter() {
p *= u;
sum += b*p;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/li2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn identities() {
let eps = 1e-14;
let zero = Complex::zero();
let omega = Complex::new(0.5, (3.).sqrt()/2.);
let values = vec![
let values = [
Complex::new(0.,0.),
Complex::new(0.5,0.),
Complex::new(1.,0.),
Expand Down

0 comments on commit ed8d8a5

Please sign in to comment.