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
FieldsModifier and TypeFieldDescriptionstatic final GenMonoid<BigInteger,Rational> evidentstatic final GenMonoid<BigInteger,Rational> evidentstatic final Rationalevidentstatic final Rationalevidentprotected static final Map<Integer,BigInteger> Cache for powers of ten.static final Rationalevidentstatic final Rationalevident -
Method Summary
Modifier and TypeMethodDescriptionabs()Return the absolute (positive) valueReturn the normalized addition result.Return rounded value.byteReturn rounded value.intReturn the comparison result of this and x, from {-1,0,+1}.divide(long factor) Return the normalized division result.Return the normalized division result.doubleReturns division result.booleanevidentfloatReturns division result.final BigIntegerevidentfinal BigIntegerevidentinthashCode()evidentintintValue()Return rounded value.int[]Returns enumerator and denominator.inverse()Return the normalized inverse result.final booleanevidentfinal booleanisOne()evidentfinal booleanisZero()evidentlongReturn 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.shortReturn rounded value.intsignum()Return the signum information -1,0,+1Return the normalized subtraction result.protected static BigIntegertenPower(int exp) Calculates 10^exp.toString()evidentstatic final RationalvalueOf(long n) evidentstatic final RationalvalueOf(long n, long d) evidentstatic final RationalParser.static final Rationalevidentstatic final Rationalevident.static final RationalvalueOf(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:
shortValuein 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:
floatValuein classNumber
-
doubleValue
public double doubleValue()Returns division result. For the conversion of the internal BigIntegers seeBigInteger.doubleValue().- Specified by:
doubleValuein 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:
compareToin interfaceComparable<Rational>
-
hashCode
public int hashCode()evident -
toString
evident
-