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
Rationalclass.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtendedRational.NumberType
-
Field Summary
Fields Modifier and Type Field Description static ExtendedRationalINFTYstatic ExtendedRationalNaNstatic ExtendedRationalNEG_INFTYstatic ExtendedRationalZERO
-
Constructor Summary
Constructors Constructor Description ExtendedRational(Rational pRational)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ExtendedRational b)ExtendedRationaldivides(ExtendedRational b)booleanequals(@Nullable Object y)RationalgetRational()If the represented number is rational, return the wrapped object.inthashCode()booleanisRational()ExtendedRationalminus(ExtendedRational b)ExtendedRationalnegate()static ExtendedRationalofString(String s)Reverses the effect oftoString().ExtendedRationalplus(ExtendedRational b)ExtendedRationalreciprocal()ExtendedRationaltimes(ExtendedRational b)doubletoDouble()Returns rational converted to double.StringtoString()Returns one of TWO things.
-
-
-
Field Detail
-
INFTY
public static final ExtendedRational INFTY
-
NEG_INFTY
public static final ExtendedRational NEG_INFTY
-
ZERO
public static final ExtendedRational ZERO
-
NaN
public static final ExtendedRational NaN
-
-
Constructor Detail
-
ExtendedRational
public ExtendedRational(Rational pRational)
-
-
Method Detail
-
isRational
public boolean isRational()
-
getRational
public Rational 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
public String 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
public static ExtendedRational ofString(String s)
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
public int compareTo(ExtendedRational b)
- Specified by:
compareToin interfaceComparable<ExtendedRational>
-
times
public ExtendedRational times(ExtendedRational b)
-
plus
public ExtendedRational plus(ExtendedRational b)
-
minus
public ExtendedRational minus(ExtendedRational b)
-
divides
public ExtendedRational divides(ExtendedRational b)
-
reciprocal
public ExtendedRational reciprocal()
-
negate
public ExtendedRational negate()
-
-