Package org.sosy_lab.common.rationals
Class ExtendedRational
java.lang.Object
org.sosy_lab.common.rationals.ExtendedRational
- All Implemented Interfaces:
Comparable<ExtendedRational>
@Immutable
public final class ExtendedRational
extends Object
implements Comparable<ExtendedRational>
This class represents "extended rational": rationals which allow for infinities, negative
infinities and undefined numbers.
Any operation on the numbers is guaranteed to never yield an exception.
Represented as wrapper around Rational class.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ExtendedRationalstatic final ExtendedRationalstatic final ExtendedRationalstatic final ExtendedRational -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanIf the represented number is rational, return the wrapped object.inthashCode()booleannegate()static ExtendedRationalReverses the effect oftoString().doubletoDouble()Returns rational converted to double.toString()Returns one of TWO things.
-
Field Details
-
INFTY
-
NEG_INFTY
-
ZERO
-
NaN
-
-
Constructor Details
-
ExtendedRational
-
-
Method Details
-
isRational
public boolean isRational() -
getRational
If the represented number is rational, return the wrapped object.- Throws:
UnsupportedOperationException- in case the value is not rational
-
toDouble
public double toDouble()Returns rational converted to double.The method works, because the Java Double class also supports Infinity/-Infinity/NaN.
-
toString
Returns one of TWO things. a) String of the form num/den if the number is rational. b) String representation of infinity/etc, consistent with theDoubleclass. -
ofString
Reverses the effect oftoString(). Supports 4 different formats, to be consistent with theDoubleclass:"Infinity""-Infinity""NaN"a/bfor some integersaandbafor some integera
- Parameters:
s- Input string,- Returns:
- New
ExtendedRational. - Throws:
NumberFormatException-sis not a valid representation of ExtendedRational.
-
compareTo
- Specified by:
compareToin interfaceComparable<ExtendedRational>
-
equals
-
hashCode
public int hashCode() -
times
-
plus
-
minus
-
divides
-
reciprocal
-
negate
-