Skip to content

Commit

Permalink
Update 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
3442853561 committed Jun 21, 2017
1 parent b697022 commit 4042308
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: rust
rust:
- stable
- beta
- nightly
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "granny"
version = "0.0.1"
license = "MIT"
authors = ["3442853561<3442853561@qq.com>"]
keywords = ["computing", "scientific computing"]

description = "Granny is the crate for scientific computing with Rust"
repository = "https://github.com/RustDream/Granny"

[lib]
name = "granny"
path = "./src/lib.rs"

[[bin]]
name = "main"
path = "./src/examples/main.rs"
7 changes: 7 additions & 0 deletions src/examples/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate granny;

use granny::Euclidean;

fn main() {
println!("{}", 10u8.gcd(8));
}
1 change: 1 addition & 0 deletions src/float.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod float;
pub mod math;
pub use math::Euclidean;
32 changes: 32 additions & 0 deletions src/math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::ops::{Div, Rem};

pub trait Euclidean<T>
where T: Div + Rem
{
/// Calculate the maximum common divisor
fn gcd(self, p: T) -> T;
}

impl Euclidean<u8> for u8 {
fn gcd(self, p: u8) -> u8 {
if self % p != 0 { p.gcd(self % p) } else { p }
}
}

impl Euclidean<u16> for u16 {
fn gcd(self, p: u16) -> u16 {
if self % p != 0 { p.gcd(self % p) } else { p }
}
}

impl Euclidean<u32> for u32 {
fn gcd(self, p: u32) -> u32 {
if self % p != 0 { p.gcd(self % p) } else { p }
}
}

impl Euclidean<u64> for u64 {
fn gcd(self, p: u64) -> u64 {
if self % p != 0 { p.gcd(self % p) } else { p }
}
}

0 comments on commit 4042308

Please sign in to comment.