Class SimpleFraction


  • public class SimpleFraction
    extends Object
    • Constructor Detail

      • SimpleFraction

        public SimpleFraction​(int numerator,
                              int denominator)
        Create a fraction given a numerator and denominator.
        Parameters:
        numerator - the numerator
        denominator - maxDenominator The maximum allowed value for denominator
    • Method Detail

      • buildFractionExactDenominator

        public static SimpleFraction buildFractionExactDenominator​(double val,
                                                                   int exactDenom)
        Create a fraction given a double value and a denominator.
        Parameters:
        val - double value of fraction
        exactDenom - the exact denominator
        Returns:
        a SimpleFraction with the given values set.
      • buildFractionMaxDenominator

        public static SimpleFraction buildFractionMaxDenominator​(double value,
                                                                 int maxDenominator)
        Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.
        Parameters:
        value - the double value to convert to a fraction.
        maxDenominator - maximum denominator value allowed.
        Throws:
        IllegalStateException - if the continued fraction failed to converge.
        IllegalArgumentException - if value > Integer.MAX_VALUE
      • getDenominator

        public int getDenominator()
        Access the denominator.
        Returns:
        the denominator.
      • getNumerator

        public int getNumerator()
        Access the numerator.
        Returns:
        the numerator.