Package eu.bandm.tools.util
Class Rational
java.lang.Object
java.lang.Number
eu.bandm.tools.util.Rational
- All Implemented Interfaces:
Serializable
,Comparable<Rational>
Realizing Rational numbers, internally based on
BigInteger
.
All results of arithmetic operations are normalized immediately.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final GenMonoid<BigInteger,
Rational> evidentstatic final GenMonoid<BigInteger,
Rational> evidentstatic final Rational
evidentstatic final Rational
evidentprotected static final Map<Integer,
BigInteger> Cache for powers of ten.static final Rational
evidentstatic final Rational
evident -
Method Summary
Modifier and TypeMethodDescriptionabs()
Return the absolute (positive) valueReturn the normalized addition result.Return rounded value.byte
Return rounded value.int
Return the comparison result of this and x, from {-1,0,+1}.divide
(long factor) Return the normalized division result.Return the normalized division result.double
Returns division result.boolean
evidentfloat
Returns division result.final BigInteger
evidentfinal BigInteger
evidentint
hashCode()
evidentint
intValue()
Return rounded value.int[]
Returns enumerator and denominator.inverse()
Return the normalized inverse result.final boolean
evidentfinal boolean
isOne()
evidentfinal boolean
isZero()
evidentlong
Return rounded value.Return the larger of this and x.Return the smaller of this and x.FIXME ???multiply
(long factor) Return the normalized multiplication result.Return the normalized multiplication result.negate()
Return the normalized negation.power
(int n) Return the normalized power of this to the exponent n.short
Return rounded value.int
signum()
Return the signum information -1,0,+1Return the normalized subtraction result.protected static BigInteger
tenPower
(int exp) Calculates 10^exp.toString()
evidentstatic final Rational
valueOf
(long n) evidentstatic final Rational
valueOf
(long n, long d) evidentstatic final Rational
Parser.static final Rational
evidentstatic final Rational
evident.static final Rational
valueOf
(BigInteger n, BigInteger d) evident
-
Field Details
-
ZERO
evident -
ONE
evident -
TWO
evident -
ONE_HALF
evident -
powerOfTen
Cache for powers of ten. -
addition
evident -
multiplication
evident
-
-
Method Details
-
valueOf
evident -
getNumerator
evident -
getDenominator
evident -
isInteger
public final boolean isInteger()evident -
isZero
public final boolean isZero()evident -
isOne
public final boolean isOne()evident -
valueOf
Parser. The string must be either a plain integer, according toInteger.parseInt(String)
. Or it contains exactly one "/" sign, separating both such strings. The string after the "/" must not have a sign symbol. . @throws NumberFormatException- Throws:
NumberFormatException
-
valueOf
evident. -
tenPower
Calculates 10^exp. Uses the local cache. -
valueOf
evident -
valueOf
evident -
valueOf
evident -
bigIntegerValue
Return rounded value. Implies rounding towards zero, according to Java default rules. Relies onBigInteger.divide(BigInteger)
. See Java specification. -
byteValue
public byte byteValue()Return rounded value. -
shortValue
public short shortValue()Return rounded value.- Overrides:
shortValue
in classNumber
- See Also:
-
intValue
public int intValue()Return rounded value. -
intValues
public int[] intValues()Returns enumerator and denominator. For the conversion of the interal BigIntegers seeBigInteger.intValue()
. -
longValue
public long longValue()Return rounded value. -
floatValue
public float floatValue()Returns division result. For the conversion of the internal BigIntegers seeBigInteger.floatValue()
.- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()Returns division result. For the conversion of the internal BigIntegers seeBigInteger.doubleValue()
.- Specified by:
doubleValue
in classNumber
-
add
Return the normalized addition result. -
subtract
Return the normalized subtraction result. -
negate
Return the normalized negation. -
multiply
Return the normalized multiplication result. -
multiply
Return the normalized multiplication result. -
divide
Return the normalized division result. -
divide
Return the normalized division result. -
inverse
Return the normalized inverse result. -
power
Return the normalized power of this to the exponent n. -
modulo
FIXME ??? -
signum
public int signum()Return the signum information -1,0,+1 -
abs
Return the absolute (positive) value -
min
Return the smaller of this and x. -
max
Return the larger of this and x. -
equals
evident -
compareTo
Return the comparison result of this and x, from {-1,0,+1}.- Specified by:
compareTo
in interfaceComparable<Rational>
-
hashCode
public int hashCode()evident -
toString
evident
-