Class SimpleFraction
java.lang.Object
org.xlsx4j.org.apache.poi.ss.format.SimpleFraction
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe denominator.private final intThe numerator. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleFraction(int numerator, int denominator) Create a fraction given a numerator and denominator. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimpleFractionbuildFractionExactDenominator(double val, int exactDenom) Create a fraction given a double value and a denominator.private static SimpleFractionbuildFractionMaxDenominator(double value, double epsilon, int maxDenominator, int maxIterations) Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.static SimpleFractionbuildFractionMaxDenominator(double value, int maxDenominator) Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.intAccess the denominator.intAccess the numerator.
-
Field Details
-
denominator
private final int denominatorThe denominator. -
numerator
private final int numeratorThe numerator.
-
-
Constructor Details
-
SimpleFraction
public SimpleFraction(int numerator, int denominator) Create a fraction given a numerator and denominator.- Parameters:
numerator-denominator- maxDenominator The maximum allowed value for denominator
-
-
Method Details
-
buildFractionExactDenominator
Create a fraction given a double value and a denominator.- Parameters:
val- double value of fractionexactDenom- the exact denominator- Returns:
- a SimpleFraction with the given values set.
-
buildFractionMaxDenominator
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:
RuntimeException- if the continued fraction failed to converge.IllegalArgumentException- if value > Integer.MAX_VALUE
-
buildFractionMaxDenominator
private static SimpleFraction buildFractionMaxDenominator(double value, double epsilon, int maxDenominator, int maxIterations) Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits.References:
- Continued Fraction equations (11) and (22)-(26)
- Parameters:
value- the double value to convert to a fraction.epsilon- maximum error allowed. The resulting fraction is withinepsilonofvalue, in absolute terms.maxDenominator- maximum denominator value allowed.maxIterations- maximum number of convergents- Throws:
RuntimeException- 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.
-