Package eu.bandm.tools.ops
Class Rational
java.lang.Object
java.lang.Number
eu.bandm.tools.ops.Rational
- All Implemented Interfaces:
Serializable
,Comparable<Rational>
Realizing Rational numbers, internally based on
BigInteger
.
All instances returned by this code are always cancelled and normalized. (Internal intermediate data not necessarily.)
- 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.additiveName
(@Opt String separator) Shows integer part and fractional rest separately.Return rounded value.byte
Return rounded value.int
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.Returns the fractional rest of the division by x, with "this/x" defined as with integer division, namely rounding towards zero, not towards negative infinity.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
Returns the fractional rest of the division by x, with "this/x" defined as with integer division, namely rounding towards zero, not towards negative infinity. This method behaves like java integer {code %}, cf https://docs.oracle.com/javase/specs/jls/se22/html/jls-15.html#jls-15.17.3.5%3 produces 2 (note that 5/3 produces 1) 5%(-3) produces 2 (note that 5/(-3) produces -1) (-5)%3 produces -2 (note that (-5)/3 produces -1) (-5)%(-3) produces -2 (note that (-5)/(-3) produces 1) *
-
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
- Specified by:
compareTo
in interfaceComparable<Rational>
-
hashCode
public int hashCode()evident -
toString
evident -
additiveName
Shows integer part and fractional rest separately. If integer part == 0, then the simpletoString()
is returned. Otheriwse, if value < 0, then the represenationof the negation is inclosed in-(..)
.- Parameters:
separator
- string set betweeninteger and fractional part, defaults to " "
-