|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.princeton.repeatedgames.rgsolve.utilities.Fraction
public class Fraction
A class for converting doubles to rationals, and the reverse. See http://shreevatsa.wordpress.com/2011/01/10/not-all-best- rational-approximations-are-the-convergents-of-the-continued-fraction/
Field Summary | |
---|---|
private long |
denominator
the denominator of this fraction |
static int |
MAX_CONVERGENTS
default Maximum number of convergents in series to calculate |
private long |
numerator
the numerator of this fraction |
static Fraction |
ONE
1/1 |
static double |
TOLERANCE
default approximation tolerance of fraction to inputed double |
static Fraction |
ZERO
0/1 |
Constructor Summary | |
---|---|
Fraction(double value)
Constructs a rational approximation to the double value |
|
Fraction(long numerator,
long denominator)
Constructor. |
Method Summary | |
---|---|
Fraction |
add(Fraction f)
|
static long |
gcd(long A,
long B)
The greatest common divisor of integers A and B |
static Fraction |
getFraction(double x)
Finds rational approximation to reals (doubles) x ,
using default parameters. |
static Fraction |
getFraction(double x,
double tolerance,
int maxConvergents)
Finds rational approximation to reals (doubles) x . |
java.lang.String |
getLatexString()
|
Fraction |
getReciprocal()
Gets the reciprocal. |
double |
getValue()
Returns this fraction as a double value |
Fraction |
multiply(Fraction f)
|
Fraction |
over(Fraction f)
Returns this / f |
static boolean |
setMaxConvergents()
GUI display to change max convergents |
static void |
setMaxConvergents(int max)
|
Fraction |
subtract(Fraction f)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Fraction ONE
public static final Fraction ZERO
public static final double TOLERANCE
public static int MAX_CONVERGENTS
private long numerator
private long denominator
Constructor Detail |
---|
public Fraction(long numerator, long denominator)
denominator
= 0
numerator
- denominator
- public Fraction(double value)
value
value
- Method Detail |
---|
public static boolean setMaxConvergents()
public Fraction add(Fraction f)
public Fraction subtract(Fraction f)
public Fraction multiply(Fraction f)
public Fraction over(Fraction f)
this
/ f
f
-
this/ / f
public Fraction getReciprocal()
this
public double getValue()
public java.lang.String toString()
toString
in class java.lang.Object
public static long gcd(long A, long B)
A
- B
-
public static Fraction getFraction(double x)
x
,
using default parameters.
x
- the real to be approximated
x
public static Fraction getFraction(double x, double tolerance, int maxConvergents)
x
.
x
- the real to be approximatedtolerance
- distance between approximation and x
prompting terminationmaxConvergents
- maximum number of convergents in series to calculate
x
public java.lang.String getLatexString()
public static void setMaxConvergents(int max)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |