# Fraction

'LGPLv3 License' Build Status

Examples

Simple arithmetic

```rust use fraction::Fraction;

fn main () { let mut fr = Fraction::zero ();

fr = fr + Fraction::from (2); // 0 + 2 = 2 fr = fr / Fraction::from (0.5); // 2 / 0.5 = 4

assert_eq! (fr, Fraction::from (4)); } ```

Using as keys for a HashMap

```rust use std::collections::HashMap; use fraction::Fraction;

fn main () { let f = Fraction::from (0.75);

let mut map: HashMap

map.insert (f, ());

assert! (map.containskey (&Fraction::new (3, 4))); // 0.75 == 3/4 assert! (map.containskey (&Fraction::new (6, 8))); // 0.75 == 6/8 assert! (map.containskey (&Fraction::new (12, 16))); // 0.75 == 12/16 assert! (! map.containskey (&Fraction::from (0.5))); // 0.75 != 1/2 } ```

Comparison

```rust use fraction::Fraction;

fn main () { let f14 = Fraction::new (1, 4); // 1/4 == 0.25 let f12 = Fraction::new (1, 2); // 1/2 == 0.50 let f24 = Fraction::new (2, 4); // 2/4 == 0.50 let f34 = Fraction::new (3, 4); // 3/4 == 0.75

asserteq! (f12, f24); // 1/2 == 2/4 asserteq! (f34, f12 + f14); // 3/4 == 1/2 + 1/4 assert_eq! (f14, Fraction::from (0.25)); // 1/4 == 0.25 } ```