diff --git a/Cargo.lock b/Cargo.lock index 50d1089..733b763 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,20 +2,20 @@ name = "piar" version = "0.1.0" dependencies = [ - "byteorder 1.0.0 (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.2 (registry+https://github.com/rust-lang/crates.io-index)", - "pbr 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pbr 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "byteorder" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "getopts" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -29,38 +29,38 @@ dependencies = [ [[package]] name = "lazy_static" -version = "0.2.2" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.20" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" -version = "0.3.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.16" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.36" +version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -75,13 +75,13 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" -"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685" +"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" +"checksum getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "65922871abd2f101a2eb0eaebadc66668e54a87ad9c3dd82520b5f86ede5eff9" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" -"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5" -"checksum pbr 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f37516f7ab051df67430a6572735d7992fe74dde52554495eec459fb57da41f" -"checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753" -"checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade" +"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" +"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" +"checksum pbr 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e048e3afebb6c454bb1c5d0fe73fda54698b4715d78ed8e7302447c37736d23a" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" +"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml index 15c10dd..184af61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ authors = ["logaritmisk "] [dependencies] getopts = "0.2" -byteorder = "1.0" -pbr = "0.3" +byteorder = "1.1" +pbr = "1.0" lazy_static = "0.2" [profile.release] diff --git a/src/bbp.rs b/src/bbp.rs index 62d58a2..1309b96 100644 --- a/src/bbp.rs +++ b/src/bbp.rs @@ -1,7 +1,7 @@ pub fn get_byte(id: i32) -> u8 { let pid: f64 = 4.0 * series(1, id) - 2.0 * series(4, id) - series(5, id) - series(6, id); - let y: f64 = (pid - (pid as i32) as f64 + 1.0).abs(); + let y: f64 = (pid - f64::from(pid as i32) + 1.0).abs(); let y = 16.0 * (y - y.floor()); ((y as u8) << 4) | (16.0 * (y - y.floor())) as u8 @@ -15,23 +15,23 @@ fn series(m: i32, id: i32) -> f64 { let mut s: f64 = 0.0; for k in 0..id { - ak = (8 * k + m) as f64; - t = expm((id - k) as f64, ak); + ak = f64::from(8 * k + m); + t = expm(f64::from(id - k), ak); - s += t / ak; - s -= s.trunc(); + s += t / ak; + s -= s.trunc(); } for k in id..id + 101 { - ak = (8 * k + m) as f64; - t = 16f64.powi(id - k) / ak; + ak = f64::from(8 * k + m); + t = 16f64.powi(id - k) / ak; - if t < EPS { - break; - } + if t < EPS { + break; + } - s += t; - s -= s.trunc(); + s += t; + s -= s.trunc(); } s @@ -67,19 +67,19 @@ fn expm(p: f64, ak: f64) -> f64 { let mut r: f64 = 1.0; for _ in 1..i + 1 { - if p >= pt { - r *= 16.0; - r -= (r / ak).trunc() * ak; + if p >= pt { + r *= 16.0; + r -= (r / ak).trunc() * ak; - p -= pt; - } + p -= pt; + } - pt *= 0.5; + pt *= 0.5; - if pt >= 1.0 { - r *= r; - r -= (r / ak).trunc() * ak; - } + if pt >= 1.0 { + r *= r; + r -= (r / ak).trunc() * ak; + } } r diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/src/main.rs b/src/main.rs index 1a330ed..55ee490 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ -#[macro_use] extern crate lazy_static; -extern crate getopts; + extern crate byteorder; +extern crate getopts; +#[macro_use] +extern crate lazy_static; extern crate pbr; @@ -13,7 +15,7 @@ use std::io::Cursor; use std::collections::BTreeMap; use getopts::Options; -use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian}; +use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use pbr::{ProgressBar, Units}; @@ -22,20 +24,20 @@ mod bbp; struct Pi { next: i32, - map: BTreeMap + map: BTreeMap, } impl Pi { fn new() -> Self { Pi { next: 0, - map: BTreeMap::new() + map: BTreeMap::new(), } } fn find(&mut self, byte: u8) -> i32 { if self.map.contains_key(&byte) { - *self.map.get(&byte).unwrap() + self.map[&byte] } else { for i in self.next..i32::MAX { if byte == bbp::get_byte(i) { @@ -51,7 +53,7 @@ impl Pi { } -fn print_usage(program: &str, opts: Options) { +fn print_usage(program: &str, opts: &Options) { let brief = format!("Usage: {} [option] INPUT OUTPUT", program); print!("{}", opts.usage(&brief)); } @@ -69,13 +71,13 @@ fn main() { let matches = match opts.parse(&args[1..]) { Ok(m) => m, Err(_) => { - print_usage(&program, opts); - std::process::exit(1); + print_usage(&program, &opts); + std::process::exit(1) } }; if matches.opt_present("help") { - print_usage(&program, opts); + print_usage(&program, &opts); std::process::exit(0); } @@ -123,7 +125,7 @@ fn compress(input: &str, output: &str) { let i = pi.find(b); - let mut index : Vec = vec![]; + let mut index: Vec = vec![]; index.write_i32::(i).unwrap();