title: Is there a commonly used rational numbers library in Java?
body: <p>I'm looking for a Java library which represents fractions (rational numbers). For example, if I want to store the fraction <code>1/3</code> then it will not be saved as <code>0.33333</code> which will lose its accuracy.</p>
  
  <p>Here is some of the functionality I expect finding in such a library:</p>
  
  <ul>
  <li><code>getNumerator()</code></li>
  <li><code>getDenominator()</code></li>
  <li><code>add(Rational r1, Rational r2)</code>, <code>subtract(Rational r1, Rational r2)</code>, <code>multiply(Rational r1, Rational r2)</code>, <code>divide(Rational r1, Rational r2)</code></li>
  <li><code>isProper()</code></li>
  <li><code>getCommonDenominator(Collection&lt;Rational&gt; rationals)</code></li>
  <li><code>getSimplified()</code></li>
  </ul>
  
  <p>I can implement such a library by myself, though I was wondering whether something similar  already exists.</p>
  
  <p><strong>EDIT:</strong> It would also be nice if the library implements (in addition to the above) some number theory algorithms, such as <code>getEgyptianFractionsSum()</code> etc.</p>