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
| Improve this Doc 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
| Improve this Doc 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
| Improve this Doc View SourceIsNegative
Gets a value indicating whether this object is negative or not
Declaration
public readonly bool IsNegative { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsZero
Gets a value indicating whether this object is zero (0) or not
Declaration
public readonly bool IsZero { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc 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 |
---|---|
Int32 |
|
CompareTo(Object)
Declaration
public int CompareTo(object o)
Parameters
Type | Name | Description |
---|---|---|
Object | o |
Returns
Type | Description |
---|---|
Int32 |
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 |
---|---|
Boolean |
|
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc 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 |
---|---|
Int32 |
Overrides
| Improve this Doc 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 |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
IsPositive()
Gets a value indicating whether this object is positive or not
Declaration
public bool IsPositive()
Returns
Type | Description |
---|---|
Boolean |
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 |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
|
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(Int32)
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 |
---|---|---|
Int32 | 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 |
---|---|
Int32 | 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 Int32 value.
Declaration
public int ToIntValue()
Returns
Type | Description |
---|---|
Int32 | The nearest Int32 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
| Improve this Doc 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
| Improve this Doc View SourceAddition(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 |
Addition(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 |
Division(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.
|
Division(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.
|
Equality(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 |
---|---|
Boolean |
|
Explicit(String to DD)
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(Double to DD)
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 |
Inequality(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 |
---|---|
Boolean |
|
Multiply(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.
|
Multiply(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.
|
Subtraction(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 |
Subtraction(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 |
UnaryNegation(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 |