Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl Rational {
- pub fn new(p: i32, q: i32) -> Rational {
- if q == 0 {
- panic!("Denominator should not be zero.");
- }
- let d = Rational::gcd(p, q).abs();
- Rational{ num: p / d, denom: q / d }
- }
- }
- impl Rational {
- fn gcd(a: i32, b: i32) -> i32 {
- if b == 0 {
- a
- } else {
- Rational::gcd(b, a % b)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement