Freigeben über


Double Class

Definition

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 object that represents the primitive double argument.

Double(String)

Constructs a newly allocated Double object that represents the floating-point value of type double represented by the string.

Fields

Bytes

The number of bytes used to represent a double value.

MaxExponent

Maximum exponent a finite double variable may have.

MaxValue

A constant holding the largest positive finite value of type double, (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>.

MinExponent

Minimum exponent a normalized double variable may have.

MinNormal

A constant holding the smallest positive normal value of type double, 2<sup>-1022</sup>.

MinValue

A constant holding the smallest positive nonzero value of type double, 2<sup>-1074</sup>.

NaN

A constant holding a Not-a-Number (NaN) value of type double.

NegativeInfinity

A constant holding the negative infinity of type double.

PositiveInfinity

A constant holding the positive infinity of type double.

Size

The number of bits used to represent a double value.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsInfinite

Returns true if this Double value is infinitely large in magnitude, false otherwise.

IsNaN

Returns true if this Double value is a Not-a-Number (NaN), false otherwise.

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 Class instance representing the primitive type double.

Methods

ByteValue()

Returns the value of the specified number as a byte.

(Inherited from Number)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Compare(Double, Double)

Compares the two specified double values.

CompareTo(Double)

Compares two Double objects numerically.

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 double value of this Double object.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
FloatValue()

Returns the value of this Double as a float after a narrowing primitive conversion.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
HashCode(Double)

Returns a hash code for a double value; compatible with Double.hashCode().

IntValue()

Returns the value of this Double as an int after a narrowing primitive conversion.

InvokeIsInfinite(Double)

Returns true if the specified number is infinitely large in magnitude, false otherwise.

InvokeIsNaN(Double)

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

IsFinite(Double)

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

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 double value corresponding to a given bit representation.

LongValue()

Returns the value of this Double as a long after a narrowing primitive conversion.

Max(Double, Double)

Returns the greater of two double values as if by calling Math#max(double, double) Math.max.

Min(Double, Double)

Returns the smaller of two double values as if by calling Math#min(double, double) Math.min.

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 double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ShortValue()

Returns the value of the specified number as a short.

(Inherited from Number)
Sum(Double, Double)

Adds two double values together as per the + operator.

ToArray<T>() (Inherited from Object)
ToHexString(Double)

Returns a hexadecimal string representation of the double argument.

ToString()

Returns a string representation of the object.

(Inherited from Object)
ToString(Double)

Returns a string representation of the double argument.

UnregisterFromRuntime() (Inherited from Object)
ValueOf(Double)

Returns a Double instance representing the specified double value.

ValueOf(String)

Returns a Double object holding the double value represented by the argument string s.

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

IComparable.CompareTo(Object)
IConvertible.GetTypeCode()
IConvertible.ToBoolean(IFormatProvider)
IConvertible.ToByte(IFormatProvider)
IConvertible.ToChar(IFormatProvider)
IConvertible.ToDateTime(IFormatProvider)
IConvertible.ToDecimal(IFormatProvider)
IConvertible.ToDouble(IFormatProvider)
IConvertible.ToInt16(IFormatProvider)
IConvertible.ToInt32(IFormatProvider)
IConvertible.ToInt64(IFormatProvider)
IConvertible.ToSByte(IFormatProvider)
IConvertible.ToSingle(IFormatProvider)
IConvertible.ToString(IFormatProvider)
IConvertible.ToType(Type, IFormatProvider)
IConvertible.ToUInt16(IFormatProvider)
IConvertible.ToUInt32(IFormatProvider)
IConvertible.ToUInt64(IFormatProvider)
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to