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.) In this class, a rational number consists of a numerator and denominator, each an arbitrary-precision integer (EInteger), and this class does not automatically convert rational numbers to lowest terms.

    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).

    • Constructor Summary

      Constructors 
      Constructor Description
      ERational​(EInteger numerator, EInteger denominator)
      Deprecated.
      Use the Create method instead.
    • 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​(int v)
      Adds this arbitrary-precision rational number and a 32-bit signed integer and returns the result.
      ERational Add​(long v)
      Adds this arbitrary-precision rational number and a 64-bit signed integer and returns the result.
      ERational Add​(ERational otherValue)
      Adds this arbitrary-precision rational number and another arbitrary-precision rational number and returns the result.
      int compareTo​(int intOther)
      Compares the mathematical value of an arbitrary-precision rational number with that of this instance.
      int compareTo​(long intOther)
      Compares the mathematical values of this object and another object, accepting NaN values.
      int compareTo​(ERational other)
      Compares the mathematical value of an arbitrary-precision rational number with that of this instance.
      int CompareToBinary​(EFloat other)
      Compares an arbitrary-precision binary floating-point number 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).
      int CompareToValue​(int intOther)
      Compares the mathematical value of an arbitrary-precision rational number with that of this instance.
      int CompareToValue​(long intOther)
      Compares the mathematical values of this object and another object, accepting NaN values.
      int CompareToValue​(ERational other)
      Compares the mathematical value of an arbitrary-precision rational number with that of this instance.
      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​(long numeratorLong, long denominatorLong)
      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 Decrement()
      Subtracts one from an arbitrary-precision rational number.
      ERational Divide​(int v)
      Divides this arbitrary-precision rational number by a 32-bit signed integer and returns the result.
      ERational Divide​(long v)
      Divides this arbitrary-precision rational number by a 64-bit signed integer and returns the result.
      ERational Divide​(ERational otherValue)
      Divides this arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.
      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 FromDoubleBits​(long value)
      Creates a binary rational number from a 64-bit floating-point number encoded in the IEEE 754 binary64 format.
      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 floating-point number 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 FromSingleBits​(int value)
      Creates a binary rational number from a 32-bit floating-point number encoded in the IEEE 754 binary32 format.
      static ERational FromString​(byte[] bytes)
      Creates a rational number from a sequence of bytes that represents a number.
      static ERational FromString​(byte[] bytes, int offset, int length)
      Creates a rational number from a sequence of bytes that represents a number.
      static ERational FromString​(char[] chars)
      Creates a rational number from a sequence of char s that represents a number.
      static ERational FromString​(char[] chars, int offset, int length)
      Creates a rational number from a sequence of char s that represents a 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.
      ERational Increment()
      Adds one to an arbitrary-precision rational number.
      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 IsInteger()
      Returns whether this object's value is an integer.
      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.
      static ERational Max​(ERational first, ERational second)
      Gets the greater value between two rational numbers.
      static ERational MaxMagnitude​(ERational first, ERational second)
      Gets the greater value between two values, ignoring their signs.
      static ERational Min​(ERational first, ERational second)
      Gets the lesser value between two rational numbers.
      static ERational MinMagnitude​(ERational first, ERational second)
      Gets the lesser value between two values, ignoring their signs.
      ERational Multiply​(int v)
      Multiplies this arbitrary-precision rational number by a 32-bit signed integer and returns the result.
      ERational Multiply​(long v)
      Multiplies this arbitrary-precision rational number by a 64-bit signed integer and returns the result.
      ERational Multiply​(ERational otherValue)
      Multiplies this arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.
      ERational Negate()
      Returns a rational number with the same value as this one but with the sign reversed.
      ERational Remainder​(int v)
      Returns the remainder that would result when this arbitrary-precision rational number is divided by a 32-bit signed integer.
      ERational Remainder​(long v)
      Returns the remainder that would result when this arbitrary-precision rational number is divided by a 64-bit signed integer.
      ERational Remainder​(ERational otherValue)
      Returns the remainder that would result when this arbitrary-precision rational number is divided by another arbitrary-precision rational number.
      int signum()
      Gets the sign of this rational number.
      ERational Subtract​(int v)
      Subtracts a 32-bit signed integer from this arbitrary-precision rational number and returns the result.
      ERational Subtract​(long v)
      Subtracts a 64-bit signed integer from this arbitrary-precision rational number and returns the result.
      ERational Subtract​(ERational otherValue)
      Subtracts an arbitrary-precision rational number from this arbitrary-precision rational number and returns the result.
      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 converting it to an integer by discarding its fractional part.
      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()
      Converts this number's value to an integer (using ToEInteger), and returns the least-significant bits of that integer's two's-complement form as a byte (from 0 to 255).
      double ToDouble()
      Converts this value to a 64-bit floating-point number.
      long ToDoubleBits()
      Converts this value to its closest equivalent as a 64-bit floating-point number, expressed as an integer in the IEEE 754 binary64 format.
      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 floating-point number.
      EFloat ToEFloat​(EContext ctx)
      Converts this rational number to a binary floating-point number and rounds that result to the given precision.
      EFloat ToEFloatExactIfPossible​(EContext ctx)
      Converts this rational number to a binary floating-point number, 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 by dividing the numerator by the denominator and discarding the fractional part of the result.
      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 converting it to an integer by discarding its fractional part.
      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()
      Converts this number's value to an integer by discarding its fractional part, 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 converting it to an integer by discarding its fractional part.
      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()
      Converts this number's value to an integer by discarding its fractional part, 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 converting it to an integer by discarding its fractional part.
      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()
      Converts this number's value to an integer by discarding its fractional part, and returns the least-significant bits of its two's-complement form as a 64-bit signed integer.
      ERational ToLowestTerms()
      Converts this value to its form in lowest terms.
      float ToSingle()
      Converts this value to a 32-bit binary floating-point number.
      int ToSingleBits()
      Converts this value to its closest equivalent as 32-bit floating-point number, expressed as an integer in the IEEE 754 binary32 format.
      EInteger ToSizedEInteger​(int maxBitLength)
      Converts this value to an arbitrary-precision integer by dividing the numerator by the denominator, discarding its fractional part, and checking whether the resulting integer overflows the given signed bit count.
      EInteger ToSizedEIntegerIfExact​(int maxBitLength)
      Converts this value to an arbitrary-precision integer, only if this number's value is an exact integer and that integer does not overflow the given signed bit count.
      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

        @Deprecated
        public ERational​(EInteger numerator,
                         EInteger denominator)
        Deprecated.
        Use the Create method instead.
        Initializes a new instance of the ERational class.
        Parameters:
        numerator - An arbitrary-precision integer serving as the numerator.
        denominator - An arbitrary-precision integer serving as the denominator.
        Throws:
        java.lang.NullPointerException - The parameter numerator or denominator is null.
        java.lang.IllegalArgumentException - Denominator is zero.
    • Method Detail

      • Copy

        public ERational Copy()
        Creates a copy of this arbitrary-precision rational number.
        Returns:
        An arbitrary-precision 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.
      • IsInteger

        public boolean IsInteger()
        Returns whether this object's value is an integer.
        Returns:
        true if this object's value is an integer; 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 rational number.
        Throws:
        java.lang.IllegalArgumentException - The denominator is zero.
      • Create

        public static ERational Create​(long numeratorLong,
                                       long denominatorLong)
        Creates a rational number with the given numerator and denominator.
        Parameters:
        numeratorLong - The numerator.
        denominatorLong - The denominator.
        Returns:
        An arbitrary-precision 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 rational number.
        Throws:
        java.lang.IllegalArgumentException - The denominator is zero.
        java.lang.NullPointerException - The parameter numerator or denominator is null.
      • 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 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 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 floating-point number 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 floating-point number 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.
      • FromSingleBits

        public static ERational FromSingleBits​(int value)
        Creates a binary rational number from a 32-bit floating-point number encoded in the IEEE 754 binary32 format. 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:
        value - A 32-bit integer encoded in the IEEE 754 binary32 format.
        Returns:
        A rational number with the same floating-point value as value.
      • FromDoubleBits

        public static ERational FromDoubleBits​(long value)
        Creates a binary rational number from a 64-bit floating-point number encoded in the IEEE 754 binary64 format. 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:
        value - A 64-bit integer encoded in the IEEE 754 binary64 format.
        Returns:
        A rational number with the same floating-point value as value.
      • 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 (these digits may begin with any number of zeros).
        • Optionally, "/" followed by the denominator in the form of one or more digits (these digits may begin with any number of zeros). 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 - An index starting at 0 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.
        java.lang.IllegalArgumentException - Either offset or length is less than 0 or greater than str 's length, or str 's length minus offset is less than length.
      • FromString

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

        public static ERational FromString​(char[] chars,
                                           int offset,
                                           int length)

        Creates a rational number from a sequence of char s that represents a number.

        The format of the sequence of char s 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 (these digits may begin with any number of zeros).
        • Optionally, "/" followed by the denominator in the form of one or more digits (these digits may begin with any number of zeros). If a denominator is not given, it's equal to 1.

        The sequence of char s 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 sequence of char s is not allowed to contain white space characters, including spaces.

        Parameters:
        chars - A sequence of char s, a portion of which represents a number.
        offset - An index starting at 0 showing where the desired portion of chars begins.
        length - The length, in code units, of the desired portion of chars (but not more than chars 's length).
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NumberFormatException - The parameter chars is not a correctly formatted sequence of char s.
        java.lang.NullPointerException - The parameter chars is null.
        java.lang.IllegalArgumentException - Either offset or length is less than 0 or greater than chars 's length, or chars 's length minus offset is less than length.
      • FromString

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

        public static ERational FromString​(byte[] bytes,
                                           int offset,
                                           int length)

        Creates a rational number from a sequence of bytes that represents a number.

        The format of the sequence of bytes 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 (these digits may begin with any number of zeros).
        • Optionally, "/" followed by the denominator in the form of one or more digits (these digits may begin with any number of zeros). If a denominator is not given, it's equal to 1.

        The sequence of bytes 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 sequence of bytes is not allowed to contain white space characters, including spaces.

        Parameters:
        bytes - A sequence of bytes, a portion of which represents a number.
        offset - An index starting at 0 showing where the desired portion of bytes begins.
        length - The length, in code units, of the desired portion of bytes (but not more than bytes 's length).
        Returns:
        An arbitrary-precision rational number.
        Throws:
        java.lang.NumberFormatException - The parameter bytes is not a correctly formatted sequence of bytes.
        java.lang.NullPointerException - The parameter bytes is null.
        java.lang.IllegalArgumentException - Either offset or length is less than 0 or greater than bytes 's length, or bytes 's length minus offset is less than length.
      • 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. This implementation returns a positive number if.
      • 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. This implementation returns a positive number if.
      • 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 rational number.
      • Add

        public ERational Add​(ERational otherValue)
        Adds this arbitrary-precision rational number and another arbitrary-precision rational number and returns the result.
        Parameters:
        otherValue - Another arbitrary-precision rational number.
        Returns:
        The sum of the two numbers, that is, this arbitrary-precision rational number plus another arbitrary-precision rational number.
        Throws:
        java.lang.NullPointerException - The parameter otherValue is null.
      • compareTo

        public int compareTo​(ERational other)
        Compares the mathematical value of an arbitrary-precision rational number with that of this instance. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.
        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. This implementation returns a positive number if.
      • CompareToValue

        public int CompareToValue​(ERational other)
        Compares the mathematical value of an arbitrary-precision rational number with that of this instance. In this method, NaN values are greater than any other ERational value, and two NaN values (even if their payloads differ) are treated as equal by this method. This method is not consistent with the Equals method.
        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. This implementation returns a positive number if.
      • Max

        public static ERational Max​(ERational first,
                                    ERational second)
        Gets the greater value between two rational numbers.
        Parameters:
        first - An arbitrary-precision rational number.
        second - Another arbitrary-precision rational number.
        Returns:
        The larger value of the two numbers. If one is positive zero and the other is negative zero, returns the positive zero. If the two numbers are positive and have the same value, returns the one with the larger denominator. If the two numbers are negative and have the same value, returns the one with the smaller denominator.
        Throws:
        java.lang.NullPointerException - The parameter first or second is null.
      • MaxMagnitude

        public static ERational MaxMagnitude​(ERational first,
                                             ERational second)
        Gets the greater value between two values, ignoring their signs. If the absolute values are equal, has the same effect as Max.
        Parameters:
        first - The first value to compare.
        second - The second value to compare.
        Returns:
        The larger value of the two numbers, ignoring their signs.
        Throws:
        java.lang.NullPointerException - The parameter first or second is null.
      • Min

        public static ERational Min​(ERational first,
                                    ERational second)
        Gets the lesser value between two rational numbers.
        Parameters:
        first - The first value to compare.
        second - The second value to compare.
        Returns:
        The smaller value of the two numbers. If one is positive zero and the other is negative zero, returns the negative zero. If the two numbers are positive and have the same value, returns the one with the smaller denominator. If the two numbers are negative and have the same value, returns the one with the larger denominator.
        Throws:
        java.lang.NullPointerException - The parameter first or second is null.
      • MinMagnitude

        public static ERational MinMagnitude​(ERational first,
                                             ERational second)
        Gets the lesser value between two values, ignoring their signs. If the absolute values are equal, has the same effect as Min.
        Parameters:
        first - The first value to compare.
        second - The second value to compare.
        Returns:
        The smaller value of the two numbers, ignoring their signs.
        Throws:
        java.lang.NullPointerException - The parameter first or second is null.
      • compareTo

        public int compareTo​(int intOther)
        Compares the mathematical value of an arbitrary-precision rational number with that of this instance. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.
        Parameters:
        intOther - The parameter intOther is a 32-bit signed integer.
        Returns:
        Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
      • CompareToValue

        public int CompareToValue​(int intOther)
        Compares the mathematical value of an arbitrary-precision rational number with that of this instance. In this method, NaN values are greater than any other ERational value, and two NaN values (even if their payloads differ) are treated as equal by this method. This method is not consistent with the Equals method.
        Parameters:
        intOther - The parameter intOther is a 32-bit signed integer.
        Returns:
        Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
      • CompareToValue

        public int CompareToValue​(long intOther)
        Compares the mathematical values of this object and another object, accepting NaN values.

        This method is not consistent with the Equals method because two different numbers with the same mathematical value, but different exponents, will compare as equal.

        In this method, negative zero and positive zero are considered equal.

        If this object is a quiet NaN or signaling NaN, this method will not trigger an error. Instead, NaN will compare greater than any other number, including infinity.

        Parameters:
        intOther - The parameter intOther is a 64-bit signed integer.
        Returns:
        Less than 0 if this object's value is less than the other value, or greater than 0 if this object's value is greater than the other value, or 0 if both values are equal.
      • compareTo

        public int compareTo​(long intOther)
        Compares the mathematical values of this object and another object, accepting NaN values. This method currently uses the rules given in the CompareToValue method, so that it it is not consistent with the Equals method, but it may change in a future version to use the rules for the CompareToTotal method instead.
        Parameters:
        intOther - The parameter intOther is a 64-bit signed integer.
        Returns:
        Less than 0 if this object's value is less than the other value, or greater than 0 if this object's value is greater than the other value, or 0 if both values are equal.
      • CompareToBinary

        public int CompareToBinary​(EFloat other)
        Compares an arbitrary-precision binary floating-point number with this instance. In this method, NaN values are greater than any other ERational or EFloat value, and two NaN values (even if their payloads differ) are treated as equal by this method.
        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. This implementation returns a positive number if.
      • 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. This implementation returns a positive number if.
      • 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 arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The result of dividing this arbitrary-precision rational number by another arbitrary-precision rational number.
        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. In this method, two objects are not equal if they don't have the same type or if one is null and the other isn't.
      • 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 arbitrary-precision rational number by another arbitrary-precision rational number and returns the result.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The product of the two numbers, that is, this arbitrary-precision rational number times another arbitrary-precision rational number.
        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 rational number.
      • Remainder

        public ERational Remainder​(ERational otherValue)
        Returns the remainder that would result when this arbitrary-precision rational number is divided by another arbitrary-precision rational number.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The remainder that would result when this arbitrary-precision rational number is divided by another arbitrary-precision rational number.
        Throws:
        java.lang.NullPointerException - The parameter otherValue is null.
      • Subtract

        public ERational Subtract​(ERational otherValue)
        Subtracts an arbitrary-precision rational number from this arbitrary-precision rational number and returns the result.
        Parameters:
        otherValue - An arbitrary-precision rational number.
        Returns:
        The difference between the two numbers, that is, this arbitrary-precision rational number minus another arbitrary-precision rational number.
        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.
      • ToDoubleBits

        public long ToDoubleBits()
        Converts this value to its closest equivalent as a 64-bit floating-point number, expressed as an integer in the IEEE 754 binary64 format. The half-even rounding mode is used.

        If this value is a NaN, sets the high bit of the 64-bit floating point number's significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object's unsigned significand, and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN.

        Returns:
        The closest 64-bit binary floating-point number to this value, expressed as an integer in the IEEE 754 binary64 format. The return value can be positive infinity or negative infinity if this value exceeds the range of a 64-bit floating point number.
      • ToSingleBits

        public int ToSingleBits()
        Converts this value to its closest equivalent as 32-bit floating-point number, expressed as an integer in the IEEE 754 binary32 format. The half-even rounding mode is used.

        If this value is a NaN, sets the high bit of the 32-bit floating point number's significand area for a quiet NaN, and clears it for a signaling NaN. Then the other bits of the significand area are set to the lowest bits of this object's unsigned significand, and the next-highest bit of the significand area is set if those bits are all zeros and this is a signaling NaN.

        Returns:
        The closest 32-bit binary floating-point number to this value, expressed as an integer in the IEEE 754 binary32 format. The return value can be positive infinity or negative infinity if this value exceeds the range of a 32-bit floating point number.
      • ToLowestTerms

        public ERational ToLowestTerms()
        Converts this value to its form in lowest terms. For example, (8/4) becomes (4/1).
        Returns:
        An arbitrary-precision rational with the same value as this one but in lowest terms. Returns this object if it is infinity or NaN. Returns ERational.NegativeZero if this object is a negative zero. Returns ERational.Zero if this object is a positive zero.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN).
      • ToSizedEInteger

        public EInteger ToSizedEInteger​(int maxBitLength)
        Converts this value to an arbitrary-precision integer by dividing the numerator by the denominator, discarding its fractional part, and checking whether the resulting integer overflows the given signed bit count.
        Parameters:
        maxBitLength - The maximum number of signed bits the integer can have. The integer's value may not be less than -(2^maxBitLength) or greater than (2^maxBitLength) - 1.
        Returns:
        An arbitrary-precision integer.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN), or this number's value, once converted to an integer by dividing the numerator by the denominator and discarding its fractional part, is less than -(2^maxBitLength) or greater than (2^maxBitLength) - 1.
      • ToSizedEIntegerIfExact

        public EInteger ToSizedEIntegerIfExact​(int maxBitLength)
        Converts this value to an arbitrary-precision integer, only if this number's value is an exact integer and that integer does not overflow the given signed bit count.
        Parameters:
        maxBitLength - The maximum number of signed bits the integer can have. The integer's value may not be less than -(2^maxBitLength) or greater than (2^maxBitLength) - 1.
        Returns:
        An arbitrary-precision integer.
        Throws:
        java.lang.ArithmeticException - This object's value is infinity or not-a-number (NaN), or this number's value as an integer is less than -(2^maxBitLength) or greater than (2^maxBitLength) - 1.
        java.lang.ArithmeticException - This object's value is not an exact integer.
      • ToEInteger

        public EInteger ToEInteger()
        Converts this value to an arbitrary-precision integer by dividing the numerator by the denominator and discarding the fractional part of the result.
        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 floating-point 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 binary expansion.
      • ToEFloat

        public EFloat ToEFloat​(EContext ctx)
        Converts this rational number to a binary floating-point number 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 floating-point number, 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 floating-point 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 binary expansion.
      • ToExtendedFloat

        @Deprecated
        public EFloat ToExtendedFloat​(EContext ctx)
        Deprecated.
        Renamed to ToEFloat.
        Converts this rational number to a binary floating-point number 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 floating-point number, 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.Divide(denominator).
      • Increment

        public ERational Increment()
        Adds one to an arbitrary-precision rational number.
        Returns:
        The given arbitrary-precision rational number plus one.
      • Decrement

        public ERational Decrement()
        Subtracts one from an arbitrary-precision rational number.
        Returns:
        The given arbitrary-precision rational number minus one.
      • Add

        public ERational Add​(int v)
        Adds this arbitrary-precision rational number and a 32-bit signed integer and returns the result.
        Parameters:
        v - A 32-bit signed integer.
        Returns:
        The sum of the two numbers, that is, this arbitrary-precision rational number plus a 32-bit signed integer.
      • Subtract

        public ERational Subtract​(int v)
        Subtracts a 32-bit signed integer from this arbitrary-precision rational number and returns the result.
        Parameters:
        v - The parameter v is a 32-bit signed integer.
        Returns:
        The difference between the two numbers, that is, this arbitrary-precision rational number minus a 32-bit signed integer.
      • Multiply

        public ERational Multiply​(int v)
        Multiplies this arbitrary-precision rational number by a 32-bit signed integer and returns the result.
        Parameters:
        v - The parameter v is a 32-bit signed integer.
        Returns:
        The product of the two numbers, that is, this arbitrary-precision rational number times a 32-bit signed integer.
      • Divide

        public ERational Divide​(int v)
        Divides this arbitrary-precision rational number by a 32-bit signed integer and returns the result.
        Parameters:
        v - The parameter v is a 32-bit signed integer.
        Returns:
        The result of dividing this arbitrary-precision rational number by a 32-bit signed integer.
        Throws:
        java.lang.ArithmeticException - The parameter v is zero.
      • Remainder

        public ERational Remainder​(int v)
        Returns the remainder that would result when this arbitrary-precision rational number is divided by a 32-bit signed integer.
        Parameters:
        v - The divisor.
        Returns:
        The remainder that would result when this arbitrary-precision rational number is divided by a 32-bit signed integer.
        Throws:
        java.lang.IllegalArgumentException - The parameter v is zero.
      • Add

        public ERational Add​(long v)
        Adds this arbitrary-precision rational number and a 64-bit signed integer and returns the result.
        Parameters:
        v - A 64-bit signed integer.
        Returns:
        The sum of the two numbers, that is, this arbitrary-precision rational number plus a 64-bit signed integer.
      • Subtract

        public ERational Subtract​(long v)
        Subtracts a 64-bit signed integer from this arbitrary-precision rational number and returns the result.
        Parameters:
        v - The parameter v is a 64-bit signed integer.
        Returns:
        The difference between the two numbers, that is, this arbitrary-precision rational number minus a 64-bit signed integer.
      • Multiply

        public ERational Multiply​(long v)
        Multiplies this arbitrary-precision rational number by a 64-bit signed integer and returns the result.
        Parameters:
        v - The parameter v is a 64-bit signed integer.
        Returns:
        The product of the two numbers, that is, this arbitrary-precision rational number times a 64-bit signed integer.
      • Divide

        public ERational Divide​(long v)
        Divides this arbitrary-precision rational number by a 64-bit signed integer and returns the result.
        Parameters:
        v - The parameter v is a 64-bit signed integer.
        Returns:
        The result of dividing this arbitrary-precision rational number by a 64-bit signed integer.
        Throws:
        java.lang.ArithmeticException - The parameter v is zero.
      • Remainder

        public ERational Remainder​(long v)
        Returns the remainder that would result when this arbitrary-precision rational number is divided by a 64-bit signed integer.
        Parameters:
        v - The divisor.
        Returns:
        The remainder that would result when this arbitrary-precision rational number is divided by a 64-bit signed integer.
        Throws:
        java.lang.IllegalArgumentException - The parameter v is zero.
      • 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 converting it to an integer by discarding its fractional part.
        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 number, once converted to an integer by discarding its fractional part, is less than 0 or greater than 255.
      • ToByteUnchecked

        public byte ToByteUnchecked()
        Converts this number's value to an integer (using ToEInteger), and returns the least-significant bits of that integer's 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 converting it to an integer by discarding its fractional part.
        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 number, once converted to an integer by discarding its fractional part, is less than -32768 or greater than 32767.
      • ToInt16Unchecked

        public short ToInt16Unchecked()
        Converts this number's value to an integer by discarding its fractional part, 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 converting it to an integer by discarding its fractional part.
        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 number, once converted to an integer by discarding its fractional part, is less than -2147483648 or greater than 2147483647.
      • ToInt32Unchecked

        public int ToInt32Unchecked()
        Converts this number's value to an integer by discarding its fractional part, 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 converting it to an integer by discarding its fractional part.
        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 number, once converted to an integer by discarding its fractional part, is less than -9223372036854775808 or greater than 9223372036854775807.
      • ToInt64Unchecked

        public long ToInt64Unchecked()
        Converts this number's value to an integer by discarding its fractional part, 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.