DD class

Implements extended-precision floating-point numbers which maintain 106 bits (approximately 30 decimal digits) of precision.

A DoubleDouble uses a representation containing two double-precision values. A number x is represented as a pair of doubles, x.hi and x.lo, such that the number represented by x is x.hi + x.lo, where

   |x.lo| <= 0.5*ulp(x.hi)
and ulp(y) means "unit in the last place of y". The basic arithmetic operations are implemented using convenient properties of IEEE-754 floating-point arithmetic.

The range of values which can be represented is the same as in IEEE-754. The precision of the representable numbers is twice as great as IEEE-754 double precision.

The correctness of the arithmetic algorithms relies on operations being performed with standard IEEE-754 double precision and rounding. This is the Java standard arithmetic model, but for performance reasons Java implementations are not constrained to using this standard by default. Some processors (notably the Intel Pentium architecture) perform floating point operations in (non-IEEE-754-standard) extended-precision. A JVM implementation may choose to use the non-standard extended-precision as its default arithmetic mode. To prevent this from happening, this code uses the Java strictfp modifier, which forces all operations to take place in the standard IEEE-754 rounding model.

The API provides both a set of value-oriented operations and a set of mutating operations. Value-oriented operations treat DoubleDouble values as immutable; operations on them return new objects carrying the result of the operation. This provides a simple and safe semantics for writing DoubleDouble expressions. However, there is a performance penalty for the object allocations required. The mutable interface updates object values in-place. It provides optimum memory performance, but requires care to ensure that aliasing errors are not created and constant values are not changed.

For example, the following code example constructs three DD instances: two to hold the input values and one to hold the result of the addition.

    DD a = new DD(2.0);
    DD b = new DD(3.0);
    DD c = a.add(b);
In contrast, the following approach uses only one object:
    DD a = new DD(2.0);
    a.selfAdd(3.0);

This implementation uses algorithms originally designed variously by Knuth, Kahan, Dekker, and Linnainmaa. Douglas Priest developed the first C implementation of these techniques. Other more recent C++ implementation are due to Keith M. Briggs and David Bailey et al.

References

  • Priest, D., Algorithms for Arbitrary Precision Floating Point Arithmetic, in P. Kornerup and D. Matula, Eds., Proc. 10th Symposium on Computer Arithmetic, IEEE Computer Society Press, Los Alamitos, Calif., 1991.
  • Yozo Hida, Xiaoye S. Li and David H. Bailey, Quad-Double Arithmetic: Algorithms, Implementation, and Application, manuscript, Oct 2000; Lawrence Berkeley National Laboratory Report BNL-46996.
  • David Bailey, High Precision Software Directory; http://crd.lbl.gov/~dhbailey/mpdist/index.html

@author Martin Davis

Implemented types

Constructors

DD(double x)
Creates a new DoubleDouble with value x.
DD.empty()
Creates a new DoubleDouble with value 0.0.
DD.fromDD(DD dd)
Creates a new DoubleDouble with value equal to the argument.
DD.withHiLo(double hi, double lo)
Creates a new DoubleDouble with value (hi, lo).
DD.withString(String str)
Creates a new DoubleDouble with value equal to the argument.

Properties

