Update crate.

Clippy.
Fmt.
This commit is contained in:
2017-09-14 09:49:29 +02:00
parent 2e7d5b0214
commit c27239c01b
5 changed files with 60 additions and 57 deletions

View File

@@ -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

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@

View File

@@ -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<u8, i32>
map: BTreeMap<u8, i32>,
}
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<u8> = vec![];
let mut index: Vec<u8> = vec![];
index.write_i32::<LittleEndian>(i).unwrap();