daily pastebin goal
8%
SHARE
TWEET

[Rust] Implementing Add trait for Rational

cwchen Sep 4th, 2017 302 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. // Implement binary '+' operation
  2. impl Add for Rational {
  3.     type Output = Rational;
  4.  
  5.     fn add(self, other: Rational) -> Rational {
  6.          let p = self.num * other.denom + other.num * self.denom;
  7.          let q = self.denom * other.denom;
  8.          Rational::new(p, q)
  9.      }
  10.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top