hashCode int
The hash code for this object.
no setterinherited
hi double
The high-order component of the double-double precision value.
getter/setter pair
lo double
The low-order component of the double-double precision value.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() DD
Returns the absolute value of this value. Special cases:
add(double y) DD
Returns a new DoubleDouble whose value is (this + y).
addDD(DD y) DD
Returns a new DoubleDouble whose value is (this + y).
ceil() DD
Returns the smallest (closest to negative infinity) value that is not less than the argument and is equal to a mathematical integer. Special cases:
compareTo(dynamic o) int
Compares two DoubleDouble objects numerically.
override
divide(double y) DD
Computes a new DoubleDouble whose value is (this / y).
divideDD(DD y) DD
Computes a new DoubleDouble whose value is (this / y).
doubleValue() double
Converts this value to the nearest double-precision number.
dump() String
Dumps the components of this number to a string.
equals(DD y) bool
Tests whether this value is equal to another DoubleDouble value.
extractSignificantDigits(bool insertDecimalPoint, List<int> magnitudeList) String
Extracts the significant digits in the decimal representation of the argument. A decimal point may be optionally inserted in the string of digits (as long as its position lies within the extracted digits
floor() DD
Returns the largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer. Special cases:
ge(DD y) bool
Tests whether this value is greater than or equals to another DoubleDouble value. @param y a DoubleDouble value @return true if this value >= y
getSpecialNumberString() String?
Returns the string for this value if it has a known representation. (E.g. NaN or 0.0)
gt(DD y) bool
Tests whether this value is greater than another DoubleDouble value. @param y a DoubleDouble value @return true if this value > y
init(double x) → void
** / should never reach here
initFromDD(DD dd) → void
iniWithHiLo(double hi, double lo) → void
intValue() int
Converts this value to the nearest integer.
isNaN() bool
Tests whether this value is NaN.
isNegative() bool
Tests whether this value is less than 0.
isPositive() bool
Tests whether this value is greater than 0.
isZero() bool
Tests whether this value is equal to 0.
le(DD y) bool
Tests whether this value is less than or equal to another DoubleDouble value. @param y a DoubleDouble value @return true if this value <= y
lt(DD y) bool
Tests whether this value is less than another DoubleDouble value. @param y a DoubleDouble value @return true if this value < y
max(DD x) DD
Computes the maximum of this and another DD number.
min(DD x) DD
Computes the minimum of this and another DD number.
multiply(double y) DD
Returns a new DoubleDouble whose value is (this * y).
multiplyDD(DD y) DD
Returns a new DoubleDouble whose value is (this * y).
negate() DD
Returns a new DoubleDouble whose value is -this.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(int exp) DD
Computes the value of this number raised to an integral power. Follows semantics of Java Math.pow as closely as possible.
reciprocal() DD
Returns a DoubleDouble whose value is 1 / this.
rint() DD
Rounds this value to the nearest integer. The value is rounded to an integer by adding 1/2 and taking the floor of the result. Special cases:
selfAdd(double y) DD
Adds the argument to the value of this. To prevent altering constants, this method must only be used on values known to be newly created.
selfAddDD(DD y) DD
Adds the argument to the value of this. To prevent altering constants, this method must only be used on values known to be newly created.
selfAddHiLo(double yhi, double ylo) DD
selfDivide(double y) DD
Divides this object by the argument, returning this. To prevent altering constants, this method must only be used on values known to be newly created.
selfDivideDD(DD y) DD
Divides this object by the argument, returning this. To prevent altering constants, this method must only be used on values known to be newly created.
selfDivideHiLo(double yhi, double ylo) DD
selfMultiply(double y) DD
Multiplies this object by the argument, returning this. To prevent altering constants, this method must only be used on values known to be newly created.
selfMultiplyDD(DD y) DD
Multiplies this object by the argument, returning this. To prevent altering constants, this method must only be used on values known to be newly created.
selfMultiplyHiLo(double yhi, double ylo) DD
selfSqr() DD
Squares this object. To prevent altering constants, this method must only be used on values known to be newly created.
selfSubtract(double y) DD
Subtracts the argument from the value of this. To prevent altering constants, this method must only be used on values known to be newly created.
selfSubtractDD(DD y) DD
Subtracts the argument from the value of this. To prevent altering constants, this method must only be used on values known to be newly created.
setValue(double value) DD
Set the value for the DD object. This method supports the mutating operations concept described in the class documentation (see above). @param value a floating point value to be stored in the instance. @return a self-reference to the DD instance.
setValueDD(DD value) DD
Set the value for the DD object. This method supports the mutating operations concept described in the class documentation (see above). @param value a DD instance supplying an extended-precision value. @return a self-reference to the DD instance.
signum() int
Returns an integer indicating the sign of this value.
sqr() DD
Computes the square of this value.
sqrt() DD
Computes the positive square root of this value. If the number is NaN or negative, NaN is returned.
subtract(double y) DD
Computes a new DoubleDouble object whose value is (this - y).
subtractDD(DD y) DD
Computes a new DoubleDouble object whose value is (this - y).
toSciNotation() String
Returns the string representation of this value in scientific notation.
toStandardNotation() String
Returns the string representation of this value in standard notation.
toString() String
Returns a string representation of this number, in either standard or scientific notation. If the magnitude of the number is in the range 10<sup>-3</sup>, 10<sup>8</sup> standard notation will be used. Otherwise, scientific notation will be used.
override
trunc() DD
Returns the integer which is largest in absolute value and not further from zero than this value. Special cases:

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

E DD
The value nearest to the constant e (the natural logarithm base).
final
EPS double
The smallest representable relative difference between two {link @ DoubleDouble} values
final
MAX_PRINT_DIGITS int
final
NaN DD
A value representing the result of an operation which does not return a valid number.
final
ONE DD
final
PI DD
The value nearest to the constant Pi.
final
PI_2 DD
The value nearest to the constant Pi / 2.
final
SCI_NOT_EXPONENT_CHAR String
final
SCI_NOT_ZERO String
final
SPLIT double
The value to split a double-precision value on during multiplication
final
TEN DD
final
TWO_PI DD
The value nearest to the constant 2 * Pi.
final

Static Methods

copy(DD dd) DD
Creates a new DoubleDouble with the value of the argument.
createNaN() DD
determinant(double x1, double y1, double x2, double y2) DD
Computes the determinant of the 2x2 matrix with the given entries.
determinantDD(DD x1, DD y1, DD x2, DD y2) DD
Computes the determinant of the 2x2 matrix with the given entries.
magnitude(double x) int
Determines the decimal magnitude of a number. The magnitude is the exponent of the greatest power of 10 which is less than or equal to the number.
parse(String str) DD
Converts a string representation of a real number into a DoubleDouble value. The format accepted is similar to the standard Java real number syntax. It is defined by the following regular expression:
sqrDouble(double x) DD
Computes the square of this value.
sqrtDouble(double x) DD
stringOfChar(String ch, int len) String
Creates a string of a given length containing the given character
valueOf(double x) DD
Converts the double argument to a DoubleDouble number.
valueOfStr(String str) DD
Converts the string argument to a DoubleDouble number.