diff --git a/Cargo.lock b/Cargo.lock index 29b05de..55e3fbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,6 +4,7 @@ version = "0.1.0" dependencies = [ "byteorder 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pbr 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -26,6 +27,11 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lazy_static" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.11" diff --git a/Cargo.toml b/Cargo.toml index d1813ed..2276de3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ authors = ["logaritmisk "] getopts = "0.2" byteorder = "0.5" pbr = "0.2.1" +lazy_static = "0.2.1" diff --git a/src/.#main.rs b/src/.#main.rs new file mode 120000 index 0000000..e3a0987 --- /dev/null +++ b/src/.#main.rs @@ -0,0 +1 @@ +olsson@ralph.local.68703 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 513f672..f86dcf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ extern crate getopts; extern crate byteorder; extern crate pbr; +#[macro_use] +extern crate lazy_static; use std::env; use std::fs; @@ -158,14 +160,21 @@ fn series(m: i32, id: i32) -> f64 { fn expm(p: f64, ak: f64) -> f64 { const NTP : usize = 25; - let mut tp = vec![1f64; NTP]; let mut i : i32 = 0; let mut p1 : f64 = p; let mut pt : f64; let mut r : f64 = 1.0; - for n in 1..NTP { - tp[n] = 2.0 * tp[n - 1]; + lazy_static! { + static ref TP : Vec = { + let mut v = vec![1f64; NTP]; + + for i in 1..NTP { + v[i] = 2.0 * v[i - 1]; + } + + v + }; } if ak == 1.0 { @@ -173,13 +182,13 @@ fn expm(p: f64, ak: f64) -> f64 { } for n in 0..NTP { - if tp[n] > p { + if TP[n] > p { i = n as i32; break; } } - pt = tp[(i - 1) as usize]; + pt = TP[(i - 1) as usize]; for _ in 1..i + 1 { if p1 >= pt {