Double Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The Double
class wraps a value of the primitive type
double
in an object.
[Android.Runtime.Register("java/lang/Double", DoNotGenerateAcw=true)]
public sealed class Double : Java.Lang.Number, IConvertible, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable
[<Android.Runtime.Register("java/lang/Double", DoNotGenerateAcw=true)>]
type Double = class
inherit Number
interface IConvertible
interface IComparable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
- Inheritance
- Attributes
- Implements
Remarks
The Double
class wraps a value of the primitive type double
in an object. An object of type Double
contains a single field whose type is double
.
In addition, this class provides several methods for converting a double
to a String
and a String
to a double
, as well as other constants and methods useful when dealing with a double
.
<!-- Android-removed: paragraph on ValueBased
This is a value-based class; programmers should treat instances that are #equals(Object) equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. -->
<h2>equivalenceRelation>Floating-point Equality, Equivalence, and Comparison</h2>
IEEE 754 floating-point values include finite nonzero values, signed zeros (+0.0
and -0.0
), signed infinities Double#POSITIVE_INFINITY positive infinity and Double#NEGATIVE_INFINITY negative infinity), and Double#NaN NaN (not-a-number).
An <em>equivalence relation</em> on a set of values is a boolean relation on pairs of values that is reflexive, symmetric, and transitive. For more discussion of equivalence relations and object equality, see the Object#equals Object.equals
specification. An equivalence relation partitions the values it operates over into sets called equivalence classes. All the members of the equivalence class are equal to each other under the relation. An equivalence class may contain only a single member. At least for some purposes, all the members of an equivalence class are substitutable for each other. In particular, in a numeric expression equivalent values can be <em>substituted</em> for one another without changing the result of the expression, meaning changing the equivalence class of the result of the expression.
Notably, the built-in ==
operation on floating-point values is <em>not</em> an equivalence relation. Despite not defining an equivalence relation, the semantics of the IEEE 754 ==
operator were deliberately designed to meet other needs of numerical computation. There are two exceptions where the properties of an equivalence relation are not satisfied by ==
on floating-point values:
<ul>
<li>If v1
and v2
are both NaN, then v1 == v2
has the value false
. Therefore, for two NaN arguments the <em>reflexive</em> property of an equivalence relation is <em>not</em> satisfied by the ==
operator.
<li>If v1
represents +0.0
while v2
represents -0.0
, or vice versa, then v1 == v2
has the value true
even though +0.0
and -0.0
are distinguishable under various floating-point operations. For example, 1.0/+0.0
evaluates to positive infinity while 1.0/-0.0
evaluates to <em>negative</em> infinity and positive infinity and negative infinity are neither equal to each other nor equivalent to each other. Thus, while a signed zero input most commonly determines the sign of a zero result, because of dividing by zero, +0.0
and -0.0
may not be substituted for each other in general. The sign of a zero input also has a non-substitutable effect on the result of some math library methods.
</ul>
For ordered comparisons using the built-in comparison operators (<
, <=
, etc.), NaN values have another anomalous situation: a NaN is neither less than, nor greater than, nor equal to any value, including itself. This means the trichotomy of comparison does <em>not</em> hold.
To provide the appropriate semantics for equals
and compareTo
methods, those methods cannot simply be wrappers around ==
or ordered comparison operations. Instead, Double#equals equals
defines NaN arguments to be equal to each other and defines +0.0
to <em>not</em> be equal to -0.0
, restoring reflexivity. For comparisons, Double#compareTo compareTo
defines a total order where -0.0
is less than +0.0
and where a NaN is equal to itself and considered greater than positive infinity.
The operational semantics of equals
and compareTo
are expressed in terms of #doubleToLongBits bit-wise converting the floating-point values to integral values.
The <em>natural ordering</em> implemented by #compareTo compareTo
is Comparable consistent with equals. That is, two objects are reported as equal by equals
if and only if compareTo
on those objects returns zero.
The adjusted behaviors defined for equals
and compareTo
allow instances of wrapper classes to work properly with conventional data structures. For example, defining NaN values to be equals
to one another allows NaN to be used as an element of a java.util.HashSet HashSet
or as the key of a java.util.HashMap HashMap
. Similarly, defining compareTo
as a total ordering, including +0.0
, -0.0
, and NaN, allows instances of wrapper classes to be used as elements of a java.util.SortedSet SortedSet
or as keys of a java.util.SortedMap SortedMap
.
Added in 1.0.
Java documentation for java.lang.Double
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
Double(Double) |
Constructs a newly allocated |
Double(String) |
Constructs a newly allocated |
Fields
Bytes |
The number of bytes used to represent a |
MaxExponent |
Maximum exponent a finite |
MaxValue |
A constant holding the largest positive finite value of type
|
MinExponent |
Minimum exponent a normalized |
MinNormal |
A constant holding the smallest positive normal value of type
|
MinValue |
A constant holding the smallest positive nonzero value of type
|
NaN |
A constant holding a Not-a-Number (NaN) value of type
|
NegativeInfinity |
A constant holding the negative infinity of type
|
PositiveInfinity |
A constant holding the positive infinity of type
|
Size |
The number of bits used to represent a |
Properties
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
IsInfinite |
Returns |
IsNaN |
Returns |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Number) |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Number) |
Type |
The |
Methods
ByteValue() |
Returns the value of the specified number as a |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
Compare(Double, Double) |
Compares the two specified |
CompareTo(Double) |
Compares two |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
DoubleToLongBits(Double) |
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout. |
DoubleToRawLongBits(Double) |
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, preserving Not-a-Number (NaN) values. |
DoubleValue() |
Returns the |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
FloatValue() |
Returns the value of this |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
HashCode(Double) |
Returns a hash code for a |
IntValue() |
Returns the value of this |
InvokeIsInfinite(Double) |
Returns |
InvokeIsNaN(Double) |
Returns |
IsFinite(Double) |
Returns |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
LongBitsToDouble(Int64) |
Returns the |
LongValue() |
Returns the value of this |
Max(Double, Double) |
Returns the greater of two |
Min(Double, Double) |
Returns the smaller of two |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
ParseDouble(String) |
Returns a new |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ShortValue() |
Returns the value of the specified number as a |
Sum(Double, Double) |
Adds two |
ToArray<T>() | (Inherited from Object) |
ToHexString(Double) |
Returns a hexadecimal string representation of the
|
ToString() |
Returns a string representation of the object. (Inherited from Object) |
ToString(Double) |
Returns a string representation of the |
UnregisterFromRuntime() | (Inherited from Object) |
ValueOf(Double) |
Returns a |
ValueOf(String) |
Returns a |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Operators
Explicit(Double to Double) |
Explicit Interface Implementations
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |