HE_Mesh2014  2.0.11
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
wblut.math.WB_DoubleDouble Class Reference
+ Inheritance diagram for wblut.math.WB_DoubleDouble:

Public Member Functions

 WB_DoubleDouble ()
 
 WB_DoubleDouble (final double x)
 
 WB_DoubleDouble (final double hi, final double lo)
 
 WB_DoubleDouble (final WB_DoubleDouble dd)
 
 WB_DoubleDouble (final String str) throws NumberFormatException
 
Object clone ()
 
WB_DoubleDouble add (final WB_DoubleDouble y)
 
WB_DoubleDouble add (final double y)
 
WB_DoubleDouble selfAdd (final WB_DoubleDouble y)
 
WB_DoubleDouble selfAdd (final double y)
 
WB_DoubleDouble subtract (final WB_DoubleDouble y)
 
WB_DoubleDouble subtract (final double y)
 
WB_DoubleDouble selfSubtract (final WB_DoubleDouble y)
 
WB_DoubleDouble selfSubtract (final double y)
 
WB_DoubleDouble negate ()
 
WB_DoubleDouble multiply (final WB_DoubleDouble y)
 
WB_DoubleDouble multiply (final double y)
 
WB_DoubleDouble selfMultiply (final WB_DoubleDouble y)
 
WB_DoubleDouble selfMultiply (final double y)
 
WB_DoubleDouble divide (final WB_DoubleDouble y)
 
WB_DoubleDouble divide (final double y)
 
WB_DoubleDouble selfDivide (final WB_DoubleDouble y)
 
WB_DoubleDouble selfDivide (final double y)
 
WB_DoubleDouble reciprocal ()
 
WB_DoubleDouble floor ()
 
WB_DoubleDouble ceil ()
 
int signum ()
 
WB_DoubleDouble rint ()
 
WB_DoubleDouble trunc ()
 
WB_DoubleDouble abs ()
 
WB_DoubleDouble sqr ()
 
WB_DoubleDouble sqrt ()
 
WB_DoubleDouble pow (final int exp)
 
double doubleValue ()
 
int intValue ()
 
boolean isZero ()
 
boolean isNegative ()
 
boolean isPositive ()
 
boolean isNaN ()
 
boolean equals (final WB_DoubleDouble y)
 
boolean gt (final WB_DoubleDouble y)
 
boolean ge (final WB_DoubleDouble y)
 
boolean lt (final WB_DoubleDouble y)
 
boolean le (final WB_DoubleDouble y)
 
int compareTo (final Object o)
 
String dump ()
 
String toString ()
 
String toStandardNotation ()
 
String toSciNotation ()
 

Static Public Member Functions

static WB_DoubleDouble valueOf (final String str) throws NumberFormatException
 
static WB_DoubleDouble valueOf (final double x)
 
static WB_DoubleDouble copy (final WB_DoubleDouble dd)
 
static WB_DoubleDouble sqr (final double x)
 
static WB_DoubleDouble sqrt (final double x)
 
static WB_DoubleDouble parse (final String str) throws NumberFormatException
 

Static Public Attributes

static final WB_DoubleDouble PI
 
static final WB_DoubleDouble TWO_PI
 
static final WB_DoubleDouble PI_2
 
static final WB_DoubleDouble E
 
static final WB_DoubleDouble NaN
 
static final double EPS = 1.23259516440783e-32
 
static final WB_DoubleDouble ZERO = new WB_DoubleDouble(0.0, 0.0)
 

Private Member Functions

void init (final double x)
 
void init (final double hi, final double lo)
 
void init (final WB_DoubleDouble dd)
 
WB_DoubleDouble selfAdd (final double yhi, final double ylo)
 
WB_DoubleDouble selfMultiply (final double yhi, final double ylo)
 
WB_DoubleDouble selfDivide (final double yhi, final double ylo)
 
String extractSignificantDigits (final boolean insertDecimalPoint, final int[] magnitude)
 
String getSpecialNumberString ()
 

Static Private Member Functions

static WB_DoubleDouble createNaN ()
 
static String stringOfChar (final char ch, final int len)
 
static int magnitude (final double x)
 

Private Attributes

double hi = 0.0
 
double lo = 0.0
 

Static Private Attributes

static final long serialVersionUID = -2751466014056438637L
 
static final double SPLIT = 134217729.0D
 
static final int MAX_PRINT_DIGITS = 32
 
static final WB_DoubleDouble TEN = WB_DoubleDouble.valueOf(10.0)
 
static final WB_DoubleDouble ONE = WB_DoubleDouble.valueOf(1.0)
 
static final String SCI_NOT_EXPONENT_CHAR = "E"
 
static final String SCI_NOT_ZERO = "0.0E0"
 

Detailed Description

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

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.

Author
Martin Davis

Constructor & Destructor Documentation

wblut.math.WB_DoubleDouble.WB_DoubleDouble ( )

Creates a new DoubleDouble with value 0.0.

wblut.math.WB_DoubleDouble.WB_DoubleDouble ( final double  x)

Creates a new DoubleDouble with value x.

Parameters
xthe value to initialize
wblut.math.WB_DoubleDouble.WB_DoubleDouble ( final double  hi,
final double  lo 
)

Creates a new DoubleDouble with value (hi, lo).

Parameters
hithe high-order component
lothe high-order component
wblut.math.WB_DoubleDouble.WB_DoubleDouble ( final WB_DoubleDouble  dd)

Creates a new DoubleDouble with value equal to the argument.

Parameters
ddthe value to initialize
wblut.math.WB_DoubleDouble.WB_DoubleDouble ( final String  str) throws NumberFormatException

Creates a new DoubleDouble with value equal to the argument.

Parameters
strthe value to initialize by
Exceptions
NumberFormatExceptionif str is not a valid representation of a number

Member Function Documentation

WB_DoubleDouble wblut.math.WB_DoubleDouble.abs ( )

Returns the absolute value of this value. Special cases:

  • If this value is NaN, it is returned.
Returns
the absolute value of this value
WB_DoubleDouble wblut.math.WB_DoubleDouble.add ( final WB_DoubleDouble  y)

Returns a DoubleDouble whose value is (this + y).

Parameters
ythe addend
Returns
(this + y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.add ( final double  y)

Returns a DoubleDouble whose value is (this + y).

Parameters
ythe addend
Returns
(this + y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.ceil ( )

Returns the smallest (closest to negative infinity) value that is not less than the argument and is equal to a mathematical integer. Special cases:

  • If this value is NaN, returns NaN.
Returns
the smallest (closest to negative infinity) value that is not less than the argument and is equal to a mathematical integer.
Object wblut.math.WB_DoubleDouble.clone ( )

Creates and returns a copy of this value.

Returns
a copy of this value
int wblut.math.WB_DoubleDouble.compareTo ( final Object  o)

Compares two DoubleDouble objects numerically.

Parameters
othe o
Returns
-1,0 or 1 depending on whether this value is less than, equal to or greater than the value of o
static WB_DoubleDouble wblut.math.WB_DoubleDouble.copy ( final WB_DoubleDouble  dd)
static

Creates a new DoubleDouble with the value of the argument.

Parameters
ddthe DoubleDouble value to copy
Returns
a copy of the input value
static WB_DoubleDouble wblut.math.WB_DoubleDouble.createNaN ( )
staticprivate

Creates the na n.

Returns
the w b_ double double
WB_DoubleDouble wblut.math.WB_DoubleDouble.divide ( final WB_DoubleDouble  y)

Computes a new DoubleDouble whose value is (this / y).

Parameters
ythe divisor
Returns
a new object with the value (this / y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.divide ( final double  y)

Computes a new DoubleDouble whose value is (this / y).

Parameters
ythe divisor
Returns
a new object with the value (this / y)
double wblut.math.WB_DoubleDouble.doubleValue ( )

Converts this value to the nearest double-precision number.

Returns
the nearest double-precision number to this value
String wblut.math.WB_DoubleDouble.dump ( )

Dumps the components of this number to a string.

Returns
a string showing the components of the number
boolean wblut.math.WB_DoubleDouble.equals ( final WB_DoubleDouble  y)

Tests whether this value is equal to another DoubleDouble value.

Parameters
ya DoubleDouble value
Returns
true if this value = y
String wblut.math.WB_DoubleDouble.extractSignificantDigits ( final boolean  insertDecimalPoint,
final int[]  magnitude 
)
private

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 - if not, the caller must prepend or append the appropriate zeroes and decimal point).

Parameters
insertDecimalPointthe insert decimal point
magnitudethe magnitude
Returns
the string containing the significant digits and possibly a decimal point

This should never happen, due to heuristic checks on remainder below

If a negative remainder is encountered, simply terminate the extraction. This is robust, but maybe slightly inaccurate. My current hypothesis is that negative remainders only occur for very small lo components, so the inaccuracy is tolerable

Heuristic check: if the remaining portion of y is non-positive, assume that output is complete

Check if remaining digits will be 0, and if so don't output them. Do this by comparing the magnitude of the remainder with the expected precision.

WB_DoubleDouble wblut.math.WB_DoubleDouble.floor ( )

Returns the largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer. Special cases:

  • If this value is NaN, returns NaN.
Returns
the largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer.
boolean wblut.math.WB_DoubleDouble.ge ( final WB_DoubleDouble  y)

Tests whether this value is greater than or equals to another DoubleDouble value.

Parameters
ya DoubleDouble value
Returns
true if this value >= y
String wblut.math.WB_DoubleDouble.getSpecialNumberString ( )
private

Returns the string for this value if it has a known representation. (E.g. NaN or 0.0)

Returns
the string for this special number null if the number is not a special number
boolean wblut.math.WB_DoubleDouble.gt ( final WB_DoubleDouble  y)

Tests whether this value is greater than another DoubleDouble value.

Parameters
ya DoubleDouble value
Returns
true if this value > y
void wblut.math.WB_DoubleDouble.init ( final double  x)
private

Inits the.

Parameters
xthe x
void wblut.math.WB_DoubleDouble.init ( final double  hi,
final double  lo 
)
private

Inits the.

Parameters
hithe hi
lothe lo
void wblut.math.WB_DoubleDouble.init ( final WB_DoubleDouble  dd)
private

Inits the.

Parameters
ddthe dd
int wblut.math.WB_DoubleDouble.intValue ( )

Converts this value to the nearest integer.

Returns
the nearest integer to this value
boolean wblut.math.WB_DoubleDouble.isNaN ( )

Tests whether this value is NaN.

Returns
true if this value is NaN
boolean wblut.math.WB_DoubleDouble.isNegative ( )

Tests whether this value is less than 0.

Returns
true if this value is less than 0
boolean wblut.math.WB_DoubleDouble.isPositive ( )

Tests whether this value is greater than 0.

Returns
true if this value is greater than 0
boolean wblut.math.WB_DoubleDouble.isZero ( )

Tests whether this value is equal to 0.

Returns
true if this value is equal to 0
boolean wblut.math.WB_DoubleDouble.le ( final WB_DoubleDouble  y)

Tests whether this value is less than or equal to another DoubleDouble value.

Parameters
ya DoubleDouble value
Returns
true if this value <= y
boolean wblut.math.WB_DoubleDouble.lt ( final WB_DoubleDouble  y)

Tests whether this value is less than another DoubleDouble value.

Parameters
ya DoubleDouble value
Returns
true if this value < y
static int wblut.math.WB_DoubleDouble.magnitude ( final double  x)
staticprivate

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.

Parameters
xthe number to find the magnitude of
Returns
the decimal magnitude of x

Since log computation is inexact, there may be an off-by-one error in the computed magnitude. Following tests that magnitude is correct, and adjusts it if not

WB_DoubleDouble wblut.math.WB_DoubleDouble.multiply ( final WB_DoubleDouble  y)

Returns a new DoubleDouble whose value is (this * y).

Parameters
ythe multiplicand
Returns
(this * y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.multiply ( final double  y)

Returns a new DoubleDouble whose value is (this * y).

Parameters
ythe multiplicand
Returns
(this * y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.negate ( )

Returns a DoubleDouble whose value is -this.

Returns
-this
static WB_DoubleDouble wblut.math.WB_DoubleDouble.parse ( final String  str) throws NumberFormatException
static

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:

[+|-] {digit} [ . {digit} ] [ ( e | E ) [+|-
] {digit}+
Parameters
strthe string to parse
Returns
the value of the parsed number
Exceptions
NumberFormatExceptionif str is not a valid representation of a number
WB_DoubleDouble wblut.math.WB_DoubleDouble.pow ( final int  exp)

Computes the value of this number raised to an integral power. Follows semantics of Java Math.pow as closely as possible.

Parameters
expthe integer exponent
Returns
x raised to the integral power exp
WB_DoubleDouble wblut.math.WB_DoubleDouble.reciprocal ( )

Returns a DoubleDouble whose value is 1 / this.

Returns
the reciprocal of this value
WB_DoubleDouble wblut.math.WB_DoubleDouble.rint ( )

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:

  • If this value is NaN, returns NaN.
Returns
this value rounded to the nearest integer
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfAdd ( final WB_DoubleDouble  y)

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.

Parameters
ythe addend
Returns
this object, increased by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfAdd ( final double  y)

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.

Parameters
ythe addend
Returns
this object, increased by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfAdd ( final double  yhi,
final double  ylo 
)
private

Self add.

Parameters
yhithe yhi
ylothe ylo
Returns
the w b_ double double
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfDivide ( final WB_DoubleDouble  y)

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.

Parameters
ythe value to divide by
Returns
this object, divided by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfDivide ( final double  y)

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.

Parameters
ythe value to divide by
Returns
this object, divided by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfDivide ( final double  yhi,
final double  ylo 
)
private

Self divide.

Parameters
yhithe yhi
ylothe ylo
Returns
the w b_ double double
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfMultiply ( final WB_DoubleDouble  y)

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.

Parameters
ythe value to multiply by
Returns
this object, multiplied by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfMultiply ( final double  y)

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.

Parameters
ythe value to multiply by
Returns
this object, multiplied by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfMultiply ( final double  yhi,
final double  ylo 
)
private

Self multiply.

Parameters
yhithe yhi
ylothe ylo
Returns
the w b_ double double
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfSubtract ( final WB_DoubleDouble  y)

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.

Parameters
ythe addend
Returns
this object, decreased by y
WB_DoubleDouble wblut.math.WB_DoubleDouble.selfSubtract ( final double  y)

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.

Parameters
ythe addend
Returns
this object, decreased by y
int wblut.math.WB_DoubleDouble.signum ( )

Returns an integer indicating the sign of this value.

  • if this value is > 0, returns 1
  • if this value is < 0, returns -1
  • if this value is = 0, returns 0
  • if this value is NaN, returns 0
Returns
an integer indicating the sign of this value
WB_DoubleDouble wblut.math.WB_DoubleDouble.sqr ( )

Computes the square of this value.

Returns
the square of this value.
static WB_DoubleDouble wblut.math.WB_DoubleDouble.sqr ( final double  x)
static

Computes the square of this value.

Parameters
xthe x
Returns
the square of this value.
WB_DoubleDouble wblut.math.WB_DoubleDouble.sqrt ( )

Computes the positive square root of this value. If the number is NaN or negative, NaN is returned.

Returns
the positive square root of this number. If the argument is NaN or less than zero, the result is NaN.
static WB_DoubleDouble wblut.math.WB_DoubleDouble.sqrt ( final double  x)
static

Sqrt.

Parameters
xthe x
Returns
the w b_ double double
static String wblut.math.WB_DoubleDouble.stringOfChar ( final char  ch,
final int  len 
)
staticprivate

Creates a string of a given length containing the given character.

Parameters
chthe character to be repeated
lenthe len of the desired string
Returns
the string
WB_DoubleDouble wblut.math.WB_DoubleDouble.subtract ( final WB_DoubleDouble  y)

Computes a new DoubleDouble object whose value is (this - y).

Parameters
ythe subtrahend
Returns
(this - y)
WB_DoubleDouble wblut.math.WB_DoubleDouble.subtract ( final double  y)

Computes a new DoubleDouble object whose value is (this - y).

Parameters
ythe subtrahend
Returns
(this - y)
String wblut.math.WB_DoubleDouble.toSciNotation ( )

Returns the string representation of this value in scientific notation.

Returns
the string representation in scientific notation
String wblut.math.WB_DoubleDouble.toStandardNotation ( )

Returns the string representation of this value in standard notation.

Returns
the string representation in standard notation
String wblut.math.WB_DoubleDouble.toString ( )

Returns a string representation of this number, in either standard or scientific notation. If the magnitude of the number is in the range [ 10-3, 108 ] standard notation will be used. Otherwise, scientific notation will be used.

Returns
a string representation of this number
WB_DoubleDouble wblut.math.WB_DoubleDouble.trunc ( )

Returns the integer which is largest in absolute value and not further from zero than this value. Special cases:

  • If this value is NaN, returns NaN.
Returns
the integer which is largest in absolute value and not further from zero than this value
static WB_DoubleDouble wblut.math.WB_DoubleDouble.valueOf ( final String  str) throws NumberFormatException
static

Converts the string argument to a DoubleDouble number.

Parameters
stra string containing a representation of a numeric value
Returns
the extended precision version of the value
Exceptions
NumberFormatExceptionif s is not a valid representation of a number
static WB_DoubleDouble wblut.math.WB_DoubleDouble.valueOf ( final double  x)
static

Converts the double argument to a DoubleDouble number.

Parameters
xa numeric value
Returns
the extended precision version of the value

Member Data Documentation

final WB_DoubleDouble wblut.math.WB_DoubleDouble.E
static
Initial value:
2.718281828459045091e+00, 1.445646891729250158e-16)

The value nearest to the constant e (the natural logarithm base).

final double wblut.math.WB_DoubleDouble.EPS = 1.23259516440783e-32
static

The smallest representable relative difference between two {link @ DoubleDouble} values.

double wblut.math.WB_DoubleDouble.hi = 0.0
private

The high-order component of the double-double precision value.

double wblut.math.WB_DoubleDouble.lo = 0.0
private

The low-order component of the double-double precision value.

final int wblut.math.WB_DoubleDouble.MAX_PRINT_DIGITS = 32
staticprivate

The Constant MAX_PRINT_DIGITS.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.NaN
static
Initial value:
= new WB_DoubleDouble(Double.NaN,
Double.NaN)

A value representing the result of an operation which does not return a valid number.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.ONE = WB_DoubleDouble.valueOf(1.0)
staticprivate

The Constant ONE.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.PI
static
Initial value:
3.141592653589793116e+00, 1.224646799147353207e-16)

The value nearest to the constant Pi.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.PI_2
static
Initial value:
1.570796326794896558e+00, 6.123233995736766036e-17)

The value nearest to the constant Pi / 2.

final String wblut.math.WB_DoubleDouble.SCI_NOT_EXPONENT_CHAR = "E"
staticprivate

The Constant SCI_NOT_EXPONENT_CHAR.

final String wblut.math.WB_DoubleDouble.SCI_NOT_ZERO = "0.0E0"
staticprivate

The Constant SCI_NOT_ZERO.

final long wblut.math.WB_DoubleDouble.serialVersionUID = -2751466014056438637L
staticprivate

The Constant serialVersionUID.

final double wblut.math.WB_DoubleDouble.SPLIT = 134217729.0D
staticprivate

The value to split a double-precision value on during multiplication.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.TEN = WB_DoubleDouble.valueOf(10.0)
staticprivate

The Constant TEN.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.TWO_PI
static
Initial value:
6.283185307179586232e+00, 2.449293598294706414e-16)

The value nearest to the constant 2 * Pi.

final WB_DoubleDouble wblut.math.WB_DoubleDouble.ZERO = new WB_DoubleDouble(0.0, 0.0)
static

The Constant ZERO.


The documentation for this class was generated from the following file: