Class Quadruple

java.lang.Object
java.lang.Number
gaiasky.util.math.Quadruple
All Implemented Interfaces:
Serializable, Comparable<Quadruple>

public class Quadruple extends Number implements Comparable<Quadruple>
Quadruple-precision floating-point implementation. I have removed unnecessary methods (most of BigDecimal stuff) and cleaned up the code (remove unneeded comments, fixed typos, delete unnecessary return statements and parameters, etc.). The string parsing utilities, as well as the string conversions, have been moved to QuadrupleParser. I have also made the class thread-safe by wrapping the working buffers around with a ThreadLocal.

Original code by M. Vokhmentsev, see this repository.

A floating-point number with a 128-bit fractional part of the mantissa and 32-bit exponent. Normal values range from approximately 2.271e-646456993 to 1.761e+646456993 with precision not worse than 1,469368e-39 (2^-129, half the less significant bit).

Like standard double, it can store and process subnormal values, with lower precision. The subnormal values range from 6.673e-646457032 to 2.271e-646456993, they use less than 129 bits of the mantissa and their precision depends on the number of used bits, the less the value the worst the precision.

Implements conversions from/to other numeric types, conversions from/to strings, formatting, arithmetic operations and square root.

Instances are mutable, a.add(2) changes the value of a so that it becomes a + 2, and a number of assign() methods with different types of arguments replace the old value with the new one, converted from the argument value.

For arithmetic operations, there provided both instance methods that modify the value of the instance, and static methods that return new instances with resulting values without changing the operands. A value of any numeric type may be used as an argument (the second one for static methods) in arithmetic operations. All the methods implementing arithmetic operations and assignments allow for chaining, so that one can write

a = a.add(2).multiply(5).divide(3);

to compute

a = (a + 2) * 5 / 3.

An instance internally contains boolean flag for the value's sign, 32-bit (an int) of binary exponent, and 128 bits (2 longs) of fractional part of the mantissa. Like with usual floating-point formats (e.g. standard Java double), the most significant bit of the mantissa is not stored explicitly and the exponent is biased.

The biased exponent values stored in the exponent field are as following:

biased value const name means unbiased exponent (power of 2)
0x0000_0000 EXPONENT_OF_SUBNORMAL subnormal values 0x8000_0001 = -2147483647 = Integer.MIN_VALUE + 1
0x0000_0001 EXPONENT_OF_MIN_NORMAL MIN_NORMAL 0x8000_0002 = -2147483646 = Integer.MIN_VALUE + 2
0x7FFF_FFFE   -1 0xFFFF_FFFF
0x7FFF_FFFF EXPONENT_OF_ONE 0 0x0000_0000
0x8000_0000   1 0x0000_0001
0xFFFF_FFFE EXPONENT_OF_MAX_VALUE MAX_VALUE 0x7fff_ffff = 2147483647 = Integer.MAX_VALUE
0xFFFF_FFFF EXPONENT_OF_INFINITY Infinity 0x8000_0000 = 2147483648 = Integer.MIN_VALUE
Quadruple constants and information.

The boundaries of the range are:
MAX_VALUE:  2^2147483647 * (2 - 2^-128) =
            = 1.76161305168396335320749314979184028566452310e+646456993
MIN_NORMAL: 2^-2147483646 =
            = 2.27064621040149253752656726517958758124747730e-646456993
MIN_VALUE:  2^-2147483774 =
            = 6.67282948260747430814835377499134611597699952e-646457032
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The value of the exponent (biased) corresponding to 1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF) The same as EXPONENT_OF_ONE
    static final int
    The value of the exponent (biased), corresponding to Infinity, -Infinity, and NaN; equals to -1 (0xFFFF_FFFF)
    static final long
    The value of the exponent (biased), corresponding to MAX_VALUE; equals to 4_294_967_294L (0xFFFF_FFFEL)
    static final int
    The value of the exponent (biased) corresponding to 1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of Quadruple with value 0.0
    Quadruple(boolean negative, int exponent, long mantHi, long mantLo)
    Creates a new Quadruple built from the given parts.
    Quadruple(double dValue)
    Creates a new Quadruple instance with the given double value.
    First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(double).
    Quadruple(int exponent, long mantHi, long mantLo)
    Creates a new Quadruple with a positive value built from the given parts.
    Quadruple(long lValue)
    Creates a new Quadruple with the given long value.
    First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(long).
    Creates a new Quadruple instance with the value of the given Quadruple instance.
    First creates an empty (zero) instance, then copies the fields of the parameter.
    Quadruple(String strValue)
    Creates a new Quadruple with the value represented by the given String.
    First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Returns a new instance of Quadruple with the value of the absolute value of this instance
    add(double summand)
    Adds the value of the given double summand to the value of this Quadruple.
    add(long summand)
    Adds the value of the given long summand to the value of this Quadruple.
    add(Quadruple summand)
    Adds the value of the given Quadruple summand to the value of this Quadruple.
    static Quadruple
    add(Quadruple op1, double op2)
    Adds the value of the given double op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum.
    static Quadruple
    add(Quadruple op1, long op2)
    Adds the value of the given long op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum.
    static Quadruple
    add(Quadruple op1, Quadruple op2)
    Adds the value of the given Quadruple op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum.
    assign(double value)
    Converts the given value to quadruple and assigns it to the instance.
    Expands exponent to 32 bits preserving its value, and expands mantissa to 128 bits, filling with zeroes the least significant 76 bits that absent in the double value.
    assign(long value)
    Converts the given value to quadruple and assigns it to the instance.
    To find the mantissa, shifts the bits of the absolute value of the parameter left, so that its most significant non-zero bit (that stands for the 'implicit unity' of the floating point formats) gets shifted out, then corrects the exponent depending on the shift distance and sets the sign in accordance with the initial sign of the parameter.
    assign(Quadruple qValue)
    Assigns the given value to the instance (copies the values of the private fields of the parameter to the respective fields of this instance).
    assign(String source)
    Parses the given String that is expected to contain floating-point value in any conventional string form or a string designation of one of special values, and assigns the corresponding value to the instance.
    Parsing is case-insensitive.
    The admittable string designations for special values are the following: "Quadruple.MIN_VALUE", "MIN_VALUE", "Quadruple.MAX_VALUE", "MAX_VALUE", "Quadruple.MIN_NORMAL", "MIN_NORMAL", "Quadruple.NaN", "NaN", "Quadruple.NEGATIVE_INFINITY", "NEGATIVE_INFINITY", "-INFINITY", "Quadruple.POSITIVE_INFINITy", "POSITIVE_INFINITY", "INFINITY", "+INFINITY".
    If the exact value of the number represented by the input string is greater than the nearest exact Quadruple value by less than 0.5 - 1e-17 of the least significant bit of the mantissa of the latter, it gets rounded down to the aforementioned Quadruple value.
    If it is greater by 0.5 LSB or more, it gets rounded up to the greater adjacent Quadruple value.
    In cases when difference between the input value and the nearest Quadruple value is between (0.5 - 1e-17) * LSB and 0.5 * LSB, the direction of the rounding is unpredictable.
    assignInfinity(boolean changeSign)
    Assigns the value of Infinity or -Infinity, depending on the sign of the previous value of the instance and the changeSign parameter.
    Assigns the value of Quadruple.MAX_VALUE (2^2147483647 * (2 - 2^-128) = 1.76161305168396335320749314979184028566452310e+646456993) to the instance.
    Assigns the value of Quadruple.MIN_NORMAL (2^-2147483646 = 2.27064621040149253752656726517958758124747730e-646456993) to the instance.
    Assigns the value of Quadruple.MIN_VALUE (2^-2147483774 = 6.67282948260747430814835377499134611597699952e-646457032) to the instance.
    Assigns the value of "Not a Number" (NaN) to this instance.
    Assigns the value of -Infinity to this instance.
    Assigns the value of +Infinity to this instance.
    assignWithUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo)
    Builds a Quadruple value from the given low-level parts and assigns it to the instance.
    Treats the exponent parameter as the unbiased exponent value, whose 0 value corresponds to the Quadruple value of 1.0.
    assignZero(boolean changeSign)
    Assigns the value of zero to this instance with or without inverting its sign.
    static int
    Compares the values of two instances.
    int
    Compares the magnitude (absolute value) of this instance with the magnitude of the other instance.
    int
    compareTo(double other)
    Compares the value of this instance with the specified double value.
    int
    compareTo(long other)
    Compares the value of this instance with the specified long value.
    int
    Compares the value of this instance with the value of the specified instance.
    cpy()
    Returns a copy of this Quadruple.
    divide(double divisor)
    Divides the value of this Quadruple by the value of the given double divisor.
    divide(Quadruple divisor)
    Divides the value of this Quadruple by the value of the given Quadruple divisor.
    double
    Converts the value of this Quadruple to a double value in a way similar to standard narrowing conversions (e.g., from double to float).
    boolean
    Indicates whether the other Quadruple is equal to this one.
    int
    Returns the raw (biased) value of the binary exponent of the value, i.e.
    float
    Converts the value of this Quadruple to a float value in a way similar to standard narrowing conversions (e.g., from double to float).
    static Quadruple
    from(double dValue)
    Creates a new Quadruple instance with the given double value.
    First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(double).
    static Quadruple
    from(long lValue)
    Creates a new Quadruple with the given long value.
    First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(long).
    static Quadruple
    from(String strValue)
    Creates a new Quadruple with the value represented by the given String.
    First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value.
    int
    Computes a hashcode for this Quadruple, based on the values of its fields.
    int
    Converts the value of this Quadruple to an int value in a way similar to standard narrowing conversions (e.g., from double to int).
    boolean
    Checks if the value is infinite (i.e.
    boolean
    Checks if the value is not a number (i.e.
    boolean
    Checks if the value is negative.
    boolean
    Checks if the value is zero, either positive or negative.
    long
    Converts the value of this Quadruple to a long value in a way similar to standard narrowing conversions (e.g., from double to long).
    long
    makeSubnormal(long exp2)
    For a Quadruple with a normal mantissa (with implied unity) and non-positive biased exponent, converts it into the conventional subnormal form, with the exponent = 0 and the mantissa shifted rightwards with explicit 1 in the appropriate position.
    Shifts mantissa rightwards by |exp2| + 1 bits, sets explicit 1, and rounds it up, taking into account the bits having been shifted-out
    long
    Returns the most significant 64 bits of the fractional part of the mantissa.
    long
    Returns the least significant 64 bits of the fractional part of the mantissa
    static Quadruple
    Returns a new instance of Quadruple with the value of the maximum of the values of the operands.
    static Quadruple
    Returns a new instance of Quadruple with the value of the minimum of the values of the operands.
    multiply(double factor)
    Multiplies the value of this Quadruple by the value of the given double factor.
    multiply(long factor)
    Multiplies the value of this Quadruple by the value of the given long factor.
    Multiplies the value of this Quadruple by the value of the given Quadruple factor.
    static Quadruple
    nan()
    Returns a new Quadruple instance with the value of NaN.
    Changes the sign of this Quadruple.
    static Quadruple
    one()
    Returns a new Quadruple instance with the value of 1.0.
    static Quadruple
    pi()
    Returns a new Quadruple instance with the value of the number π (pi) (3.141592653589793238462643383279502884195)
    void
    setExponent(int exponent)
     
    void
    setMantHi(long mantHi)
     
    void
    setMantLo(long mantLo)
     
    setNegative(boolean value)
    Sets the negative flag.
    int
    Returns 1 for positive values, -1 for negative values (including -0), and 0 for the positive zero value
    Computes a square root of the value of this Quadruple and replaces the old value of this instance with the newly-computed value.
    static Quadruple
    sqrt(Quadruple square)
    Computes a square root of the value of the given Quadruple, creates and returns a new instance of Quadruple containing the value of the square root.
    subtract(double subtrahend)
    Subtracts the value of the given double subtrahend from the value of this Quadruple.
    subtract(Quadruple subtrahend)
    Subtracts the value of the given Quadruple subtrahend from the value of this Quadruple.
    Returns a decimal string representation of the value of this Quadruple in a scientific (exponential) notation, rounded to 43 digits after point.
    For other String representations, see format(String)
    static Quadruple
    two()
    Returns a new Quadruple instance with the value of 2.0.
    static Quadruple
    Returns a new Quadruple instance with the value of 0.0.

    Methods inherited from class Number

    byteValue, shortValue

    Methods inherited from class Object

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

    • EXPONENT_OF_ONE

      public static final int EXPONENT_OF_ONE
      The value of the exponent (biased) corresponding to 1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF). The same as EXPONENT_BIAS
      See Also:
    • EXPONENT_BIAS

      public static final int EXPONENT_BIAS
      The value of the exponent (biased) corresponding to 1.0 == 2^0; equals to 2_147_483_647 (0x7FFF_FFFF) The same as EXPONENT_OF_ONE
      See Also:
    • EXPONENT_OF_MAX_VALUE

      public static final long EXPONENT_OF_MAX_VALUE
      The value of the exponent (biased), corresponding to MAX_VALUE; equals to 4_294_967_294L (0xFFFF_FFFEL)
      See Also:
    • EXPONENT_OF_INFINITY

      public static final int EXPONENT_OF_INFINITY
      The value of the exponent (biased), corresponding to Infinity, -Infinity, and NaN; equals to -1 (0xFFFF_FFFF)
      See Also:
  • Constructor Details

    • Quadruple

      public Quadruple()
      Creates a new instance of Quadruple with value 0.0
    • Quadruple

      public Quadruple(Quadruple qValue)
      Creates a new Quadruple instance with the value of the given Quadruple instance.
      First creates an empty (zero) instance, then copies the fields of the parameter. to the fields of the new instance
      Parameters:
      qValue - the Quadruple value to be assigned to the new instance.
    • Quadruple

      public Quadruple(double dValue)
      Creates a new Quadruple instance with the given double value.
      First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(double).
      Parameters:
      dValue - the double value to be assigned
    • Quadruple

      public Quadruple(long lValue)
      Creates a new Quadruple with the given long value.
      First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(long).
      Parameters:
      lValue - the long value to be assigned
    • Quadruple

      public Quadruple(String strValue)
      Creates a new Quadruple with the value represented by the given String.
      First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value. Some non-standard string designations for special values are admissible, see assign(String)
      Parameters:
      strValue - the String value to be assigned
      See Also:
    • Quadruple

      public Quadruple(boolean negative, int exponent, long mantHi, long mantLo)
      Creates a new Quadruple built from the given parts.
      Parameters:
      negative - the sign of the value (true signifies negative values)
      exponent - the binary exponent (unbiased)
      mantHi - the most significant 64 bits of fractional part of the mantissa
      mantLo - the least significant 64 bits of fractional part of the mantissa
    • Quadruple

      public Quadruple(int exponent, long mantHi, long mantLo)
      Creates a new Quadruple with a positive value built from the given parts.
      Parameters:
      exponent - the binary exponent (unbiased)
      mantHi - the most significant 64 bits of fractional part of the mantissa
      mantLo - the least significant 64 bits of fractional part of the mantissa
  • Method Details

    • from

      public static Quadruple from(String strValue)
      Creates a new Quadruple with the value represented by the given String.
      First creates an empty (zero) instance, then assigns the given value to the new instance, converting the string to the corresponding floating-point value. Some non-standard string designations for special values are admissible, see assign(String)
      Parameters:
      strValue - the String value to be assigned
      See Also:
    • from

      public static Quadruple from(long lValue)
      Creates a new Quadruple with the given long value.
      First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(long).
      Parameters:
      lValue - the long value to be assigned
    • from

      public static Quadruple from(double dValue)
      Creates a new Quadruple instance with the given double value.
      First creates an empty (zero) instance, then assigns the given value to the new instance, using assign(double).
      Parameters:
      dValue - the double value to be assigned
    • nan

      public static Quadruple nan()
      Returns a new Quadruple instance with the value of NaN.
      Returns:
      a new Quadruple instance with the value of NAN
    • zero

      public static Quadruple zero()
      Returns a new Quadruple instance with the value of 0.0.
      Returns:
      a new Quadruple instance with the value of 0.0
    • one

      public static Quadruple one()
      Returns a new Quadruple instance with the value of 1.0.
      Returns:
      a new Quadruple instance with the value of 1.0
    • two

      public static Quadruple two()
      Returns a new Quadruple instance with the value of 2.0.
      Returns:
      a new Quadruple instance with the value of 2.0
    • pi

      public static Quadruple pi()
      Returns a new Quadruple instance with the value of the number π (pi) (3.141592653589793238462643383279502884195)
      Returns:
      a new Quadruple instance with the value of the number π (pi)
    • exponent

      public int exponent()
      Returns the raw (biased) value of the binary exponent of the value, i.e. 0x7FFF_FFFF for values falling within the interval of [1.0 .. 2.0), 0x8000_0000 for [2.0 .. 4.0) etc.
      Returns:
      the raw (biased) value of the binary exponent of the value
    • mantHi

      public long mantHi()
      Returns the most significant 64 bits of the fractional part of the mantissa.
      Returns:
      the most significant 64 bits of the fractional part of the mantissa
    • mantLo

      public long mantLo()
      Returns the least significant 64 bits of the fractional part of the mantissa
      Returns:
      the least significant 64 bits of the fractional part of the mantissa
    • isNegative

      public boolean isNegative()
      Checks if the value is negative.
      Returns:
      true, if the value is negative, false otherwise
    • isInfinite

      public boolean isInfinite()
      Checks if the value is infinite (i.e. NEGATIVE_INFINITY or POSITIVE_INFINITY).
      Returns:
      true, if the value is infinity (either positive or negative), false otherwise
    • isNaN

      public boolean isNaN()
      Checks if the value is not a number (i.e. has the value of NaN).
      Returns:
      true, if the value is not a number (NaN), false otherwise
    • isZero

      public boolean isZero()
      Checks if the value is zero, either positive or negative.
      Returns:
      true, if the value is 0 or -0, otherwise returns
    • assign

      public Quadruple assign(Quadruple qValue)
      Assigns the given value to the instance (copies the values of the private fields of the parameter to the respective fields of this instance).
      Parameters:
      qValue - a Quadruple instance whose value is to assign
      Returns:
      this instance with the newly assigned value
    • assign

      public Quadruple assign(double value)
      Converts the given value to quadruple and assigns it to the instance.
      Expands exponent to 32 bits preserving its value, and expands mantissa to 128 bits, filling with zeroes the least significant 76 bits that absent in the double value. Subnormal double values (Double.MIN_NORMAL < v <= Double.MIN_VALUE) are converted to normal quadruple values, by shifting them leftwards and correcting the exponent accordingly.
      Parameters:
      value - the double value to be assigned.
      Returns:
      this instance with the newly assigned value
    • assign

      public Quadruple assign(long value)
      Converts the given value to quadruple and assigns it to the instance.
      To find the mantissa, shifts the bits of the absolute value of the parameter left, so that its most significant non-zero bit (that stands for the 'implicit unity' of the floating point formats) gets shifted out, then corrects the exponent depending on the shift distance and sets the sign in accordance with the initial sign of the parameter.
      Parameters:
      value - the long value to be assigned
      Returns:
      this instance with the newly assigned value
    • assign

      Parses the given String that is expected to contain floating-point value in any conventional string form or a string designation of one of special values, and assigns the corresponding value to the instance.
      Parsing is case-insensitive.
      The admittable string designations for special values are the following:
      • "Quadruple.MIN_VALUE",
      • "MIN_VALUE",
      • "Quadruple.MAX_VALUE",
      • "MAX_VALUE",
      • "Quadruple.MIN_NORMAL",
      • "MIN_NORMAL",
      • "Quadruple.NaN",
      • "NaN",
      • "Quadruple.NEGATIVE_INFINITY",
      • "NEGATIVE_INFINITY",
      • "-INFINITY",
      • "Quadruple.POSITIVE_INFINITy",
      • "POSITIVE_INFINITY",
      • "INFINITY",
      • "+INFINITY".

      If the exact value of the number represented by the input string is greater than the nearest exact Quadruple value by less than 0.5 - 1e-17 of the least significant bit of the mantissa of the latter, it gets rounded down to the aforementioned Quadruple value.
      If it is greater by 0.5 LSB or more, it gets rounded up to the greater adjacent Quadruple value.
      In cases when difference between the input value and the nearest Quadruple value is between (0.5 - 1e-17) * LSB and 0.5 * LSB, the direction of the rounding is unpredictable.

      Expressing it via formulas,

      (1 + (n + d) * 2^-128) * 2^e ==> (1 + n * 2^-128) * 2^e, if d <= 0.5 - 1e-17;
      (1 + (n + d) * 2^-128) * 2^e ==> (1 + (n + 1) * 2^-128) * 2^e, if d => 0.5.
      where n is an integer less than 2^128, e is the exponent of the Quadruple.

      For example, 1.5 + 0.5 * 2^-128, that equals
      1.500000000000000000000000000000000000001469367938527859384960921...
      gets rounded up to
      1.5000000000000000000000000000000000000029387, whose mantissa is 0x8000_..._0001,
      while 1.5 + (0.5 - 1e-17) * 2^-128, that equals to
      1.500000000000000000000000000000000000001469367938527859355573561...
      gets rounded down to 1.5, whose mantissa is 0x8000_..._0000.
      The values between the two may get rounded either up or down.
      Parameters:
      source - the String to be parsed
      Returns:
      this instance with the newly assigned value
      Throws:
      NullPointerException - if the input string is null
      NumberFormatException - if the input string does not contain valid value
    • assignWithUnbiasedExponent

      public Quadruple assignWithUnbiasedExponent(boolean negative, int exponent, long mantHi, long mantLo)
      Builds a Quadruple value from the given low-level parts and assigns it to the instance.
      Treats the exponent parameter as the unbiased exponent value, whose 0 value corresponds to the Quadruple value of 1.0.
      Parameters:
      negative - the sign of the value (true for negative)
      exponent - Binary exponent (unbiased, 0 means 2^0)
      mantHi - The higher 64 bits of the fractional part of the mantissa
      mantLo - The lower 64 bits of the fractional part of the mantissa
      Returns:
      A Quadruple containing the value built of the given parts
    • assignPositiveInfinity

      public Quadruple assignPositiveInfinity()
      Assigns the value of +Infinity to this instance.
      Returns:
      this instance with the value of POSITIVE_INFINITY
    • assignNegativeInfinity

      public Quadruple assignNegativeInfinity()
      Assigns the value of -Infinity to this instance.
      Returns:
      this instance with the value of NEGATIVE_INFINITY
    • assignNaN

      public Quadruple assignNaN()
      Assigns the value of "Not a Number" (NaN) to this instance.
      Returns:
      this instance with the value of NaN
    • intValue

      public int intValue()
      Converts the value of this Quadruple to an int value in a way similar to standard narrowing conversions (e.g., from double to int).
      Specified by:
      intValue in class Number
      Returns:
      the value of this Quadruple instance converted to an int.
    • longValue

      public long longValue()
      Converts the value of this Quadruple to a long value in a way similar to standard narrowing conversions (e.g., from double to long).
      Specified by:
      longValue in class Number
      Returns:
      the value of this Quadruple instance converted to a long.
    • floatValue

      public float floatValue()
      Converts the value of this Quadruple to a float value in a way similar to standard narrowing conversions (e.g., from double to float).
      Specified by:
      floatValue in class Number
      Returns:
      the value of this Quadruple instance converted to a float.
    • doubleValue

      public double doubleValue()
      Converts the value of this Quadruple to a double value in a way similar to standard narrowing conversions (e.g., from double to float). Uses 'half-even' approach to the rounding, like BigDecimal.doubleValue()
      Specified by:
      doubleValue in class Number
      Returns:
      the value of this Quadruple instance converted to a double.
    • toString

      public String toString()
      Returns a decimal string representation of the value of this Quadruple in a scientific (exponential) notation, rounded to 43 digits after point.
      For other String representations, see format(String)
      Overrides:
      toString in class Object
      See Also:
    • compareTo

      public int compareTo(Quadruple other)
      Compares the value of this instance with the value of the specified instance.
      Specified by:
      compareTo in interface Comparable<Quadruple>
      Parameters:
      other - the Quadruple to compare with
      Returns:
      a negative integer, zero, or a positive integer as the value of this instance is less than, equal to, or greater than the value of the specified instance.
    • compareTo

      public int compareTo(long other)
      Compares the value of this instance with the specified long value. The value of the argument is converted to Quadruple, and then two Quadruple values are compared by compareTo(Quadruple)
      Parameters:
      other - the long value to compare with
      Returns:
      a negative integer, zero, or a positive integer as the value of this instance is less than, equal to, or greater than the specified long value.
    • compareTo

      public int compareTo(double other)
      Compares the value of this instance with the specified double value. The value of the argument is converted to Quadruple, and then two Quadruple values are compared by compareTo(Quadruple)
      Parameters:
      other - the double value to compare with
      Returns:
      a negative integer, zero, or a positive integer as the value of this instance is less than, equal to, or greater than the specified double value.
    • equals

      public boolean equals(Object obj)
      Indicates whether the other Quadruple is equal to this one.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with
      Returns:
      true if the given object is Quadruple and its value is equal to the value of this Quadruple instance, false otherwise.
    • hashCode

      public int hashCode()
      Computes a hashcode for this Quadruple, based on the values of its fields.
      Overrides:
      hashCode in class Object
      See Also:
    • compare

      public static int compare(Quadruple q1, Quadruple q2)
      Compares the values of two instances.
      Parameters:
      q1 - the instance to compare with the other one
      q2 - the instance to compare with
      Returns:
      a negative integer, zero, or a positive integer as the value of the first instance is less than, equal to, or greater than the value of the second instance.
    • compareMagnitudeTo

      public int compareMagnitudeTo(Quadruple other)
      Compares the magnitude (absolute value) of this instance with the magnitude of the other instance.
      Parameters:
      other - the Quadruple to compare with
      Returns:
      1 if this instance is greater in magnitude than the other instance, 0 if the argument is equal in magnitude to this instance, -1 if this instance is less in magnitude, than the argument
    • max

      public static Quadruple max(Quadruple q1, Quadruple q2)
      Returns a new instance of Quadruple with the value of the maximum of the values of the operands.
      Parameters:
      q1 - first operand to compare
      q2 - first operand to compare
      Returns:
      a new instance of Quadruple whose value is equal to the value of the greater of the operands.
    • min

      public static Quadruple min(Quadruple q1, Quadruple q2)
      Returns a new instance of Quadruple with the value of the minimum of the values of the operands.
      Parameters:
      q1 - first operand to compare
      q2 - first operand to compare
      Returns:
      a new instance of Quadruple whose value is equal to the value of the lesser of the operands.
    • add

      public Quadruple add(Quadruple summand)
      Adds the value of the given Quadruple summand to the value of this Quadruple. The instance acquires a new value that equals the sum of the previous value and the value of the summand.
      Parameters:
      summand - the value to add
      Returns:
      the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
    • add

      public Quadruple add(long summand)
      Adds the value of the given long summand to the value of this Quadruple. The value of the long operand is preliminarily converted to a Quadruple value. The instance acquires the new value that equals the sum of the previous value and the value of the summand.
      Parameters:
      summand - the value to add
      Returns:
      the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
    • add

      public Quadruple add(double summand)
      Adds the value of the given double summand to the value of this Quadruple. The value of the double operand is preliminarily converted to a Quadruple value. The instance acquires the new value that equals the sum of the previous value and the value of the summand.
      Parameters:
      summand - the value to add
      Returns:
      the reference to this object, which holds a new value that equals the sum of its previous value and the value of the summand
    • add

      public static Quadruple add(Quadruple op1, Quadruple op2)
      Adds the value of the given Quadruple op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum. The operands remain unchanged.
      Parameters:
      op1 - the first operand to add
      op2 - the second operand to add
      Returns:
      a new instance of Quadruple containing the sum of the operands
    • add

      public static Quadruple add(Quadruple op1, long op2)
      Adds the value of the given long op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum. The value of the long operand is preliminarily converted to a Quadruple value. The Quadruple operand remains unchanged.
      Parameters:
      op1 - the first operand to add
      op2 - the second operand to add
      Returns:
      a new instance of Quadruple containing the sum of the operands
    • add

      public static Quadruple add(Quadruple op1, double op2)
      Adds the value of the given double op2 to the value of Quadruple op1 and creates a new instance of Quadruple containing the sum. The value of the double operand is preliminarily converted to a Quadruple value. The Quadruple operand remains unchanged.
      Parameters:
      op1 - the first operand to add
      op2 - the second operand to add
      Returns:
      a new instance of Quadruple containing the sum of the operands
    • subtract

      public Quadruple subtract(Quadruple subtrahend)
      Subtracts the value of the given Quadruple subtrahend from the value of this Quadruple. The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.
      Parameters:
      subtrahend - the value to be subtracted from the current value of this Quadruple
      Returns:
      the reference to this object, which holds a new value that equals the difference between its previous value and the value of the subtrahend
    • subtract

      public Quadruple subtract(double subtrahend)
      Subtracts the value of the given double subtrahend from the value of this Quadruple. The value of the double subtrahend is preliminarily converted to a Quadruple value. The instance acquires a new value that equals the difference between the previous value and the value of the subtrahend.
      Parameters:
      subtrahend - the value to be subtracted from the current value of this Quadruple
      Returns:
      the reference to this object, which holds a new value that equals the difference between its previous value and the value of the subtrahend
    • multiply

      public Quadruple multiply(Quadruple factor)
      Multiplies the value of this Quadruple by the value of the given Quadruple factor. The instance acquires a new value that equals the product of the previous value and the value of the factor.
      Parameters:
      factor - the value to multiply the current value of this Quadruple by.
      Returns:
      the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
    • multiply

      public Quadruple multiply(long factor)
      Multiplies the value of this Quadruple by the value of the given long factor. The value of the long factor is preliminarily converted to a Quadruple value. The instance acquires a new value that equals the product of the previous value and the value of the factor.
      Parameters:
      factor - the value to multiply the current value of this Quadruple by.
      Returns:
      the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
    • multiply

      public Quadruple multiply(double factor)
      Multiplies the value of this Quadruple by the value of the given double factor. The value of the double factor is preliminarily converted to a Quadruple value. The instance acquires a new value that equals the product of the previous value and the value of the factor.
      Parameters:
      factor - the value to multiply the current value of this Quadruple by.
      Returns:
      the reference to this object, which holds a new value that equals the product of its previous value and the value of the factor
    • divide

      public Quadruple divide(Quadruple divisor)
      Divides the value of this Quadruple by the value of the given Quadruple divisor. The instance acquires a new value that equals the quotient.
      Parameters:
      divisor - the divisor to divide the current value of this Quadruple by
      Returns:
      the reference to this object, which holds a new value that equals the quotient of the previous value of this Quadruple divided by the given divisor
    • divide

      public Quadruple divide(double divisor)
      Divides the value of this Quadruple by the value of the given double divisor. The instance acquires a new value that equals the quotient. The value of the double divisor is preliminarily converted to a Quadruple value.
      Parameters:
      divisor - the divisor to divide the current value of this Quadruple by
      Returns:
      the reference to this object, which holds a new value that equals the quotient of the previous value of this Quadruple divided by the given divisor
    • sqrt

      public Quadruple sqrt()
      Computes a square root of the value of this Quadruple and replaces the old value of this instance with the newly-computed value.
      Returns:
      the reference to this instance, which holds a new value that equals to the square root of its previous value
    • sqrt

      public static Quadruple sqrt(Quadruple square)
      Computes a square root of the value of the given Quadruple, creates and returns a new instance of Quadruple containing the value of the square root. The parameter remains unchanged.
      Parameters:
      square - the value to find the square root of
      Returns:
      a new instance of Quadruple containing the value of the square root of the given argument
    • setNegative

      public Quadruple setNegative(boolean value)
      Sets the negative flag.
    • setExponent

      public void setExponent(int exponent)
    • setMantHi

      public void setMantHi(long mantHi)
    • setMantLo

      public void setMantLo(long mantLo)
    • negate

      public Quadruple negate()
      Changes the sign of this Quadruple.
      Returns:
      the reference to this object, which holds a new value that equals the previous value in magnitude, but with opposite sign
    • cpy

      public Quadruple cpy()
      Returns a copy of this Quadruple.
      Returns:
      A new instance of Quadruple with the same value as this
    • abs

      public Quadruple abs()
      Returns a new instance of Quadruple with the value of the absolute value of this instance
      Returns:
      a new instance of Quadruple with the value of the absolute value of this instance
    • signum

      public int signum()
      Returns 1 for positive values, -1 for negative values (including -0), and 0 for the positive zero value
      Returns:
      1 for positive values, -1 for negative values (including -0), and 0 for the positive zero value
    • makeSubnormal

      public long makeSubnormal(long exp2)
      For a Quadruple with a normal mantissa (with implied unity) and non-positive biased exponent, converts it into the conventional subnormal form, with the exponent = 0 and the mantissa shifted rightwards with explicit 1 in the appropriate position.
      Shifts mantissa rightwards by |exp2| + 1 bits, sets explicit 1, and rounds it up, taking into account the bits having been shifted-out
      Parameters:
      exp2 - the exponent of the newly-found subnormal value (always negative)
      Returns:
      the exponent for the new value, 0 in an ordinary case, an 1 if the rounding has led to overflow of the mantissa
    • assignMinNormal

      public Quadruple assignMinNormal()
      Assigns the value of Quadruple.MIN_NORMAL (2^-2147483646 = 2.27064621040149253752656726517958758124747730e-646456993) to the instance.
      Returns:
      this instance with the new value
    • assignMaxValue

      public Quadruple assignMaxValue()
      Assigns the value of Quadruple.MAX_VALUE (2^2147483647 * (2 - 2^-128) = 1.76161305168396335320749314979184028566452310e+646456993) to the instance.
      Returns:
      this instance with the new value
    • assignMinValue

      public Quadruple assignMinValue()
      Assigns the value of Quadruple.MIN_VALUE (2^-2147483774 = 6.67282948260747430814835377499134611597699952e-646457032) to the instance.
      Returns:
      this instance with the new value.
    • assignZero

      public Quadruple assignZero(boolean changeSign)
      Assigns the value of zero to this instance with or without inverting its sign.
      Parameters:
      changeSign - if true, the instance will change its sign, if false, the sign is not changed.
      Returns:
      this instance with the new value (+0 or -0)
    • assignInfinity

      public Quadruple assignInfinity(boolean changeSign)
      Assigns the value of Infinity or -Infinity, depending on the sign of the previous value of the instance and the changeSign parameter.
      Parameters:
      changeSign - if true, the instance will change its sign, if false, the sign is not changed.
      Returns:
      this instance with the new value (Infinity or -Infinity)