Struct DD
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.
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
Inherited Members
Namespace: NetTopologySuite.Mathematics
Assembly: NetTopologySuite.dll
Syntax
[Serializable]
public struct DD : IComparable, IComparable<DD>
Constructors
| Edit this page View SourceDD(DD)
Creates a DD with a value equal to the argument
Declaration
public DD(DD dd)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | dd | The initial value |
DD(double)
Creates a new DD with value x.
Declaration
public DD(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | The initial value |
DD(double, double)
Creates a new DD with value (hi, lo).
Declaration
public DD(double hi, double lo)
Parameters
| Type | Name | Description |
|---|---|---|
| double | hi | The high order component |
| double | lo | The low order component |
DD(string)
Creates a new DD with value equal to the argument.
Declaration
public DD(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The value to initialize by |
Exceptions
| Type | Condition |
|---|---|
| FormatException | if |
Fields
| Edit this page View SourceE
The value nearest to the constant e (the natural logarithm base).
Declaration
public static readonly DD E
Field Value
| Type | Description |
|---|---|
| DD |
Epsilon
The smallest representable relative difference between two DD values
Declaration
public static readonly double Epsilon
Field Value
| Type | Description |
|---|---|
| double |
NaN
A value representing the result of an operation which does not return a valid number.
Declaration
public static readonly DD NaN
Field Value
| Type | Description |
|---|---|
| DD |
PI
The value nearest to the constant Pi.
Declaration
public static readonly DD PI
Field Value
| Type | Description |
|---|---|
| DD |
PiHalf
The value nearest to the constant Pi / 2.
Declaration
public static readonly DD PiHalf
Field Value
| Type | Description |
|---|---|
| DD |
TwoPi
The value nearest to the constant 2 * Pi.
Declaration
public static readonly DD TwoPi
Field Value
| Type | Description |
|---|---|
| DD |
Properties
| Edit this page View SourceIsNegative
Gets a value indicating whether this object is negative or not
Declaration
public bool IsNegative { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsZero
Gets a value indicating whether this object is zero (0) or not
Declaration
public bool IsZero { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceAbs()
Returns the absolute value of this value.
Special cases:- if this value is NaN, it is returned.
Declaration
public DD Abs()
Returns
| Type | Description |
|---|---|
| DD | The absolute value of this value |
Ceiling()
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.
Declaration
public DD Ceiling()
Returns
| Type | Description |
|---|---|
| DD | The smallest (closest to negative infinity) value that is not less than the argument and is equal to a mathematical integer. |
Clone()
Creates and returns a copy of this value.
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| object | A copy of this value |
CompareTo(DD)
Compares two DoubleDouble objects numerically.
Declaration
public int CompareTo(DD other)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | other | An other DoubleDouble value |
Returns
| Type | Description |
|---|---|
| int |
|
CompareTo(object)
Declaration
public int CompareTo(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o |
Returns
| Type | Description |
|---|---|
| int |
Copy(DD)
Creates a new DD with the value of the argument.
Declaration
public static DD Copy(DD dd)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | dd | The value to copy |
Returns
| Type | Description |
|---|---|
| DD | A copy of |
Determinant(DD, DD, DD, DD)
Computes the determinant of the 2x2 matrix with the given entries.
Declaration
public static DD Determinant(DD x1, DD y1, DD x2, DD y2)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | x1 | A matrix entry |
| DD | y1 | A matrix entry |
| DD | x2 | A matrix entry |
| DD | y2 | A matrix entry |
Returns
| Type | Description |
|---|---|
| DD | The determinant of the matrix of values |
Determinant(double, double, double, double)
Computes the determinant of the 2x2 matrix with the given entries.
Declaration
public static DD Determinant(double x1, double y1, double x2, double y2)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x1 | A matrix entry |
| double | y1 | A matrix entry |
| double | x2 | A matrix entry |
| double | y2 | A matrix entry |
Returns
| Type | Description |
|---|---|
| DD | The determinant of the matrix of values |
Dump()
Dumps the components of this number to a string.
Declaration
public string Dump()
Returns
| Type | Description |
|---|---|
| string | A string showing the components of the number |
Equals(DD)
Tests whether this value is equal to another DoubleDouble value.
Declaration
public bool Equals(DD y)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | y | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceFloor()
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.
Declaration
public DD Floor()
Returns
| Type | Description |
|---|---|
| DD | The largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
| Edit this page View SourceGreaterOrEqualThan(DD)
Tests whether this value is greater than or equals to another DoubleDouble value.
Declaration
public bool GreaterOrEqualThan(DD y)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | y | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
GreaterThan(DD)
Tests whether this value is greater than another DoubleDouble value.
Declaration
public bool GreaterThan(DD y)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | y | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
IsInfinity(DD)
Checks if value is infinity.
Declaration
public static bool IsInfinity(DD value)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | value | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
IsNaN(DD)
Gets a value indicating whether this object is positive or not
Declaration
public static bool IsNaN(DD value)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | value |
Returns
| Type | Description |
|---|---|
| bool |
IsPositive()
Gets a value indicating whether this object is positive or not
Declaration
public bool IsPositive()
Returns
| Type | Description |
|---|---|
| bool |
LessOrEqualThan(DD)
Tests whether this value is less than or equal to another DoubleDouble value.
Declaration
public bool LessOrEqualThan(DD y)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | y | A DoubleDouble |
Returns
| Type | Description |
|---|---|
| bool |
|
LessThan(DD)
Tests whether this value is less than another DoubleDouble value.
Declaration
public bool LessThan(DD y)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | y | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
Max(DD)
Computes the maximum of this and another DD number.
Declaration
public DD Max(DD x)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | x | A DD number |
Returns
| Type | Description |
|---|---|
| DD | The maximum of the two numbers |
Min(DD)
Computes the minimum of this and another DD number.
Declaration
public DD Min(DD x)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | x | A DD number |
Returns
| Type | Description |
|---|---|
| DD | The minimum of the two numbers |
Parse(string)
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}+
Declaration
public static DD Parse(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string to parse |
Returns
| Type | Description |
|---|---|
| DD | The value of the parsed number |
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown if str is not a valid representation of a number |
Pow(int)
Computes the value of this number raised to an integral power. Follows semantics of .Net Math.Pow as closely as possible.
Declaration
[Pure]
public DD Pow(int exp)
Parameters
| Type | Name | Description |
|---|---|---|
| int | exp | The integer exponent |
Returns
| Type | Description |
|---|---|
| DD | x raised to the integral power exp |
Reciprocal()
Returns a DD whose value is 1 / this.
Declaration
public DD Reciprocal()
Returns
| Type | Description |
|---|---|
| DD | The reciprocal of this value |
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.
Declaration
public DD Rint()
Returns
| Type | Description |
|---|---|
| DD | This value rounded to the nearest integer |
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
Declaration
public int Signum()
Returns
| Type | Description |
|---|---|
| int | An integer indicating the sign of this value |
Sqr()
Computes the square of this value.
Declaration
public DD Sqr()
Returns
| Type | Description |
|---|---|
| DD | The square of this value |
Sqr(double)
Computes the square of this value.
Declaration
public static DD Sqr(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x |
Returns
| Type | Description |
|---|---|
| DD | The square of this value. |
Sqrt()
Computes the positive square root of this value.
If the number is NaN or negative, NaN is returned.Declaration
public DD Sqrt()
Returns
| Type | Description |
|---|---|
| DD | If this is NaN or less than zero, the result is NaN. |
Sqrt(double)
Computes the positive square root of a DoubleDouble value.
If the number is NaN or negative, NaN is returned.Declaration
public static DD Sqrt(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | A numeric value |
Returns
| Type | Description |
|---|---|
| DD | the positive square root of this number. If the argument is NaN or less than zero, the result is NaN. |
ToDoubleValue()
Converts this value to the nearest double number.
Declaration
public double ToDoubleValue()
Returns
| Type | Description |
|---|---|
| double | The nearest double value |
ToIntValue()
Converts this value to the nearest int value.
Declaration
public int ToIntValue()
Returns
| Type | Description |
|---|---|
| int | The nearest int value |
ToSciNotation()
Returns the string representation of this value in scientific notation.
Declaration
public string ToSciNotation()
Returns
| Type | Description |
|---|---|
| string | The string representation in scientific notation |
ToStandardNotation()
Returns the string representation of this value in standard notation.
Declaration
public string ToStandardNotation()
Returns
| Type | Description |
|---|---|
| string | The string representation in standard notation |
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.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of this number |
Overrides
| Edit this page View SourceTruncate()
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.
Declaration
public DD Truncate()
Returns
| Type | Description |
|---|---|
| DD | The integer which is largest in absolute value and not further from zero than this value |
ValueOf(double)
Converts the double argument to a DoubleDouble number.
Declaration
public static DD ValueOf(double x)
Parameters
| Type | Name | Description |
|---|---|---|
| double | x | A numeric value |
Returns
| Type | Description |
|---|---|
| DD | The extended precision version of the value |
ValueOf(string)
Converts the string argument to a DoubleDouble number.
Declaration
public static DD ValueOf(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | A string containing a representation of a numeric value |
Returns
| Type | Description |
|---|---|
| DD | The extended precision version of the value |
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown if |
Operators
| Edit this page View Sourceoperator +(DD, DD)
Returns the sum of lhs and rhs.
Declaration
public static DD operator +(DD lhs, DD rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | The left hand side |
| DD | rhs | The right hand side |
Returns
| Type | Description |
|---|---|
| DD | The sum of |
operator +(DD, double)
Returns the sum of lhs and rhs.
Declaration
public static DD operator +(DD lhs, double rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | The left hand side |
| double | rhs | The right hand side |
Returns
| Type | Description |
|---|---|
| DD | The sum of |
operator /(DD, DD)
Divides lhs by rhs.
Declaration
public static DD operator /(DD lhs, DD rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | A DoubleDouble numerator. |
| DD | rhs | A DoubleDouble divisor. |
Returns
| Type | Description |
|---|---|
| DD | The result of the division. |
operator /(DD, double)
Divides lhs by rhs.
Declaration
public static DD operator /(DD lhs, double rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | A DoubleDouble numerator. |
| double | rhs | A double divisor. |
Returns
| Type | Description |
|---|---|
| DD | The result of the division. |
operator ==(DD, DD)
Equality operator for DoubleDouble values
Declaration
public static bool operator ==(DD lhs, DD rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | A DoubleDouble value |
| DD | rhs | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
explicit operator DD(string)
Operator to parse a DoubleDouble from a string
Declaration
public static explicit operator DD(string val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | val | The DoubleDouble string |
Returns
| Type | Description |
|---|---|
| DD |
implicit operator DD(double)
Operator to convert the double value to a DoubleDouble value.
Declaration
public static implicit operator DD(double val)
Parameters
| Type | Name | Description |
|---|---|---|
| double | val | The DoubleDouble string |
Returns
| Type | Description |
|---|---|
| DD |
operator !=(DD, DD)
Inequality operator for DoubleDouble values
Declaration
public static bool operator !=(DD rhs, DD lhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | rhs | A DoubleDouble value |
| DD | lhs | A DoubleDouble value |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(DD, DD)
Multiplies lhs by rhs.
Declaration
public static DD operator *(DD lhs, DD rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | A DoubleDouble value. |
| DD | rhs | A DoubleDouble value. |
Returns
| Type | Description |
|---|---|
| DD | The result of the multiplication. |
operator *(DD, double)
Multiplies lhs by rhs.
Declaration
public static DD operator *(DD lhs, double rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | A DoubleDouble value. |
| double | rhs | A double value. |
Returns
| Type | Description |
|---|---|
| DD | The result of the multiplication. |
operator -(DD, DD)
Returns the difference of lhs and rhs.
Declaration
public static DD operator -(DD lhs, DD rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | The left hand side |
| DD | rhs | The right hand side |
Returns
| Type | Description |
|---|---|
| DD | The difference of |
operator -(DD, double)
Returns the difference of lhs and rhs.
Declaration
public static DD operator -(DD lhs, double rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | lhs | The left hand side |
| double | rhs | The right hand side |
Returns
| Type | Description |
|---|---|
| DD | The difference of |
operator -(DD)
Subtracts the argument from the value of this.
Declaration
public static DD operator -(DD val)
Parameters
| Type | Name | Description |
|---|---|---|
| DD | val | The subtrahend |
Returns
| Type | Description |
|---|---|
| DD | The result of this - y |