Class ERational

  • All Implemented Interfaces:
    java.lang.Comparable<ERational>

    public final class ERational
    extends java.lang.Object
    implements java.lang.Comparable<ERational>
    Represents an arbitrary-precision rational number. This class can't be inherited. (The "E" stands for "extended", meaning that instances of this class can be values other than numbers proper, such as infinity and not-a-number.)

    Thread safety: Instances of this class are immutable, so they are inherently safe for use by multiple threads. Multiple instances of this object with the same properties are interchangeable, so they should not be compared using the "==" operator (which might only check if each side of the operator is the same instance).

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      ERational Abs()
      Returns the absolute value of this rational number, that is, a number with the same value as this one but as a nonnegative number.
      ERational Add​(ERational otherValue)
      Adds two rational numbers.
      int compareTo​(ERational other)
      Compares an arbitrary-precision rational number with this instance.
      int CompareToBinary​(EFloat other)
      Compares an arbitrary-precision binary float with this instance.
      int CompareToDecimal​(EDecimal other)
      Compares an arbitrary-precision decimal number with this instance.
      int CompareToTotal​(ERational other)
      Compares the values of this object and another object, imposing a total ordering on all possible values.
      int CompareToTotalMagnitude​(ERational other)
      Compares the absolute values of this object and another object, imposing a total ordering on all possible values (ignoring their signs).
      ERational Copy()
      Creates a copy of this arbitrary-precision rational number.
      ERational CopySign​(ERational other)
      Returns a number with the same value as this one, but copying the sign (positive or negative) of another number.
      static ERational Create​(int numeratorSmall, int denominatorSmall)
      Creates a rational number with the given numerator and denominator.
      static ERational Create​(EInteger numerator, EInteger denominator)
      Creates a rational number with the given numerator and denominator.
      static ERational CreateNaN​(EInteger diag)
      Creates a not-a-number arbitrary-precision rational number.
      static ERational CreateNaN​(EInteger diag, boolean signaling, boolean negative)
      Creates a not-a-number arbitrary-precision rational number.
      ERational Divide​(ERational otherValue)
      Divides this instance by the value of an arbitrary-precision rational number object.
      boolean equals​(ERational other)
      Determines whether this object's numerator, denominator, and properties are equal to those of another object.
      boolean equals​(java.lang.Object obj)
      Determines whether this object's numerator, denominator, and properties are equal to those of another object and that other object is an arbitrary-precision rational number.
      static ERational FromBoolean​(boolean boolValue)
      Converts a boolean value (true or false) to an arbitrary-precision rational number.
      static ERational FromByte​(byte inputByte)
      Converts a byte (from 0 to 255) to an arbitrary-precision rational number.
      static ERational FromDouble​(double flt)
      Converts a 64-bit floating-point number to a rational number.
      static ERational FromEDecimal​(EDecimal ef)
      Converts an arbitrary-precision decimal number to a rational number.
      static ERational FromEFloat​(EFloat ef)
      Converts an arbitrary-precision binary float to a rational number.
      static ERational FromEInteger​(EInteger bigint)
      Converts an arbitrary-precision integer to a rational number.
      static ERational FromExtendedDecimal​(EDecimal ef)
      Deprecated.
      Renamed to FromEDecimal.
      static ERational FromExtendedFloat​(EFloat ef)
      Deprecated.
      Renamed to FromEFloat.
      static ERational FromInt16​(short inputInt16)
      Converts a 16-bit signed integer to an arbitrary-precision rational number.
      static ERational FromInt32​(int inputInt32)
      Converts a 32-bit signed integer to an arbitrary-precision rational number.
      static ERational FromInt64​(long inputInt64)
      Converts a 64-bit signed integer to an arbitrary-precision rational number.
      static ERational FromSingle​(float flt)
      Converts a 32-bit binary floating-point number to a rational number.
      static ERational FromString​(java.lang.String str)
      Creates a rational number from a text string that represents a number.
      static ERational FromString​(java.lang.String str, int offset, int length)
      Creates a rational number from a text string that represents a number.
      EInteger getDenominator()
      Gets this object's denominator.
      EInteger getNumerator()
      Gets this object's numerator.
      EInteger getUnsignedNumerator()
      Gets this object's numerator with the sign removed.
      int hashCode()
      Returns the hash code for this instance.
      boolean isFinite()
      Gets a value indicating whether this object is finite (not infinity or NaN).
      boolean IsInfinity()
      Gets a value indicating whether this object's value is infinity.
      boolean IsNaN()
      Returns whether this object is a not-a-number value.
      boolean isNegative()
      Gets a value indicating whether this object's value is negative (including negative zero).
      boolean IsNegativeInfinity()
      Returns whether this object is negative infinity.
      boolean IsPositiveInfinity()
      Returns whether this object is positive infinity.
      boolean IsQuietNaN()
      Returns whether this object is a quiet not-a-number value.
      boolean IsSignalingNaN()
      Returns whether this object is a signaling not-a-number value (which causes an error if the value is passed to any arithmetic operation in this class).
      boolean isZero()
      Gets a value indicating whether this object's value equals 0.
      ERational Multiply​(ERational otherValue)
      Multiplies this instance by the value of an arbitrary-precision rational number.
      ERational Negate()
      Returns a rational number with the same value as this one but with the sign reversed.
      ERational Remainder​(ERational otherValue)
      Finds the remainder that results when this instance is divided by the value of an arbitrary-precision rational number.
      int signum()
      Gets the sign of this rational number.
      ERational Subtract​(ERational otherValue)
      Subtracts an arbitrary-precision rational number from this instance.
      byte ToByteChecked()
      Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) after truncating to an integer.
      byte ToByteIfExact()
      Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) without rounding to a different numerical value.
      byte ToByteUnchecked()
      Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a byte (from 0 to 255).
      double ToDouble()
      Converts this value to a 64-bit floating-point number.
      EDecimal ToEDecimal()
      Converts this rational number to an arbitrary-precision decimal number.
      EDecimal ToEDecimal​(EContext ctx)
      Converts this rational number to an arbitrary-precision decimal number and rounds the result to the given precision.
      EDecimal ToEDecimalExactIfPossible​(EContext ctx)
      Converts this rational number to an arbitrary-precision decimal number, but if the result would have a nonterminating decimal expansion, rounds that result to the given precision.
      EFloat ToEFloat()
      Converts this rational number to a binary float.
      EFloat ToEFloat​(EContext ctx)
      Converts this rational number to a binary float and rounds that result to the given precision.
      EFloat ToEFloatExactIfPossible​(EContext ctx)
      Converts this rational number to a binary float, but if the result would have a nonterminating binary expansion, rounds that result to the given precision.
      EInteger ToEInteger()
      Converts this value to an arbitrary-precision integer.
      EInteger ToEIntegerExact()
      Deprecated.
      Renamed to ToEIntegerIfExact.
      EInteger ToEIntegerIfExact()
      Converts this value to an arbitrary-precision integer, checking whether the value is an exact integer.
      EDecimal ToExtendedDecimal()
      Deprecated.
      Renamed to ToEDecimal.
      EDecimal ToExtendedDecimal​(EContext ctx)
      Deprecated.
      Renamed to ToEDecimal.
      EDecimal ToExtendedDecimalExactIfPossible​(EContext ctx)
      Deprecated.
      Renamed to ToEDecimalExactIfPossible.
      EFloat ToExtendedFloat()
      Deprecated.
      Renamed to ToEFloat.
      EFloat ToExtendedFloat​(EContext ctx)
      Deprecated.
      Renamed to ToEFloat.
      EFloat ToExtendedFloatExactIfPossible​(EContext ctx)
      Deprecated.
      Renamed to ToEFloatExactIfPossible.
      short ToInt16Checked()
      Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer after truncating to an integer.
      short ToInt16IfExact()
      Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer without rounding to a different numerical value.
      short ToInt16Unchecked()
      Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 16-bit signed integer.
      int ToInt32Checked()
      Converts this number's value to a 32-bit signed integer if it can fit in a 32-bit signed integer after truncating to an integer.
      int ToInt32IfExact()
      Converts this number's value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.
      int ToInt32Unchecked()
      Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 32-bit signed integer.
      long ToInt64Checked()
      Converts this number's value to a 64-bit signed integer if it can fit in a 64-bit signed integer after truncating to an integer.
      long ToInt64IfExact()
      Converts this number's value to a 64-bit signed integer if it can fit in a 64-bit signed integer without rounding to a different numerical value.
      long ToInt64Unchecked()
      Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 64-bit signed integer.
      float ToSingle()
      Converts this value to a 32-bit binary floating-point number.
      java.lang.String toString()
      Converts this object to a text string.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NaN

        public static final ERational NaN
        A not-a-number value.
      • NegativeInfinity

        public static final ERational NegativeInfinity
        Negative infinity, less than any other number.
      • NegativeZero

        public static final ERational NegativeZero
        A rational number for negative zero.
      • One

        public static final ERational One
        The rational number one.
      • PositiveInfinity

        public static final ERational PositiveInfinity
        Positive infinity, greater than any other number.
      • SignalingNaN

        public static final ERational SignalingNaN
        A signaling not-a-number value.
      • Ten

        public static final ERational Ten
        The rational number ten.
      • Zero

        public static final ERational Zero
        A rational number for zero.
    • Constructor Detail

      • ERational

        public ERational​(EInteger numerator,
                         EInteger denominator)
        Initializes a new instance of the ERational class.
        Parameters:
        numerator - The numerator.
        denominator - The denominator.
        Throws:
        java.lang.IllegalArgumentException - The denominator is zero.
        java.lang.NullPointerException - The parameter numerator or denominator is null.
    • Method Detail

      • Copy

        public ERational Copy()
        Creates a copy of this arbitrary-precision rational number.
        Returns:
        An arbitrary-precision binary rational number.
      • getDenominator

        public final EInteger getDenominator()
        Gets this object's denominator.
        Returns:
        This object' s denominator.
      • isFinite

        public final boolean isFinite()
        Gets a value indicating whether this object is finite (not infinity or NaN).
        Returns:
        true if this object is finite (not infinity or NaN); otherwise, false .
      • isNegative

        public final boolean isNegative()
        Gets a value indicating whether this object's value is negative (including negative zero).
        Returns:
        true if this object's value is negative (including negative zero); otherwise, false . true if this object's value is negative; otherwise, false .
      • isZero

        public final boolean isZero()
        Gets a value indicating whether this object's value equals 0.
        Returns:
        true if this object's value equals 0; otherwise, false . true if this object' s value equals 0; otherwise, . false .
      • getNumerator

        public final EInteger getNumerator()
        Gets this object's numerator.
        Returns:
        This object' s numerator. If this object is a not-a-number value, returns the diagnostic information (which will be negative if this object is negative).
      • signum

        public final int signum()
        Gets the sign of this rational number.
        Returns:
        The sign of this rational number.
      • getUnsignedNumerator

        public final EInteger getUnsignedNumerator()
        Gets this object's numerator with the sign removed.
        Returns:
        This object's numerator. If this object is a not-a-number value, returns the diagnostic information.
      • Create

        public static ERational Create​(int numeratorSmall,
                                       int denominatorSmall)
        Creates a rational number with the given numerator and denominator.
        Parameters:
        numeratorSmall - The numerator.
        denominatorSmall - The denominator.
        Returns:
        An arbitrary-precision binary rational number.
        Throws:
        java.lang.IllegalArgumentException - The denominator is zero.
      • Create

        public static ERational Create​(EInteger numerator,
                                       EInteger denominator)
        Creates a rational number with the given numerator and denominator.
        Parameters:
        numerator - The numerator.
        denominator - The denominator.
        Returns:
        An arbitrary-precision binary rational number.
        Throws:
        java.lang.IllegalArgumentException - The denominator is zero.
      • CreateNaN

        public static ERational CreateNaN​(EInteger diag)
        Creates a not-a-number arbitrary-precision rational number.
        Parameters:
        diag - An integer, 0 or greater, to use as diagnostic information associated with this object. If none is needed, should be zero. To get the diagnostic information from another arbitrary-precision binary rational number, use that object's UnsignedNumerator property.
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.IllegalArgumentException - The parameter "diag" is less than 0.
      • CreateNaN

        public static ERational CreateNaN​(EInteger diag,
                                          boolean signaling,
                                          boolean negative)
        Creates a not-a-number arbitrary-precision rational number.
        Parameters:
        diag - An integer, 0 or greater, to use as diagnostic information associated with this object. If none is needed, should be zero. To get the diagnostic information from another arbitrary-precision binary rational number, use that object's UnsignedNumerator property.
        signaling - Whether the return value will be signaling (true) or quiet (false).
        negative - Whether the return value is negative.
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.IllegalArgumentException - The parameter "diag" is less than 0.
        java.lang.NullPointerException - The parameter "diag" is null.
      • FromDouble

        public static ERational FromDouble​(double flt)
        Converts a 64-bit floating-point number to a rational number. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string.
        Parameters:
        flt - The parameter flt is a 64-bit floating-point number.
        Returns:
        A rational number with the same value as "flt".
      • FromExtendedDecimal

        @Deprecated
        public static ERational FromExtendedDecimal​(EDecimal ef)
        Deprecated.
        Renamed to FromEDecimal.
        Converts an arbitrary-precision decimal number to a rational number.
        Parameters:
        ef - The number to convert as an arbitrary-precision decimal number.
        Returns:
        An arbitrary-precision rational number.
      • FromExtendedFloat

        @Deprecated
        public static ERational FromExtendedFloat​(EFloat ef)
        Deprecated.
        Renamed to FromEFloat.
        Converts an arbitrary-precision binary float to a rational number.
        Parameters:
        ef - The number to convert as an arbitrary-precision binary floating-point number.
        Returns:
        An arbitrary-precision rational number.
      • FromEDecimal

        public static ERational FromEDecimal​(EDecimal ef)
        Converts an arbitrary-precision decimal number to a rational number.
        Parameters:
        ef - The number to convert as an arbitrary-precision decimal number.
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NullPointerException - The parameter "ef" is null.
      • FromEFloat

        public static ERational FromEFloat​(EFloat ef)
        Converts an arbitrary-precision binary float to a rational number.
        Parameters:
        ef - The number to convert as an arbitrary-precision binary floating-point number.
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NullPointerException - The parameter "ef" is null.
      • FromEInteger

        public static ERational FromEInteger​(EInteger bigint)
        Converts an arbitrary-precision integer to a rational number.
        Parameters:
        bigint - The number to convert as an arbitrary-precision integer.
        Returns:
        The exact value of the integer as a rational number.
      • FromSingle

        public static ERational FromSingle​(float flt)
        Converts a 32-bit binary floating-point number to a rational number. This method computes the exact value of the floating point number, not an approximation, as is often the case by converting the number to a string.
        Parameters:
        flt - The parameter flt is a 32-bit binary floating-point number.
        Returns:
        A rational number with the same value as "flt".
      • FromString

        public static ERational FromString​(java.lang.String str)
        Creates a rational number from a text string that represents a number. See FromString(String, int, int) for more information.
        Parameters:
        str - A string that represents a number.
        Returns:
        An arbitrary-precision rational number with the same value as the given string.
        Throws:
        java.lang.NumberFormatException - The parameter "str" is not a correctly formatted number string.
      • FromString

        public static ERational FromString​(java.lang.String str,
                                           int offset,
                                           int length)

        Creates a rational number from a text string that represents a number.

        The format of the string generally consists of:

        • An optional plus sign ("+" , U+002B) or minus sign ("-", U+002D) (if '-' , the value is negative.)
        • The numerator in the form of one or more digits.
        • Optionally, "/" followed by the denominator in the form of one or more digits. If a denominator is not given, it's equal to 1.

        The string can also be "-INF", "-Infinity", "Infinity", "INF", quiet NaN ("NaN" /"-NaN") followed by any number of digits, or signaling NaN ("sNaN" /"-sNaN") followed by any number of digits, all in any combination of upper and lower case.

        All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U + 0030 to U + 0039). The string is not allowed to contain white space characters, including spaces.

        Parameters:
        str - A text string, a portion of which represents a number.
        offset - A zero-based index showing where the desired portion of str begins.
        length - The length, in code units, of the desired portion of str (but not more than str 's length).
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NumberFormatException - The parameter "str" is not a correctly formatted number string.
        java.lang.NullPointerException - The parameter "str" is null.
      • CompareToTotalMagnitude

        public int CompareToTotalMagnitude​(ERational other)
        Compares the absolute values of this object and another object, imposing a total ordering on all possible values (ignoring their signs). In this method:
        • For objects with the same value, the one with the higher denominator has a greater "absolute value".
        • Negative zero and positive zero are considered equal.
        • Quiet NaN has a higher "absolute value" than signaling NaN. If both objects are quiet NaN or both are signaling NaN, the one with the higher diagnostic information has a greater "absolute value".
        • NaN has a higher "absolute value" than infinity.
        • Infinity has a higher "absolute value" than any finite number.
        Parameters:
        other - An arbitrary-precision rational number to compare with this one.
        Returns:
        The number 0 if both objects have the same value, or -1 if this object is less than the other value, or 1 if this object is greater.
      • CompareToTotal

        public int CompareToTotal​(ERational other)
        Compares the values of this object and another object, imposing a total ordering on all possible values. In this method:
        • For objects with the same value, the one with the higher denominator has a greater "absolute value".
        • Negative zero is less than positive zero.
        • Quiet NaN has a higher "absolute value" than signaling NaN. If both objects are quiet NaN or both are signaling NaN, the one with the higher diagnostic information has a greater "absolute value".
        • NaN has a higher "absolute value" than infinity.
        • Infinity has a higher "absolute value" than any finite number.
        • Negative numbers are less than positive numbers.
        Parameters:
        other - An arbitrary-precision rational number to compare with this one.
        Returns:
        The number 0 if both objects have the same value, or -1 if this object is less than the other value, or 1 if this object is greater.
      • Abs

        public ERational Abs()
        Returns the absolute value of this rational number, that is, a number with the same value as this one but as a nonnegative number.
        Returns:
        An arbitrary-precision binary rational number.
      • Add

        public ERational Add​(ERational otherValue)
        Adds two rational numbers.
        Parameters:
        otherValue - Another arbitrary-precision rational number.
        Returns:
        The sum of the two numbers. Returns not-a-number (NaN) if either operand is NaN.
        Throws:
        java.lang.NullPointerException - The parameter "otherValue" is null.
      • compareTo

        public int compareTo​(ERational other)
        Compares an arbitrary-precision rational number with this instance.
        Specified by:
        compareTo in interface java.lang.Comparable<ERational>
        Parameters:
        other - An arbitrary-precision rational number.
        Returns:
        Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
        Throws:
        java.lang.IllegalArgumentException - Doesn't satisfy this.isFinite(); doesn't satisfy other.isFinite().
      • CompareToBinary

        public int CompareToBinary​(EFloat other)
        Compares an arbitrary-precision binary float with this instance.
        Parameters:
        other - An arbitrary-precision binary floating-point number.
        Returns:
        Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
        Throws:
        java.lang.IllegalArgumentException - Doesn't satisfy this.isFinite(); doesn't satisfy other.isFinite().
      • CompareToDecimal

        public int CompareToDecimal​(EDecimal other)
        Compares an arbitrary-precision decimal number with this instance.
        Parameters:
        other - An arbitrary-precision decimal number.
        Returns:
        Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
        Throws:
        java.lang.IllegalArgumentException - Doesn't satisfy this.isFinite(); doesn't satisfy other.isFinite().
      • CopySign

        public ERational CopySign​(ERational other)
        Returns a number with the same value as this one, but copying the sign (positive or negative) of another number.
        Parameters:
        other - A number whose sign will be copied.
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NullPointerException - The parameter "other" is null.
      • Divide

        public ERational Divide​(ERational otherValue)
        Divides this instance by the value of an arbitrary-precision rational number object.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The quotient of the two objects.
        Throws:
        java.lang.NullPointerException - The parameter "otherValue" is null.
      • equals

        public boolean equals​(java.lang.Object obj)
        Determines whether this object's numerator, denominator, and properties are equal to those of another object and that other object is an arbitrary-precision rational number. Not-a-number values are considered equal if the rest of their properties are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The parameter obj is an arbitrary object.
        Returns:
        true if the objects are equal; otherwise, false .
      • equals

        public boolean equals​(ERational other)
        Determines whether this object's numerator, denominator, and properties are equal to those of another object. Not-a-number values are considered equal if the rest of their properties are equal.
        Parameters:
        other - An arbitrary-precision rational number to compare to.
        Returns:
        Either true or false .
      • hashCode

        public int hashCode()
        Returns the hash code for this instance. No application or process IDs are used in the hash code calculation.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A 32-bit signed integer.
      • IsInfinity

        public boolean IsInfinity()
        Gets a value indicating whether this object's value is infinity.
        Returns:
        true if this object's value is infinity; otherwise, false .
      • IsNaN

        public boolean IsNaN()
        Returns whether this object is a not-a-number value.
        Returns:
        true if this object is a not-a-number value; otherwise, false .
      • IsNegativeInfinity

        public boolean IsNegativeInfinity()
        Returns whether this object is negative infinity.
        Returns:
        true if this object is negative infinity; otherwise, false .
      • IsPositiveInfinity

        public boolean IsPositiveInfinity()
        Returns whether this object is positive infinity.
        Returns:
        true if this object is positive infinity; otherwise, false .
      • IsQuietNaN

        public boolean IsQuietNaN()
        Returns whether this object is a quiet not-a-number value.
        Returns:
        true if this object is a quiet not-a-number value; otherwise, false .
      • IsSignalingNaN

        public boolean IsSignalingNaN()
        Returns whether this object is a signaling not-a-number value (which causes an error if the value is passed to any arithmetic operation in this class).
        Returns:
        true if this object is a signaling not-a-number value (which causes an error if the value is passed to any arithmetic operation in this class); otherwise, false .
      • Multiply

        public ERational Multiply​(ERational otherValue)
        Multiplies this instance by the value of an arbitrary-precision rational number.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The product of the two numbers.
        Throws:
        java.lang.NullPointerException - The parameter "otherValue" is null.
      • Negate

        public ERational Negate()
        Returns a rational number with the same value as this one but with the sign reversed.
        Returns:
        An arbitrary-precision binary rational number.
      • Remainder

        public ERational Remainder​(ERational otherValue)
        Finds the remainder that results when this instance is divided by the value of an arbitrary-precision rational number.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The remainder of the two numbers.
        Throws:
        java.lang.NullPointerException - The parameter "otherValue" is null.
      • Subtract

        public ERational Subtract​(ERational otherValue)
        Subtracts an arbitrary-precision rational number from this instance.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The difference of the two objects.
        Throws:
        java.lang.NullPointerException - The parameter "otherValue" is null.
      • ToDouble

        public double ToDouble()
        Converts this value to a 64-bit floating-point number. The half-even rounding mode is used.
        Returns:
        The closest 64-bit floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 64-bit floating point number.
      • ToEInteger

        public EInteger ToEInteger()
        Converts this value to an arbitrary-precision integer. Any fractional part in this value will be discarded when converting to an arbitrary-precision integer.
        Returns:
        An arbitrary-precision integer.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN).
      • ToEIntegerExact

        @Deprecated
        public EInteger ToEIntegerExact()
        Deprecated.
        Renamed to ToEIntegerIfExact.
        Converts this value to an arbitrary-precision integer, checking whether the value is an exact integer.
        Returns:
        An arbitrary-precision integer.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN).
      • ToEIntegerIfExact

        public EInteger ToEIntegerIfExact()
        Converts this value to an arbitrary-precision integer, checking whether the value is an exact integer.
        Returns:
        An arbitrary-precision integer.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN).
      • ToEDecimal

        public EDecimal ToEDecimal()
        Converts this rational number to an arbitrary-precision decimal number.
        Returns:
        The exact value of the rational number, or not-a-number (NaN) if the result can't be exact because it has a nonterminating decimal expansion.
      • ToEDecimal

        public EDecimal ToEDecimal​(EContext ctx)
        Converts this rational number to an arbitrary-precision decimal number and rounds the result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating decimal expansion.
      • ToEDecimalExactIfPossible

        public EDecimal ToEDecimalExactIfPossible​(EContext ctx)
        Converts this rational number to an arbitrary-precision decimal number, but if the result would have a nonterminating decimal expansion, rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. This context will be used only if the exact result would have a nonterminating decimal expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating decimal expansion.
      • ToExtendedDecimal

        @Deprecated
        public EDecimal ToExtendedDecimal()
        Deprecated.
        Renamed to ToEDecimal.
        Converts this rational number to an arbitrary-precision decimal number.
        Returns:
        The exact value of the rational number, or not-a-number (NaN) if the result can't be exact because it has a nonterminating decimal expansion.
      • ToExtendedDecimal

        @Deprecated
        public EDecimal ToExtendedDecimal​(EContext ctx)
        Deprecated.
        Renamed to ToEDecimal.
        Converts this rational number to an arbitrary-precision decimal number and rounds the result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating decimal expansion.
      • ToExtendedDecimalExactIfPossible

        @Deprecated
        public EDecimal ToExtendedDecimalExactIfPossible​(EContext ctx)
        Deprecated.
        Renamed to ToEDecimalExactIfPossible.
        Converts this rational number to an arbitrary-precision decimal number, but if the result would have a nonterminating decimal expansion, rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. This context will be used only if the exact result would have a nonterminating decimal expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating decimal expansion.
      • ToEFloat

        public EFloat ToEFloat()
        Converts this rational number to a binary float.
        Returns:
        The exact value of the rational number, or not-a-number (NaN) if the result can't be exact because it has a nonterminating binary expansion.
      • ToEFloat

        public EFloat ToEFloat​(EContext ctx)
        Converts this rational number to a binary float and rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating binary expansion.
      • ToEFloatExactIfPossible

        public EFloat ToEFloatExactIfPossible​(EContext ctx)
        Converts this rational number to a binary float, but if the result would have a nonterminating binary expansion, rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. This context will be used only if the exact result would have a nonterminating binary expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating binary expansion.
      • ToExtendedFloat

        @Deprecated
        public EFloat ToExtendedFloat()
        Deprecated.
        Renamed to ToEFloat.
        Converts this rational number to a binary float.
        Returns:
        The exact value of the rational number, or not-a-number (NaN) if the result can't be exact because it has a nonterminating binary expansion.
      • ToExtendedFloat

        @Deprecated
        public EFloat ToExtendedFloat​(EContext ctx)
        Deprecated.
        Renamed to ToEFloat.
        Converts this rational number to a binary float and rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The value of the rational number, rounded to the given precision. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating binary expansion.
      • ToExtendedFloatExactIfPossible

        @Deprecated
        public EFloat ToExtendedFloatExactIfPossible​(EContext ctx)
        Deprecated.
        Renamed to ToEFloatExactIfPossible.
        Converts this rational number to a binary float, but if the result would have a nonterminating binary expansion, rounds that result to the given precision.
        Parameters:
        ctx - An arithmetic context object to control the precision, rounding, and exponent range of the result. This context will be used only if the exact result would have a nonterminating binary expansion. If HasFlags of the context is true, will also store the flags resulting from the operation (the flags are in addition to the pre-existing flags). Can be null, in which case the precision is unlimited and no rounding is needed.
        Returns:
        The exact value of the rational number if possible; otherwise, the rounded version of the result if a context is given. Returns not-a-number (NaN) if the context is null and the result can't be exact because it has a nonterminating binary expansion.
      • ToSingle

        public float ToSingle()
        Converts this value to a 32-bit binary floating-point number. The half-even rounding mode is used.
        Returns:
        The closest 32-bit binary floating-point number to this value. The return value can be positive infinity or negative infinity if this value exceeds the range of a 32-bit floating point number.
      • toString

        public java.lang.String toString()
        Converts this object to a text string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this object. If this object's value is infinity or not-a-number, the result is the analogous return value of the EDecimal.toString method. Otherwise, the return value has the following form: [-]numerator/denominator .
      • ToByteChecked

        public byte ToByteChecked()
        Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) after truncating to an integer.
        Returns:
        This number's value, truncated to a byte (from 0 to 255).
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, or the truncated integer is less than 0 or greater than 255.
      • ToByteUnchecked

        public byte ToByteUnchecked()
        Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a byte (from 0 to 255).
        Returns:
        This number, converted to a byte (from 0 to 255). Returns 0 if this value is infinity or not-a-number.
      • ToByteIfExact

        public byte ToByteIfExact()
        Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) without rounding to a different numerical value.
        Returns:
        This number's value as a byte (from 0 to 255).
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, is not an exact integer, or is less than 0 or greater than 255.
      • FromByte

        public static ERational FromByte​(byte inputByte)
        Converts a byte (from 0 to 255) to an arbitrary-precision rational number.
        Parameters:
        inputByte - The number to convert as a byte (from 0 to 255).
        Returns:
        This number's value as an arbitrary-precision rational number.
      • ToInt16Checked

        public short ToInt16Checked()
        Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer after truncating to an integer.
        Returns:
        This number's value, truncated to a 16-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, or the truncated integer is less than -32768 or greater than 32767.
      • ToInt16Unchecked

        public short ToInt16Unchecked()
        Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 16-bit signed integer.
        Returns:
        This number, converted to a 16-bit signed integer. Returns 0 if this value is infinity or not-a-number.
      • ToInt16IfExact

        public short ToInt16IfExact()
        Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer without rounding to a different numerical value.
        Returns:
        This number's value as a 16-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, is not an exact integer, or is less than -32768 or greater than 32767.
      • FromInt16

        public static ERational FromInt16​(short inputInt16)
        Converts a 16-bit signed integer to an arbitrary-precision rational number.
        Parameters:
        inputInt16 - The number to convert as a 16-bit signed integer.
        Returns:
        This number's value as an arbitrary-precision rational number.
      • ToInt32Checked

        public int ToInt32Checked()
        Converts this number's value to a 32-bit signed integer if it can fit in a 32-bit signed integer after truncating to an integer.
        Returns:
        This number's value, truncated to a 32-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, or the truncated integer is less than -2147483648 or greater than 2147483647.
      • ToInt32Unchecked

        public int ToInt32Unchecked()
        Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 32-bit signed integer.
        Returns:
        This number, converted to a 32-bit signed integer. Returns 0 if this value is infinity or not-a-number.
      • ToInt32IfExact

        public int ToInt32IfExact()
        Converts this number's value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.
        Returns:
        This number's value as a 32-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, is not an exact integer, or is less than -2147483648 or greater than 2147483647.
      • FromBoolean

        public static ERational FromBoolean​(boolean boolValue)
        Converts a boolean value (true or false) to an arbitrary-precision rational number.
        Parameters:
        boolValue - Either true or false.
        Returns:
        The number 1 if boolValue is true; otherwise, 0.
      • FromInt32

        public static ERational FromInt32​(int inputInt32)
        Converts a 32-bit signed integer to an arbitrary-precision rational number.
        Parameters:
        inputInt32 - The number to convert as a 32-bit signed integer.
        Returns:
        This number's value as an arbitrary-precision rational number.
      • ToInt64Checked

        public long ToInt64Checked()
        Converts this number's value to a 64-bit signed integer if it can fit in a 64-bit signed integer after truncating to an integer.
        Returns:
        This number's value, truncated to a 64-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, or the truncated integer is less than -9223372036854775808 or greater than 9223372036854775807.
      • ToInt64Unchecked

        public long ToInt64Unchecked()
        Truncates this number's value to an integer and returns the least-significant bits of its two's-complement form as a 64-bit signed integer.
        Returns:
        This number, converted to a 64-bit signed integer. Returns 0 if this value is infinity or not-a-number.
      • ToInt64IfExact

        public long ToInt64IfExact()
        Converts this number's value to a 64-bit signed integer if it can fit in a 64-bit signed integer without rounding to a different numerical value.
        Returns:
        This number's value as a 64-bit signed integer.
        Throws:
        java.lang.ArithmeticException - This value is infinity or not-a-number, is not an exact integer, or is less than -9223372036854775808 or greater than 9223372036854775807.
      • FromInt64

        public static ERational FromInt64​(long inputInt64)
        Converts a 64-bit signed integer to an arbitrary-precision rational number.
        Parameters:
        inputInt64 - The number to convert as a 64-bit signed integer.
        Returns:
        This number's value as an arbitrary-precision rational number.