public class SimpleFraction
extends java.lang.Object
Constructor and Description |
---|
SimpleFraction(int numerator,
int denominator)
Create a fraction given a numerator and denominator.
|
Modifier and Type | Method and Description |
---|---|
static SimpleFraction |
buildFractionExactDenominator(double val,
int exactDenom)
Create a fraction given a double value and a denominator.
|
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.
|
int |
getDenominator()
Access the denominator.
|
int |
getNumerator()
Access the numerator.
|
public SimpleFraction(int numerator, int denominator)
numerator
- denominator
- maxDenominator The maximum allowed value for denominatorpublic static SimpleFraction buildFractionExactDenominator(double val, int exactDenom)
val
- double value of fractionexactDenom
- the exact denominatorpublic static SimpleFraction buildFractionMaxDenominator(double value, int maxDenominator)
value
- the double value to convert to a fraction.maxDenominator
- maximum denominator value allowed.java.lang.RuntimeException
- if the continued fraction failed to
converge.java.lang.IllegalArgumentException
- if value > Integer.MAX_VALUEpublic int getDenominator()
public int getNumerator()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.