public class MyFractionAlgebra extends Object implements JxnCloneableAlgebra
BigFraction
.Constructor and Description |
---|
MyFractionAlgebra(double x)
Finds a fraction that represents
x , using the continued fraction algorithm. |
MyFractionAlgebra(int numerator)
Equivalent to
new MyFractionAlgebra( numerator, 1 ) . |
MyFractionAlgebra(int numerator,
int denominator)
Constructs a new Fraction object.
|
Modifier and Type | Method and Description |
---|---|
MyFractionAlgebra |
add(MyFractionAlgebra opnd)
Adds
opnd to this. |
JxnCloneableAlgebra |
cloneThis()
Note:
MyFractionAlgebra implements JxnCloneableAlgebra only for demonstration. |
double |
doubleValue()
Returns this fraction as double.
|
boolean |
equals(Object other)
Fractions are equal, if both numerator and denominator are equal.
|
static int |
gcd(int m,
int n)
Returns the greatest common divisor (gcd) of
m and n . |
int |
getDenominator()
Returns the internally stored denominator.
|
int |
getNumerator()
Returns the internally stored numerator.
|
MyFractionAlgebra |
inv()
Replaces this by its reciprocal.
|
MyFractionAlgebra |
mul(MyFractionAlgebra opnd)
(Post)Multiplies this by
opnd . |
MyFractionAlgebra |
pow(int exponent)
Replaces this by its power of
exponent . |
protected int |
power(int base,
int exponent)
power.
|
protected void |
reduce()
Reduces the fraction: devides numerator and denominator by their greatest common divisor.
|
String |
toString()
Returns a string representation of the fraction.
|
public MyFractionAlgebra(int numerator, int denominator)
public MyFractionAlgebra(int numerator)
new MyFractionAlgebra( numerator, 1 )
. public MyFractionAlgebra(double x)
x
, using the continued fraction algorithm. public int getNumerator()
public int getDenominator()
public double doubleValue()
public JxnCloneableAlgebra cloneThis()
MyFractionAlgebra
implements JxnCloneableAlgebra
only for demonstration.
As MyFractionAlgebra
has only 2 int members numerator
and denominator
it
should better be implemented as immutable like java.math.
BigInteger
or CommonsMath
/ BigFraction
.JxnCloneableAlgebra
opndLeft
in
opndLeft op opndRght
, if op
is implemented as
opndLeft.op(opndRght)
and the instance method op
modifies the instance.cloneThis
in interface JxnCloneableAlgebra
public MyFractionAlgebra add(MyFractionAlgebra opnd)
opnd
to this.public MyFractionAlgebra mul(MyFractionAlgebra opnd)
opnd
.public MyFractionAlgebra inv()
public MyFractionAlgebra pow(int exponent)
exponent
.public boolean equals(Object other)
public static int gcd(int m, int n)
m
and n
.protected void reduce()
protected int power(int base, int exponent)
exponent
- must be >= 0© 2013-18 K.-M. Graf Fachbereich EIT Hochschule Darmstadt JXN