Modifier and Type | Field and Description |
---|---|
private int |
denominator
Denominator
|
private static float |
EPSILON
Epsilon precision
|
static Rational |
INVALID
Invalid rational.
|
static Rational |
MINUS_ONE
-1 rational
|
private int |
numerator
Numerator
|
static Rational |
ONE
1 rational
|
static Rational |
ZERO
0 rational
|
Modifier | Constructor and Description |
---|---|
private |
Rational(int numerator,
int denominator)
Create a new instance of Rational
|
Modifier and Type | Method and Description |
---|---|
Rational |
addition(Rational rational)
Add an other rational
|
static Rational |
addition(Rational rational1,
Rational rational2)
Add 2 rational
|
int |
compareTo(Rational rational)
Compare with an other rational.
|
static Rational |
createRational(float f)
Create rational from real.
|
static Rational |
createRational(int integer)
Create rational from integer
|
static Rational |
createRational(int numerator,
int denominator)
Create a rational
|
Rational |
divide(Rational rational)
Divide an other rational
|
static Rational |
divide(Rational rational1,
Rational rational2)
Divide 2 rational
|
private static boolean |
equals(float f1,
float f2)
Indicates if 2 reals are equals in epsilon precision
|
boolean |
equals(java.lang.Object obj)
Indicates if an object is equals to this rational
Parent documentation: |
int |
getDenominator()
Denominator
|
int |
getNumerator()
Numerator
|
int |
hashCode()
Compute hash code for rational
Parent documentation: |
Rational |
inverse()
Inverse the rational
|
boolean |
isInteger()
Indicates if rational can be see as integer.
|
boolean |
isNegative()
Indicates if rational is strictly negative
|
boolean |
isPositive()
Indicates if rational is strictly positive
|
static Rational |
middle(Rational rational1,
Rational rational2)
Compute the rational just in the middle of 2 other rational
|
Rational |
multiply(Rational rational)
Multiply an other rational
|
static Rational |
multiply(Rational rational1,
Rational rational2)
Multiply 2 rational
|
Rational |
opposite()
Rational opposite
|
static java.lang.String |
proportion(int numberPositive,
char positiveSymbol,
int numberNegative,
char negativeSymbol)
Compute a string representation of a proportion
|
Rational |
subtract(Rational rational)
Subtract an other rational
|
static Rational |
subtract(Rational rational1,
Rational rational2)
Subtract 2 rational
|
java.lang.String |
toString()
String representation
Parent documentation: |
float |
value()
Real value
|
private static final float EPSILON
public static final Rational INVALID
public static final Rational MINUS_ONE
public static final Rational ONE
public static final Rational ZERO
private final int denominator
private final int numerator
private Rational(int numerator, int denominator)
numerator
- Numeratordenominator
- Denominatorprivate static boolean equals(float f1, float f2)
f1
- First realf2
- Second realtrue
if they are equals at epsilon precisionpublic static Rational addition(Rational rational1, Rational rational2)
rational1
- First rationalrational2
- Second rationalpublic static Rational createRational(float f)
f
- Real to found nearest rationalpublic static Rational createRational(int integer)
integer
- Integer sourcepublic static Rational createRational(int numerator, int denominator)
numerator
- Numeratordenominator
- Denominatorpublic static Rational divide(Rational rational1, Rational rational2)
rational1
- First rationalrational2
- Second rationalpublic static Rational middle(Rational rational1, Rational rational2)
rational1
- First rationalrational2
- Second rationalpublic static Rational multiply(Rational rational1, Rational rational2)
rational1
- First rationalrational2
- Second rationalpublic static java.lang.String proportion(int numberPositive, char positiveSymbol, int numberNegative, char negativeSymbol)
numberPositive
- Number of "positive" valuepositiveSymbol
- Character used to represents "positive" valuesnumberNegative
- Number of "negative" valuenegativeSymbol
- Character used to represents "negative" valuespublic static Rational subtract(Rational rational1, Rational rational2)
rational1
- First rationalrational2
- Second rationalpublic Rational addition(Rational rational)
rational
- Rational to addpublic int compareTo(Rational rational)
< 0 |
If this rational is < the given rational |
---|---|
= 0 |
If this rational is equals the given rational
|
> 0 |
If this rational is > the given rational |
compareTo
in interface java.lang.Comparable<Rational>
rational
- Rational to compare withComparable.compareTo(java.lang.Object)
public Rational divide(Rational rational)
rational
- Rational to dividepublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- Object to testtrue
in equalityObject.equals(java.lang.Object)
public int getDenominator()
public int getNumerator()
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public Rational inverse()
public boolean isInteger()
numerator
true
if the rational is an integerpublic boolean isNegative()
true
if rational is strictly negativepublic boolean isPositive()
true
if ration is strictly positivepublic Rational multiply(Rational rational)
rational
- Rational to multiplypublic Rational opposite()
public Rational subtract(Rational rational)
rational
- Rational to subtractpublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public float value()