Fix a couple of todos.

This commit is contained in:
2016-06-07 19:26:43 +02:00
parent a18a709a76
commit d290f977d1
2 changed files with 35 additions and 24 deletions

View File

@@ -1,17 +1,10 @@
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 mut y : f64 = (pid - (pid as i32) as f64 + 1.0).abs(); // TODO use .trunc() instead
let y : f64 = (pid - (pid as i32) as f64 + 1.0).abs(); // TODO use .trunc() instead
let y = 16.0 * (y - y.floor());
y = 16.0 * (y - y.floor()); // TODO use .trunc() instead of floor?
let first : u8 = y as u8;
y = 16.0 * (y - y.floor()); // TODO use .trunc() instead of floor?
let second : u8 = y as u8;
(first << 4) | second
((y as u8) << 4) | (16.0 * (y - y.floor())) as u8
}
fn series(m: i32, id: i32) -> f64 {
@@ -26,7 +19,7 @@ fn series(m: i32, id: i32) -> f64 {
t = expm((id - k) as f64, ak);
s += t / ak;
s -= (s as i32) as f64; // TODO: use .truc() instead.
s -= s.trunc();
}
for k in id..id + 101 {
@@ -38,7 +31,7 @@ fn series(m: i32, id: i32) -> f64 {
}
s += t;
s -= (s as i32) as f64; // TODO: use .truc() instead.
s -= s.trunc();
}
s
@@ -70,22 +63,22 @@ fn expm(p: f64, ak: f64) -> f64 {
}
let mut pt = TP[i - 1];
let mut p1 : f64 = p; // TODO: use p instead of p1?
let mut p = p;
let mut r : f64 = 1.0;
for _ in 1..i + 1 {
if p1 >= pt {
if p >= pt {
r = 16.0 * r;
r = r - ((r / ak) as i32) as f64 * ak; // TODO: use .truc() instead.
r = r - (r / ak).trunc() * ak;
p1 -= pt;
p -= pt;
}
pt = 0.5 * pt;
if pt >= 1.0 {
r *= r;
r -= ((r / ak) as i32) as f64 * ak; // TODO: use .truc() instead.
r -= (r / ak).trunc() * ak;
}
}

View File

@@ -18,6 +18,11 @@ use pbr::{ProgressBar, Units};
mod bbp;
fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
}
fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
@@ -29,14 +34,28 @@ fn main() {
opts.optflag("h", "help", "display this help and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(f) => { panic!(f.to_string()) }
Ok(m) => m,
Err(_) => {
print_usage(&program, opts);
std::process::exit(1);
}
};
if matches.opt_present("help") {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
return;
print_usage(&program, opts);
std::process::exit(0);
}
if matches.free.len() == 1 {
println!("Missing operand: OUTPUT");
println!("Try `{} --help` for more information.", program);
std::process::exit(1);
}
if matches.free.len() == 0 {
println!("Missing operand: INPUT OUTPUT");
println!("Try `{} --help` for more information.", program);
std::process::exit(1);
}
if matches.opt_present("c") {
@@ -44,8 +63,7 @@ fn main() {
let output = &matches.free[1];
compress(&input, &output);
}
else if matches.opt_present("d") {
} else if matches.opt_present("d") {
let input = &matches.free[0];
let output = &matches.free[1];