Double Struktur
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili bilangan titik-mengambang presisi ganda.
public value class double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
public value class double : IComparable<double>, IConvertible, IEquatable<double>, IParsable<double>, ISpanParsable<double>, IUtf8SpanParsable<double>, System::Numerics::IAdditionOperators<double, double, double>, System::Numerics::IAdditiveIdentity<double, double>, System::Numerics::IBinaryFloatingPointIeee754<double>, System::Numerics::IBinaryNumber<double>, System::Numerics::IBitwiseOperators<double, double, double>, System::Numerics::IComparisonOperators<double, double, bool>, System::Numerics::IDecrementOperators<double>, System::Numerics::IDivisionOperators<double, double, double>, System::Numerics::IEqualityOperators<double, double, bool>, System::Numerics::IExponentialFunctions<double>, System::Numerics::IFloatingPoint<double>, System::Numerics::IFloatingPointConstants<double>, System::Numerics::IFloatingPointIeee754<double>, System::Numerics::IHyperbolicFunctions<double>, System::Numerics::IIncrementOperators<double>, System::Numerics::ILogarithmicFunctions<double>, System::Numerics::IMinMaxValue<double>, System::Numerics::IModulusOperators<double, double, double>, System::Numerics::IMultiplicativeIdentity<double, double>, System::Numerics::IMultiplyOperators<double, double, double>, System::Numerics::INumber<double>, System::Numerics::INumberBase<double>, System::Numerics::IPowerFunctions<double>, System::Numerics::IRootFunctions<double>, System::Numerics::ISignedNumber<double>, System::Numerics::ISubtractionOperators<double, double, double>, System::Numerics::ITrigonometricFunctions<double>, System::Numerics::IUnaryNegationOperators<double, double>, System::Numerics::IUnaryPlusOperators<double, double>
public value class double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, ISpanFormattable
public value class double : IComparable<double>, IConvertible, IEquatable<double>, IParsable<double>, ISpanParsable<double>, System::Numerics::IAdditionOperators<double, double, double>, System::Numerics::IAdditiveIdentity<double, double>, System::Numerics::IBinaryFloatingPointIeee754<double>, System::Numerics::IBinaryNumber<double>, System::Numerics::IBitwiseOperators<double, double, double>, System::Numerics::IComparisonOperators<double, double, bool>, System::Numerics::IDecrementOperators<double>, System::Numerics::IDivisionOperators<double, double, double>, System::Numerics::IEqualityOperators<double, double, bool>, System::Numerics::IExponentialFunctions<double>, System::Numerics::IFloatingPoint<double>, System::Numerics::IFloatingPointConstants<double>, System::Numerics::IFloatingPointIeee754<double>, System::Numerics::IHyperbolicFunctions<double>, System::Numerics::IIncrementOperators<double>, System::Numerics::ILogarithmicFunctions<double>, System::Numerics::IMinMaxValue<double>, System::Numerics::IModulusOperators<double, double, double>, System::Numerics::IMultiplicativeIdentity<double, double>, System::Numerics::IMultiplyOperators<double, double, double>, System::Numerics::INumber<double>, System::Numerics::INumberBase<double>, System::Numerics::IPowerFunctions<double>, System::Numerics::IRootFunctions<double>, System::Numerics::ISignedNumber<double>, System::Numerics::ISubtractionOperators<double, double, double>, System::Numerics::ITrigonometricFunctions<double>, System::Numerics::IUnaryNegationOperators<double, double>, System::Numerics::IUnaryPlusOperators<double, double>
public value class double : IComparable, IConvertible, IFormattable
public value class double : IComparable, IComparable<double>, IEquatable<double>, IFormattable
public struct Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
public readonly struct Double : IComparable<double>, IConvertible, IEquatable<double>, IParsable<double>, ISpanParsable<double>, IUtf8SpanParsable<double>, System.Numerics.IAdditionOperators<double,double,double>, System.Numerics.IAdditiveIdentity<double,double>, System.Numerics.IBinaryFloatingPointIeee754<double>, System.Numerics.IBinaryNumber<double>, System.Numerics.IBitwiseOperators<double,double,double>, System.Numerics.IComparisonOperators<double,double,bool>, System.Numerics.IDecrementOperators<double>, System.Numerics.IDivisionOperators<double,double,double>, System.Numerics.IEqualityOperators<double,double,bool>, System.Numerics.IExponentialFunctions<double>, System.Numerics.IFloatingPoint<double>, System.Numerics.IFloatingPointConstants<double>, System.Numerics.IFloatingPointIeee754<double>, System.Numerics.IHyperbolicFunctions<double>, System.Numerics.IIncrementOperators<double>, System.Numerics.ILogarithmicFunctions<double>, System.Numerics.IMinMaxValue<double>, System.Numerics.IModulusOperators<double,double,double>, System.Numerics.IMultiplicativeIdentity<double,double>, System.Numerics.IMultiplyOperators<double,double,double>, System.Numerics.INumber<double>, System.Numerics.INumberBase<double>, System.Numerics.IPowerFunctions<double>, System.Numerics.IRootFunctions<double>, System.Numerics.ISignedNumber<double>, System.Numerics.ISubtractionOperators<double,double,double>, System.Numerics.ITrigonometricFunctions<double>, System.Numerics.IUnaryNegationOperators<double,double>, System.Numerics.IUnaryPlusOperators<double,double>
public readonly struct Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
public readonly struct Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, ISpanFormattable
public readonly struct Double : IComparable<double>, IConvertible, IEquatable<double>, IParsable<double>, ISpanParsable<double>, System.Numerics.IAdditionOperators<double,double,double>, System.Numerics.IAdditiveIdentity<double,double>, System.Numerics.IBinaryFloatingPointIeee754<double>, System.Numerics.IBinaryNumber<double>, System.Numerics.IBitwiseOperators<double,double,double>, System.Numerics.IComparisonOperators<double,double,bool>, System.Numerics.IDecrementOperators<double>, System.Numerics.IDivisionOperators<double,double,double>, System.Numerics.IEqualityOperators<double,double,bool>, System.Numerics.IExponentialFunctions<double>, System.Numerics.IFloatingPoint<double>, System.Numerics.IFloatingPointConstants<double>, System.Numerics.IFloatingPointIeee754<double>, System.Numerics.IHyperbolicFunctions<double>, System.Numerics.IIncrementOperators<double>, System.Numerics.ILogarithmicFunctions<double>, System.Numerics.IMinMaxValue<double>, System.Numerics.IModulusOperators<double,double,double>, System.Numerics.IMultiplicativeIdentity<double,double>, System.Numerics.IMultiplyOperators<double,double,double>, System.Numerics.INumber<double>, System.Numerics.INumberBase<double>, System.Numerics.IPowerFunctions<double>, System.Numerics.IRootFunctions<double>, System.Numerics.ISignedNumber<double>, System.Numerics.ISubtractionOperators<double,double,double>, System.Numerics.ITrigonometricFunctions<double>, System.Numerics.IUnaryNegationOperators<double,double>, System.Numerics.IUnaryPlusOperators<double,double>
[System.Serializable]
public struct Double : IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
public struct Double : IComparable, IComparable<double>, IEquatable<double>, IFormattable
type double = struct
interface IConvertible
interface IFormattable
type double = struct
interface IConvertible
interface IFormattable
interface IParsable<double>
interface ISpanFormattable
interface ISpanParsable<double>
interface IUtf8SpanFormattable
interface IUtf8SpanParsable<double>
interface IAdditionOperators<double, double, double>
interface IAdditiveIdentity<double, double>
interface IBinaryFloatingPointIeee754<double>
interface IBinaryNumber<double>
interface IBitwiseOperators<double, double, double>
interface IComparisonOperators<double, double, bool>
interface IEqualityOperators<double, double, bool>
interface IDecrementOperators<double>
interface IDivisionOperators<double, double, double>
interface IIncrementOperators<double>
interface IModulusOperators<double, double, double>
interface IMultiplicativeIdentity<double, double>
interface IMultiplyOperators<double, double, double>
interface INumber<double>
interface INumberBase<double>
interface ISubtractionOperators<double, double, double>
interface IUnaryNegationOperators<double, double>
interface IUnaryPlusOperators<double, double>
interface IExponentialFunctions<double>
interface IFloatingPointConstants<double>
interface IFloatingPoint<double>
interface ISignedNumber<double>
interface IFloatingPointIeee754<double>
interface IHyperbolicFunctions<double>
interface ILogarithmicFunctions<double>
interface IPowerFunctions<double>
interface IRootFunctions<double>
interface ITrigonometricFunctions<double>
interface IMinMaxValue<double>
type double = struct
interface IConvertible
interface ISpanFormattable
interface IFormattable
type double = struct
interface IConvertible
interface IFormattable
interface IParsable<double>
interface ISpanFormattable
interface ISpanParsable<double>
interface IAdditionOperators<double, double, double>
interface IAdditiveIdentity<double, double>
interface IBinaryFloatingPointIeee754<double>
interface IBinaryNumber<double>
interface IBitwiseOperators<double, double, double>
interface IComparisonOperators<double, double, bool>
interface IEqualityOperators<double, double, bool>
interface IDecrementOperators<double>
interface IDivisionOperators<double, double, double>
interface IIncrementOperators<double>
interface IModulusOperators<double, double, double>
interface IMultiplicativeIdentity<double, double>
interface IMultiplyOperators<double, double, double>
interface INumber<double>
interface INumberBase<double>
interface ISubtractionOperators<double, double, double>
interface IUnaryNegationOperators<double, double>
interface IUnaryPlusOperators<double, double>
interface IExponentialFunctions<double>
interface IFloatingPointConstants<double>
interface IFloatingPoint<double>
interface ISignedNumber<double>
interface IFloatingPointIeee754<double>
interface IHyperbolicFunctions<double>
interface ILogarithmicFunctions<double>
interface IPowerFunctions<double>
interface IRootFunctions<double>
interface ITrigonometricFunctions<double>
interface IMinMaxValue<double>
type double = struct
interface IConvertible
interface IFormattable
interface IParsable<double>
interface ISpanFormattable
interface ISpanParsable<double>
interface IAdditionOperators<double, double, double>
interface IAdditiveIdentity<double, double>
interface IBinaryFloatingPointIeee754<double>
interface IBinaryNumber<double>
interface IBitwiseOperators<double, double, double>
interface IComparisonOperators<double, double, bool>
interface IEqualityOperators<double, double, bool>
interface IDecrementOperators<double>
interface IDivisionOperators<double, double, double>
interface IIncrementOperators<double>
interface IModulusOperators<double, double, double>
interface IMultiplicativeIdentity<double, double>
interface IMultiplyOperators<double, double, double>
interface INumber<double>
interface INumberBase<double>
interface ISubtractionOperators<double, double, double>
interface IUnaryNegationOperators<double, double>
interface IUnaryPlusOperators<double, double>
interface IUtf8SpanFormattable
interface IUtf8SpanParsable<double>
interface IExponentialFunctions<double>
interface IFloatingPointConstants<double>
interface IFloatingPoint<double>
interface ISignedNumber<double>
interface IFloatingPointIeee754<double>
interface IHyperbolicFunctions<double>
interface ILogarithmicFunctions<double>
interface IPowerFunctions<double>
interface IRootFunctions<double>
interface ITrigonometricFunctions<double>
interface IMinMaxValue<double>
[<System.Serializable>]
type double = struct
interface IFormattable
interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type double = struct
interface IFormattable
interface IConvertible
type double = struct
interface IFormattable
Public Structure Double
Implements IComparable, IComparable(Of Double), IConvertible, IEquatable(Of Double), IFormattable
Public Structure Double
Implements IAdditionOperators(Of Double, Double, Double), IAdditiveIdentity(Of Double, Double), IBinaryFloatingPointIeee754(Of Double), IBinaryNumber(Of Double), IBitwiseOperators(Of Double, Double, Double), IComparable(Of Double), IComparisonOperators(Of Double, Double, Boolean), IConvertible, IDecrementOperators(Of Double), IDivisionOperators(Of Double, Double, Double), IEqualityOperators(Of Double, Double, Boolean), IEquatable(Of Double), IExponentialFunctions(Of Double), IFloatingPoint(Of Double), IFloatingPointConstants(Of Double), IFloatingPointIeee754(Of Double), IHyperbolicFunctions(Of Double), IIncrementOperators(Of Double), ILogarithmicFunctions(Of Double), IMinMaxValue(Of Double), IModulusOperators(Of Double, Double, Double), IMultiplicativeIdentity(Of Double, Double), IMultiplyOperators(Of Double, Double, Double), INumber(Of Double), INumberBase(Of Double), IParsable(Of Double), IPowerFunctions(Of Double), IRootFunctions(Of Double), ISignedNumber(Of Double), ISpanParsable(Of Double), ISubtractionOperators(Of Double, Double, Double), ITrigonometricFunctions(Of Double), IUnaryNegationOperators(Of Double, Double), IUnaryPlusOperators(Of Double, Double), IUtf8SpanParsable(Of Double)
Public Structure Double
Implements IComparable, IComparable(Of Double), IConvertible, IEquatable(Of Double), ISpanFormattable
Public Structure Double
Implements IAdditionOperators(Of Double, Double, Double), IAdditiveIdentity(Of Double, Double), IBinaryFloatingPointIeee754(Of Double), IBinaryNumber(Of Double), IBitwiseOperators(Of Double, Double, Double), IComparable(Of Double), IComparisonOperators(Of Double, Double, Boolean), IConvertible, IDecrementOperators(Of Double), IDivisionOperators(Of Double, Double, Double), IEqualityOperators(Of Double, Double, Boolean), IEquatable(Of Double), IExponentialFunctions(Of Double), IFloatingPoint(Of Double), IFloatingPointConstants(Of Double), IFloatingPointIeee754(Of Double), IHyperbolicFunctions(Of Double), IIncrementOperators(Of Double), ILogarithmicFunctions(Of Double), IMinMaxValue(Of Double), IModulusOperators(Of Double, Double, Double), IMultiplicativeIdentity(Of Double, Double), IMultiplyOperators(Of Double, Double, Double), INumber(Of Double), INumberBase(Of Double), IParsable(Of Double), IPowerFunctions(Of Double), IRootFunctions(Of Double), ISignedNumber(Of Double), ISpanParsable(Of Double), ISubtractionOperators(Of Double, Double, Double), ITrigonometricFunctions(Of Double), IUnaryNegationOperators(Of Double, Double), IUnaryPlusOperators(Of Double, Double)
Public Structure Double
Implements IComparable, IConvertible, IFormattable
Public Structure Double
Implements IComparable, IComparable(Of Double), IEquatable(Of Double), IFormattable
- Warisan
- Atribut
- Penerapan
-
IComparable IComparable<Double> IConvertible IEquatable<Double> IFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Double> IParsable<TSelf> ISpanFormattable ISpanParsable<Double> ISpanParsable<TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Double> IUtf8SpanParsable<TSelf> IAdditionOperators<Double,Double,Double> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Double,Double> IAdditiveIdentity<TSelf,TSelf> IBinaryFloatingPointIeee754<Double> IBinaryNumber<Double> IBinaryNumber<TSelf> IBitwiseOperators<Double,Double,Double> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<Double,Double,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Double> IDecrementOperators<TSelf> IDivisionOperators<Double,Double,Double> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Double,Double,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IExponentialFunctions<Double> IExponentialFunctions<TSelf> IFloatingPoint<Double> IFloatingPoint<TSelf> IFloatingPointConstants<Double> IFloatingPointConstants<TSelf> IFloatingPointIeee754<Double> IFloatingPointIeee754<TSelf> IHyperbolicFunctions<Double> IHyperbolicFunctions<TSelf> IIncrementOperators<Double> IIncrementOperators<TSelf> ILogarithmicFunctions<Double> ILogarithmicFunctions<TSelf> IMinMaxValue<Double> IModulusOperators<Double,Double,Double> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Double,Double> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Double,Double,Double> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Double> INumber<TSelf> INumberBase<Double> INumberBase<TSelf> IPowerFunctions<Double> IPowerFunctions<TSelf> IRootFunctions<Double> IRootFunctions<TSelf> ISignedNumber<Double> ISignedNumber<TSelf> ISubtractionOperators<Double,Double,Double> ISubtractionOperators<TSelf,TSelf,TSelf> ITrigonometricFunctions<Double> ITrigonometricFunctions<TSelf> IUnaryNegationOperators<Double,Double> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Double,Double> IUnaryPlusOperators<TSelf,TSelf>
Contoh
Contoh kode berikut mengilustrasikan penggunaan Double:
// The Temperature class stores the temperature as a Double
// and delegates most of the functionality to the Double
// implementation.
public class Temperature : IComparable, IFormattable
{
// IComparable.CompareTo implementation.
public int CompareTo(object obj) {
if (obj == null) return 1;
Temperature temp = obj as Temperature;
if (obj != null)
return m_value.CompareTo(temp.m_value);
else
throw new ArgumentException("object is not a Temperature");
}
// IFormattable.ToString implementation.
public string ToString(string format, IFormatProvider provider) {
if( format != null ) {
if( format.Equals("F") ) {
return String.Format("{0}'F", this.Value.ToString());
}
if( format.Equals("C") ) {
return String.Format("{0}'C", this.Celsius.ToString());
}
}
return m_value.ToString(format, provider);
}
// Parses the temperature from a string in the form
// [ws][sign]digits['F|'C][ws]
public static Temperature Parse(string s, NumberStyles styles, IFormatProvider provider) {
Temperature temp = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
}
else if( s.TrimEnd(null).EndsWith("'C") ) {
temp.Celsius = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
}
else {
temp.Value = Double.Parse(s, styles, provider);
}
return temp;
}
// The value holder
protected double m_value;
public double Value {
get {
return m_value;
}
set {
m_value = value;
}
}
public double Celsius {
get {
return (m_value-32.0)/1.8;
}
set {
m_value = 1.8*value+32.0;
}
}
}
// The Temperature class stores the temperature as a Double
// and delegates most of the functionality to the Double
// implementation.
type Temperature() =
member val Value = 0. with get, set
member this.Celsius
with get () = (this.Value - 32.) / 1.8
and set (value) =
this.Value <- 1.8 * value + 32.
// Parses the temperature from a string in the form
// [ws][sign]digits['F|'C][ws]
static member Parse(s: string, styles: NumberStyles, provider: IFormatProvider) =
let temp = Temperature()
if s.TrimEnd(null).EndsWith "'F" then
temp.Value <- Double.Parse(s.Remove(s.LastIndexOf '\'', 2), styles, provider)
elif s.TrimEnd(null).EndsWith "'C" then
temp.Celsius <- Double.Parse(s.Remove(s.LastIndexOf '\'', 2), styles, provider)
else
temp.Value <- Double.Parse(s, styles, provider)
temp
interface IComparable with
// IComparable.CompareTo implementation.
member this.CompareTo(obj: obj) =
match obj with
| null -> 1
| :? Temperature as temp ->
this.Value.CompareTo temp.Value
| _ ->
invalidArg "obj" "object is not a Temperature"
interface IFormattable with
// IFormattable.ToString implementation.
member this.ToString(format: string, provider: IFormatProvider) =
match format with
| "F" ->
$"{this.Value}'F"
| "C" ->
$"{this.Celsius}'C"
| _ ->
this.Value.ToString(format, provider)
' Temperature class stores the value as Double
' and delegates most of the functionality
' to the Double implementation.
Public Class Temperature
Implements IComparable, IFormattable
Public Overloads Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
If TypeOf obj Is Temperature Then
Dim temp As Temperature = CType(obj, Temperature)
Return m_value.CompareTo(temp.m_value)
End If
Throw New ArgumentException("object is not a Temperature")
End Function
Public Overloads Function ToString(ByVal format As String, ByVal provider As IFormatProvider) As String _
Implements IFormattable.ToString
If Not (format Is Nothing) Then
If format.Equals("F") Then
Return [String].Format("{0}'F", Me.Value.ToString())
End If
If format.Equals("C") Then
Return [String].Format("{0}'C", Me.Celsius.ToString())
End If
End If
Return m_value.ToString(format, provider)
End Function
' Parses the temperature from a string in form
' [ws][sign]digits['F|'C][ws]
Public Shared Function Parse(ByVal s As String, ByVal styles As NumberStyles, ByVal provider As IFormatProvider) As Temperature
Dim temp As New Temperature()
If s.TrimEnd().EndsWith("'F") Then
temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
Else
If s.TrimEnd().EndsWith("'C") Then
temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
Else
temp.Value = Double.Parse(s, styles, provider)
End If
End If
Return temp
End Function
' The value holder
Protected m_value As Double
Public Property Value() As Double
Get
Return m_value
End Get
Set(ByVal Value As Double)
m_value = Value
End Set
End Property
Public Property Celsius() As Double
Get
Return (m_value - 32) / 1.8
End Get
Set(ByVal Value As Double)
m_value = Value * 1.8 + 32
End Set
End Property
End Class
Keterangan
Double Jenis nilai mewakili angka 64-bit presisi ganda dengan nilai mulai dari negatif 1,79769313486232e308 hingga positif 1,79769313486232e308, serta nol positif atau negatif, PositiveInfinity, NegativeInfinity, dan bukan angka (NaN). Ini dimaksudkan untuk mewakili nilai-nilai yang sangat besar (seperti jarak antara planet atau galaksi) atau sangat kecil (seperti massa molekul zat dalam kilogram) dan yang sering tidak tepat (seperti jarak dari bumi ke tata surya lain). Jenis Double sesuai dengan standar IEC 60559:1989 (IEEE 754) untuk aritmatika floating-point biner.
Representasi dan presisi titik mengambang
Jenis Double data menyimpan nilai floating-point presisi ganda dalam format biner 64-bit, seperti yang diperlihatkan dalam tabel berikut:
| Bagian | Bit |
|---|---|
| Signifikan atau mantissa | 0-51 |
| Exponent | 52-62 |
| Tanda (0 = Positif, 1 = Negatif) | 63 |
Sama seperti pecahan desimal tidak dapat secara tepat mewakili beberapa nilai pecahan (seperti 1/3 atau Math.PI), pecahan biner tidak dapat mewakili beberapa nilai pecahan. Misalnya, 1/10, yang diwakili dengan tepat oleh .1 sebagai pecahan desimal, diwakili oleh .001100110011 sebagai pecahan biner, dengan pola "0011" berulang ke tak terbatas. Dalam hal ini, nilai floating-point memberikan representasi yang tidak tepat dari angka tersebut. Melakukan operasi matematika tambahan pada nilai floating-point asli sering cenderung meningkatkan kurangnya presisinya. Misalnya, jika Anda membandingkan hasil dari mengalikan 0,1 dengan 10 dan menjumlahkan 0,1 sebanyak sembilan kali, Anda akan melihat bahwa penjumlahan, karena melibatkan delapan operasi tambahan, menghasilkan hasil yang kurang presisi. (Sebelum .NET 10, perbedaan ini jelas hanya jika Anda menampilkan dua nilai Double dengan menggunakan string format numerik "R" standard, yang menampilkan hingga 17 digit presisi yang didukung oleh jenis Double.)
using System;
public class Example13
{
public static void Main()
{
Double value = .1;
Double result1 = value * 10;
Double result2 = 0;
for (int ctr = 1; ctr <= 10; ctr++)
result2 += value;
Console.WriteLine($".1 * 10: {result1:R}");
Console.WriteLine($".1 Added 10 times: {result2:R}");
}
}
// The example displays the following output:
// .1 * 10: 1
// .1 Added 10 times: 0.99999999999999989
let value = 0.1
let result1 = value * 10.
let mutable result2 = 0.
for i = 1 to 10 do
result2 <- result2 + value
printfn $".1 * 10: {result1:R}"
printfn $".1 Added 10 times: {result2:R}"
// The example displays the following output:
// .1 * 10: 1
// .1 Added 10 times: 0.99999999999999989
Module Example14
Public Sub Run()
Dim value As Double = 0.1
Dim result1 As Double = value * 10
Dim result2 As Double
For ctr As Integer = 1 To 10
result2 += value
Next
Console.WriteLine(".1 * 10: {0:R}", result1)
Console.WriteLine(".1 Added 10 times: {0:R}", result2)
End Sub
End Module
' The example displays the following output:
' .1 * 10: 1
' .1 Added 10 times: 0.99999999999999989
Karena beberapa angka tidak dapat direpresentasikan secara tepat sebagai nilai biner pecahan, angka floating-point hanya dapat mengaproksimasi angka riil.
Semua angka floating-point memiliki jumlah digit signifikan yang terbatas, yang menentukan seberapa akurat nilai floating-point mendekati angka nyata. Nilai Double memiliki hingga 15 digit desimal presisi, meskipun maksimum 17 digit dipertahankan secara internal. Ini berarti bahwa beberapa operasi floating-point mungkin tidak memiliki presisi untuk mengubah nilai titik mengambang. Contoh berikut memberikan ilustrasi. Ini mendefinisikan nilai floating-point yang sangat besar, dan kemudian menambahkan hasil kali dari Double.Epsilon dan satu kuadriliun ke nilai tersebut. Namun, produk ini terlalu kecil sehingga tidak dapat memodifikasi nilai floating-point yang asli. Digit yang paling tidak signifikan adalah seperseribu, sedangkan digit paling signifikan dalam produk adalah 10^(-309).
using System;
public class Example14
{
public static void Main()
{
Double value = 123456789012.34567;
Double additional = Double.Epsilon * 1e15;
Console.WriteLine($"{value} + {additional} = {value + additional}");
}
}
// The example displays the following output:
// 123456789012.346 + 4.94065645841247E-309 = 123456789012.346
open System
let value = 123456789012.34567
let additional = Double.Epsilon * 1e15
printfn $"{value} + {additional} = {value + additional}"
// The example displays the following output:
// 123456789012.346 + 4.94065645841247E-309 = 123456789012.346
Module Example15
Public Sub Run()
Dim value As Double = 123456789012.34567
Dim additional As Double = Double.Epsilon * 1.0E+15
Console.WriteLine("{0} + {1} = {2}", value, additional,
value + additional)
End Sub
End Module
' The example displays the following output:
' 123456789012.346 + 4.94065645841247E-309 = 123456789012.346
Presisi terbatas dari angka titik apung memiliki beberapa konsekuensi:
Dua angka floating-point yang tampak sama untuk presisi tertentu mungkin tidak dibandingkan sama, karena digit paling tidak signifikan mereka berbeda. Dalam contoh berikut, serangkaian angka ditambahkan bersama-sama, dan totalnya dibandingkan dengan total yang diharapkan.
using System; public class Example10 { public static void Main() { Double[] values = { 10.0, 2.88, 2.88, 2.88, 9.0 }; Double result = 27.64; Double total = 0; foreach (var value in values) total += value; if (total.Equals(result)) Console.WriteLine("The sum of the values equals the total."); else Console.WriteLine($"The sum of the values ({total}) does not equal the total ({result})."); } } // The example displays the following output: // The sum of the values (36.64) does not equal the total (36.64). // // If the index items in the Console.WriteLine statement are changed to {0:R}, // the example displays the following output: // The sum of the values (27.639999999999997) does not equal the total (27.64).let values = [ 10.0; 2.88; 2.88; 2.88; 9.0 ] let result = 27.64 let total = List.sum values if total.Equals result then printfn "The sum of the values equals the total." else printfn $"The sum of the values ({total}) does not equal the total ({result})." // The example displays the following output: // The sum of the values (36.64) does not equal the total (36.64). // // If the index items in the Console.WriteLine statement are changed to {0:R}, // the example displays the following output: // The sum of the values (27.639999999999997) does not equal the total (27.64).Module Example11 Public Sub Run() Dim values() As Double = {10.0, 2.88, 2.88, 2.88, 9.0} Dim result As Double = 27.64 Dim total As Double For Each value In values total += value Next If total.Equals(result) Then Console.WriteLine("The sum of the values equals the total.") Else Console.WriteLine("The sum of the values ({0}) does not equal the total ({1}).", total, result) End If End Sub End Module ' The example displays the following output: ' The sum of the values (36.64) does not equal the total (36.64). ' ' If the index items in the Console.WriteLine statement are changed to {0:R}, ' the example displays the following output: ' The sum of the values (27.639999999999997) does not equal the total (27.64).Kedua nilai tidak sama karena hilangnya presisi selama operasi penambahan. Dalam hal ini, masalah dapat diselesaikan dengan memanggil metode Math.Round(Double, Int32) untuk membulatkan nilai Double ke presisi yang diinginkan sebelum melakukan perbandingan.
Operasi matematika atau perbandingan yang menggunakan angka floating-point mungkin tidak menghasilkan hasil yang sama jika angka desimal digunakan, karena angka floating-point biner mungkin tidak sama dengan angka desimal. Contoh sebelumnya mengilustrasikan ini dengan menampilkan hasil mengalikan .1 dengan 10 dan menambahkan .1 kali.
Ketika akurasi dalam operasi numerik dengan nilai pecahan penting, Anda dapat menggunakan tipe Decimal daripada tipe Double. Ketika akurasi dalam operasi numerik dengan nilai integral di luar rentang jenis Int128UInt128 penting, gunakan jenis .BigInteger
nilai Single memiliki presisi yang lebih sedikit daripada nilai Double. Single Nilai yang dikonversi menjadi yang tampaknya setara Double sering kali tidak sama dengan Double nilai karena perbedaan presisi. Dalam contoh berikut, hasil operasi pembagian yang identik ditetapkan ke nilai Double dan Single . Setelah nilai Single dilemparkan ke Double, perbandingan dari dua nilai menunjukkan bahwa nilai tersebut tidak sama.
using System; public class Example9 { public static void Run() { double value1 = 1 / 3.0; float sValue2 = 1 / 3.0f; double value2 = (double)sValue2; Console.WriteLine($"{value1:R} = {value2:R}: {value1.Equals(value2)}"); } } // The example displays the following output: // 0.33333333333333331 = 0.3333333432674408: Falseopen System let value1 = 1. / 3. let sValue2 = 1f /3f let value2 = double sValue2 printfn $"{value1:R} = {value2:R}: {value1.Equals value2}" // The example displays the following output: // 0.33333333333333331 = 0.3333333432674408: FalseModule Example10 Public Sub Run() Dim value1 As Double = 1 / 3 Dim sValue2 As Single = 1 / 3 Dim value2 As Double = CDbl(sValue2) Console.WriteLine("{0} = {1}: {2}", value1, value2, value1.Equals(value2)) End Sub End Module ' The example displays the following output: ' 0.33333333333333331 = 0.3333333432674408: FalseUntuk menghindari masalah ini, gunakan Double sebagai pengganti Single jenis data, atau gunakan Round metode sehingga kedua nilai memiliki presisi yang sama.
Selain itu, hasil dari operasi aritmatika dan penugasan dengan nilai Double mungkin sedikit berbeda berdasarkan platform karena hilangnya presisi dari tipe Double. Misalnya, hasil penetapan nilai Double harfiah mungkin berbeda dalam versi .NET 32-bit dan 64-bit. Contoh berikut menggambarkan perbedaan ini ketika nilai harfiah -4.42330604244772E-305 dan variabel yang nilainya adalah -4.42330604244772E-305 ditetapkan ke Double variabel. Perhatikan bahwa hasil dari metode Parse(String) dalam hal ini tidak mengalami hilangnya presisi.
double value = -4.42330604244772E-305;
double fromLiteral = -4.42330604244772E-305;
double fromVariable = value;
double fromParse = double.Parse("-4.42330604244772E-305");
Console.WriteLine("Double value from literal: {0,29:R}", fromLiteral);
Console.WriteLine("Double value from variable: {0,28:R}", fromVariable);
Console.WriteLine("Double value from Parse method: {0,24:R}", fromParse);
// The output is:
// Double value from literal: -4.42330604244772E-305
// Double value from variable: -4.42330604244772E-305
// Double value from Parse method: -4.42330604244772E-305
let value = -4.42330604244772E-305
let fromLiteral = -4.42330604244772E-305
let fromVariable = value
let fromParse = Double.Parse "-4.42330604244772E-305"
printfn $"Double value from literal: {fromLiteral,29:R}"
printfn $"Double value from variable: {fromVariable,28:R}"
printfn $"Double value from Parse method: {fromParse,24:R}"
// On 32-bit versions of the .NET Framework, the output is:
// Double value from literal: -4.42330604244772E-305
// Double value from variable: -4.42330604244772E-305
// Double value from Parse method: -4.42330604244772E-305
//
// On other versions of the .NET Framework, the output is:
// Double value from literal: -4.4233060424477198E-305
// Double value from variable: -4.4233060424477198E-305
// Double value from Parse method: -4.42330604244772E-305
Dim value As Double = -4.4233060424477198E-305
Dim fromLiteral As Double = -4.4233060424477198E-305
Dim fromVariable As Double = value
Dim fromParse As Double = Double.Parse("-4.42330604244772E-305")
Console.WriteLine("Double value from literal: {0,29:R}", fromLiteral)
Console.WriteLine("Double value from variable: {0,28:R}", fromVariable)
Console.WriteLine("Double value from Parse method: {0,24:R}", fromParse)
' The output is:
' Double value from literal: -4.42330604244772E-305
' Double value from variable: -4.42330604244772E-305
' Double value from Parse method: -4.42330604244772E-305
Uji kesetaraan
Agar dianggap sama, dua nilai Double harus mewakili nilai yang identik. Namun, karena perbedaan presisi antara nilai, atau karena hilangnya presisi oleh satu atau kedua nilai, nilai floating-point yang diharapkan identik sering kali berubah menjadi tidak sama karena perbedaan digit yang paling tidak signifikan. Akibatnya, memanggil ke metode Equals untuk menentukan apakah dua nilai sama, atau memanggil ke metode CompareTo untuk menentukan hubungan antara dua nilai Double, sering kali menghasilkan hasil yang tidak terduga. Ini terbukti dalam contoh berikut, di mana dua nilai yang tampaknya sama Double ternyata tidak sama karena yang pertama memiliki presisi 15 digit, sedangkan yang kedua memiliki 17.
using System;
public class Example
{
public static void Main()
{
double value1 = .333333333333333;
double value2 = 1.0/3;
Console.WriteLine($"{value1} = {value2}: {value1.Equals(value2)}");
}
}
// The example displays the following output:
// 0.333333333333333 = 0.33333333333333331: False
open System
let value1 = 0.333333333333333
let value2 = 1. / 3.
printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
// The example displays the following output:
// 0.333333333333333 = 0.33333333333333331: False
Module Example1
Public Sub Run()
Dim value1 As Double = 0.333333333333333
Dim value2 As Double = 1 / 3
Console.WriteLine("{0} = {1}: {2}", value1, value2, value1.Equals(value2))
End Sub
End Module
' The example displays the following output:
' 0.333333333333333 = 0.33333333333333331: False
Dalam kasus di mana hilangnya presisi kemungkinan akan memengaruhi hasil perbandingan, Anda dapat mengadopsi salah satu alternatif berikut untuk memanggil Equals metode atau CompareTo :
Panggil metode Math.Round untuk memastikan bahwa kedua nilai memiliki presisi yang sama. Contoh berikut memodifikasi contoh sebelumnya untuk menggunakan pendekatan ini sehingga dua nilai pecahan setara.
double value1 = .333333333333333; double value2 = 1.0 / 3; int precision = 7; value1 = Math.Round(value1, precision); value2 = Math.Round(value2, precision); Console.WriteLine($"{value1} = {value2}: {value1.Equals(value2)}"); // The example displays the following output: // 0.3333333 = 0.3333333: Trueopen System let v1 = 0.333333333333333 let v2 = 1. / 3. let precision = 7 let value1 = Math.Round(v1, precision) let value2 = Math.Round(v2, precision) printfn $"{value1:R} = {value2:R}: {value1.Equals value2}" // The example displays the following output: // 0.3333333 = 0.3333333: TrueModule Example3 Public Sub Run() Dim value1 As Double = 0.333333333333333 Dim value2 As Double = 1 / 3 Dim precision As Integer = 7 value1 = Math.Round(value1, precision) value2 = Math.Round(value2, precision) Console.WriteLine("{0} = {1}: {2}", value1, value2, value1.Equals(value2)) End Sub End Module ' The example displays the following output: ' 0.3333333 = 0.3333333: TrueMasalah presisi masih berlaku untuk pembulatan nilai titik tengah. Untuk informasi selengkapnya, lihat metode Math.Round(Double, Int32, MidpointRounding).
Uji kemiripan kesetaraan daripada kesetaraan. Ini mengharuskan Anda menentukan jumlah absolut di mana kedua nilai dapat berbeda tetapi masih sama, atau Anda menentukan jumlah relatif di mana nilai yang lebih kecil dapat berbeda dari nilai yang lebih besar.
Warning
Double.Epsilon terkadang digunakan sebagai ukuran absolut jarak antara dua nilai Double saat menguji kesetaraan. Namun, Double.Epsilon mengukur nilai sekecil mungkin yang dapat ditambahkan, atau dikurangi dari, Double yang nilainya nol. Untuk nilai Double paling positif dan negatif, nilai Double.Epsilon terlalu kecil untuk dideteksi. Oleh karena itu, kecuali untuk nilai yang nol, kami tidak merekomendasikan penggunaannya dalam pengujian untuk kesetaraan.
Contoh berikut menggunakan pendekatan terakhir untuk menentukan metode
IsApproximatelyEqualyang menguji perbedaan relatif antara dua nilai. Metode membagi denganMath.Max(value1, value2)sehingga membuat perbandingan relatif terhadap yang lebih besar (berdasarkan besarnya) dari kedua nilai, yang menempatkan hasil dalam urutan besaran yang tepat. JikaMath.Maxmengembalikan nol (yang terjadi ketika satu nilai adalah nol dan nilai lainnya negatif), metode akan kembaliMath.Min(value1, value2)menggunakan nilai bukan nol sebagai pembagi. Ini juga membandingkan hasil dari panggilan ke metodeIsApproximatelyEqualdan metode Equals(Double).using System; public class Example3 { public static void Main() { double one1 = .1 * 10; double one2 = 0; for (int ctr = 1; ctr <= 10; ctr++) one2 += .1; Console.WriteLine($"{one1} = {one2}: {one1.Equals(one2)}"); Console.WriteLine($"{one1} is approximately equal to {one2}: {IsApproximatelyEqual(one1, one2, .000000001)}"); } static bool IsApproximatelyEqual(double value1, double value2, double epsilon) { // If they are equal anyway, just return True. if (value1.Equals(value2)) return true; // Handle NaN, Infinity. if (Double.IsInfinity(value1) | Double.IsNaN(value1)) return value1.Equals(value2); else if (Double.IsInfinity(value2) | Double.IsNaN(value2)) return value1.Equals(value2); // Handle zero to avoid division by zero double divisor = Math.Max(value1, value2); if (divisor.Equals(0)) divisor = Math.Min(value1, value2); return Math.Abs((value1 - value2) / divisor) <= epsilon; } } // The example displays the following output: // 1 = 0.99999999999999989: False // 1 is approximately equal to 0.99999999999999989: Trueopen System let isApproximatelyEqual (value1: double) (value2: double) (epsilon: double) = // If they are equal anyway, just return True. if value1.Equals value2 then true else // Handle NaN, Infinity. if Double.IsInfinity value1 || Double.IsNaN value1 then value1.Equals value2 elif Double.IsInfinity value2 || Double.IsNaN value2 then value1.Equals value2 else // Handle zero to avoid division by zero let divisor = max value1 value2 let divisor = if divisor.Equals 0 then min value1 value2 else divisor abs ((value1 - value2) / divisor) <= epsilon let one1 = 0.1 * 10. let mutable one2 = 0. for _ = 1 to 10 do one2 <- one2 + 0.1 printfn $"{one1:R} = {one2:R}: {one1.Equals one2}" printfn $"{one1:R} is approximately equal to {one2:R}: {isApproximatelyEqual one1 one2 0.000000001}" // The example displays the following output: // 1 = 0.99999999999999989: False // 1 is approximately equal to 0.99999999999999989: TrueModule Example4 Public Sub Run() Dim one1 As Double = 0.1 * 10 Dim one2 As Double = 0 For ctr As Integer = 1 To 10 one2 += 0.1 Next Console.WriteLine("{0} = {1}: {2}", one1, one2, one1.Equals(one2)) Console.WriteLine("{0} is approximately equal to {1}: {2}", one1, one2, IsApproximatelyEqual(one1, one2, 0.000000001)) End Sub Function IsApproximatelyEqual(value1 As Double, value2 As Double, epsilon As Double) As Boolean ' If they are equal anyway, just return True. If value1.Equals(value2) Then Return True ' Handle NaN, Infinity. If Double.IsInfinity(value1) Or Double.IsNaN(value1) Then Return value1.Equals(value2) ElseIf Double.IsInfinity(value2) Or Double.IsNaN(value2) Then Return value1.Equals(value2) End If ' Handle zero to avoid division by zero Dim divisor As Double = Math.Max(value1, value2) If divisor.Equals(0) Then divisor = Math.Min(value1, value2) End If Return Math.Abs((value1 - value2) / divisor) <= epsilon End Function End Module ' The example displays the following output: ' 1 = 0.99999999999999989: False ' 1 is approximately equal to 0.99999999999999989: True
Nilai floating-point dan pengecualiannya
Tidak seperti operasi dengan jenis integral, yang melempar DivideByZeroException untuk pembagian dengan nol atau OverflowException untuk luapan dalam konteks yang diperiksa, operasi dengan nilai floating-point tidak melemparkan pengecualian. Sebaliknya, dalam situasi yang luar biasa, hasil dari operasi floating-point adalah nol, tak terhingga positif, tak terhingga negatif, atau bukan angka (NaN).
Jika hasil operasi floating-point terlalu kecil untuk format tujuan, hasilnya adalah nol. Ini dapat terjadi ketika dua angka yang sangat kecil dikalikan, seperti yang ditunjukkan contoh berikut.
using System; public class Example6 { public static void Main() { Double value1 = 1.1632875981534209e-225; Double value2 = 9.1642346778e-175; Double result = value1 * value2; Console.WriteLine($"{value1} * {value2} = {result}"); Console.WriteLine($"{result} = 0: {result.Equals(0.0)}"); } } // The example displays the following output: // 1.16328759815342E-225 * 9.1642346778E-175 = 0 // 0 = 0: Truelet value1 = 1.1632875981534209e-225 let value2 = 9.1642346778e-175 let result = value1 * value2 printfn $"{value1} * {value2} = {result}" printfn $"{result} = 0: {result.Equals 0.0}" // The example displays the following output: // 1.16328759815342E-225 * 9.1642346778E-175 = 0 // 0 = 0: TrueModule Example7 Public Sub Run() Dim value1 As Double = 1.1632875981534209E-225 Dim value2 As Double = 9.1642346778E-175 Dim result As Double = value1 * value2 Console.WriteLine("{0} * {1} = {2}", value1, value2, result) Console.WriteLine("{0} = 0: {1}", result, result.Equals(0.0)) End Sub End Module ' The example displays the following output: ' 1.16328759815342E-225 * 9.1642346778E-175 = 0 ' 0 = 0: TrueJika besarnya hasil operasi floating-point melebihi rentang format tujuan, hasil operasi adalah PositiveInfinity atau NegativeInfinity, sebagaimana mestinya untuk tanda hasil. Hasil operasi yang meluap adalah Double.MaxValue adalah PositiveInfinity, dan hasil operasi yang meluap adalah Double.MinValue adalah NegativeInfinity, sebagaimana ditampilkan dalam contoh berikut.
using System; public class Example7 { public static void Main() { Double value1 = 4.565e153; Double value2 = 6.9375e172; Double result = value1 * value2; Console.WriteLine($"PositiveInfinity: {Double.IsPositiveInfinity(result)}"); Console.WriteLine($"NegativeInfinity: {Double.IsNegativeInfinity(result)}{Environment.NewLine}"); value1 = -value1; result = value1 * value2; Console.WriteLine($"PositiveInfinity: {Double.IsPositiveInfinity(result)}"); Console.WriteLine($"NegativeInfinity: {Double.IsNegativeInfinity(result)}"); } } // The example displays the following output: // PositiveInfinity: True // NegativeInfinity: False // // PositiveInfinity: False // NegativeInfinity: Trueopen System let value1 = 4.565e153 let value2 = 6.9375e172 let result = value1 * value2 printfn $"PositiveInfinity: {Double.IsPositiveInfinity result}" printfn $"NegativeInfinity: {Double.IsNegativeInfinity result}\n" let value3 = - value1 let result2 = value2 * value3 printfn $"PositiveInfinity: {Double.IsPositiveInfinity result2}" printfn $"NegativeInfinity: {Double.IsNegativeInfinity result2}" // The example displays the following output: // PositiveInfinity: True // NegativeInfinity: False // // PositiveInfinity: False // NegativeInfinity: TrueModule Example8 Public Sub Run() Dim value1 As Double = 4.565E+153 Dim value2 As Double = 6.9375E+172 Dim result As Double = value1 * value2 Console.WriteLine("PositiveInfinity: {0}", Double.IsPositiveInfinity(result)) Console.WriteLine("NegativeInfinity: {0}", Double.IsNegativeInfinity(result)) Console.WriteLine() value1 = -value1 result = value1 * value2 Console.WriteLine("PositiveInfinity: {0}", Double.IsPositiveInfinity(result)) Console.WriteLine("NegativeInfinity: {0}", Double.IsNegativeInfinity(result)) End Sub End Module ' The example displays the following output: ' PositiveInfinity: True ' NegativeInfinity: False ' ' PositiveInfinity: False ' NegativeInfinity: TruePositiveInfinity juga dihasilkan dari pembagian sebesar nol dengan dividen positif, dan NegativeInfinity hasil dari pembagian dengan nol dengan dividen negatif.
Jika sebuah operasi floating-point tidak sah, hasil operasinya adalah NaN. Misalnya, NaN hasil dari operasi berikut:
Pembagian nol dengan dividen nol. Perhatikan bahwa kasus pembagian lainnya dengan nol menghasilkan PositiveInfinity atau NegativeInfinity.
Setiap operasi floating-point dengan input yang tidak valid. Misalnya, memanggil Math.Sqrt metode dengan nilai negatif mengembalikan NaN, seperti halnya Math.Acos memanggil metode dengan nilai yang lebih besar dari satu atau kurang dari yang negatif.
Setiap operasi dengan argumen yang nilainya Double.NaN.
Konversi tipe atau jenis
Struktur Double tidak menentukan operator konversi eksplisit atau implisit; sebaliknya, konversi diimplementasikan oleh pengkompilasi.
Konversi nilai tipe numerik primitif ke Double adalah konversi yang melebar dan oleh karena itu tidak memerlukan operator casting eksplisit atau panggilan ke metode konversi kecuali kompilator memintanya secara eksplisit. Misalnya, pengkompilasi C# memerlukan operator casting untuk konversi dari Decimal ke Double, sementara pengkompilasi Visual Basic tidak. Contoh berikut mengonversi nilai minimum atau maksimum jenis numerik primitif lainnya menjadi Double.
dynamic[] values = { Byte.MinValue, Byte.MaxValue, Decimal.MinValue,
Decimal.MaxValue, Int16.MinValue, Int16.MaxValue,
Int32.MinValue, Int32.MaxValue, Int64.MinValue,
Int64.MaxValue, SByte.MinValue, SByte.MaxValue,
Single.MinValue, Single.MaxValue, UInt16.MinValue,
UInt16.MaxValue, UInt32.MinValue, UInt32.MaxValue,
UInt64.MinValue, UInt64.MaxValue };
double dblValue;
foreach (dynamic value in values)
{
if (value.GetType() == typeof(decimal))
dblValue = (double)value;
else
dblValue = value;
Console.WriteLine($"{value} ({value.GetType().Name}) --> " +
$"{dblValue:R} ({dblValue.GetType().Name})");
}
// The example displays the following output:
// 0 (Byte) --> 0 (Double)
// 255 (Byte) --> 255 (Double)
// -79228162514264337593543950335 (Decimal) --> -7.9228162514264338E+28 (Double)
// 79228162514264337593543950335 (Decimal) --> 7.9228162514264338E+28 (Double)
// -32768 (Int16) --> -32768 (Double)
// 32767 (Int16) --> 32767 (Double)
// -2147483648 (Int32) --> -2147483648 (Double)
// 2147483647 (Int32) --> 2147483647 (Double)
// -9223372036854775808 (Int64) --> -9.2233720368547758E+18 (Double)
// 9223372036854775807 (Int64) --> 9.2233720368547758E+18 (Double)
// -128 (SByte) --> -128 (Double)
// 127 (SByte) --> 127 (Double)
// -3.402823E+38 (Single) --> -3.4028234663852886E+38 (Double)
// 3.402823E+38 (Single) --> 3.4028234663852886E+38 (Double)
// 0 (UInt16) --> 0 (Double)
// 65535 (UInt16) --> 65535 (Double)
// 0 (UInt32) --> 0 (Double)
// 4294967295 (UInt32) --> 4294967295 (Double)
// 0 (UInt64) --> 0 (Double)
// 18446744073709551615 (UInt64) --> 1.8446744073709552E+19 (Double)
open System
let values: obj[] =
[| Byte.MinValue; Byte.MaxValue; Decimal.MinValue
Decimal.MaxValue; Int16.MinValue; Int16.MaxValue
Int32.MinValue; Int32.MaxValue; Int64.MinValue
Int64.MaxValue; SByte.MinValue; SByte.MaxValue
Single.MinValue; Single.MaxValue; UInt16.MinValue
UInt16.MaxValue; UInt32.MinValue, UInt32.MaxValue
UInt64.MinValue; UInt64.MaxValue |]
for value in values do
let dblValue = value :?> double
printfn $"{value} ({value.GetType().Name}) --> {dblValue:R} ({dblValue.GetType().Name})"
// The example displays the following output:
// 0 (Byte) --> 0 (Double)
// 255 (Byte) --> 255 (Double)
// -79228162514264337593543950335 (Decimal) --> -7.9228162514264338E+28 (Double)
// 79228162514264337593543950335 (Decimal) --> 7.9228162514264338E+28 (Double)
// -32768 (Int16) --> -32768 (Double)
// 32767 (Int16) --> 32767 (Double)
// -2147483648 (Int32) --> -2147483648 (Double)
// 2147483647 (Int32) --> 2147483647 (Double)
// -9223372036854775808 (Int64) --> -9.2233720368547758E+18 (Double)
// 9223372036854775807 (Int64) --> 9.2233720368547758E+18 (Double)
// -128 (SByte) --> -128 (Double)
// 127 (SByte) --> 127 (Double)
// -3.402823E+38 (Single) --> -3.4028234663852886E+38 (Double)
// 3.402823E+38 (Single) --> 3.4028234663852886E+38 (Double)
// 0 (UInt16) --> 0 (Double)
// 65535 (UInt16) --> 65535 (Double)
// 0 (UInt32) --> 0 (Double)
// 4294967295 (UInt32) --> 4294967295 (Double)
// 0 (UInt64) --> 0 (Double)
// 18446744073709551615 (UInt64) --> 1.8446744073709552E+19 (Double)
Module Example5
Public Sub Run()
Dim values() As Object = {Byte.MinValue, Byte.MaxValue, Decimal.MinValue,
Decimal.MaxValue, Int16.MinValue, Int16.MaxValue,
Int32.MinValue, Int32.MaxValue, Int64.MinValue,
Int64.MaxValue, SByte.MinValue, SByte.MaxValue,
Single.MinValue, Single.MaxValue, UInt16.MinValue,
UInt16.MaxValue, UInt32.MinValue, UInt32.MaxValue,
UInt64.MinValue, UInt64.MaxValue}
Dim dblValue As Double
For Each value In values
dblValue = value
Console.WriteLine("{0} ({1}) --> {2:R} ({3})",
value, value.GetType().Name,
dblValue, dblValue.GetType().Name)
Next
End Sub
End Module
' The example displays the following output:
' 0 (Byte) --> 0 (Double)
' 255 (Byte) --> 255 (Double)
' -79228162514264337593543950335 (Decimal) --> -7.9228162514264338E+28 (Double)
' 79228162514264337593543950335 (Decimal) --> 7.9228162514264338E+28 (Double)
' -32768 (Int16) --> -32768 (Double)
' 32767 (Int16) --> 32767 (Double)
' -2147483648 (Int32) --> -2147483648 (Double)
' 2147483647 (Int32) --> 2147483647 (Double)
' -9223372036854775808 (Int64) --> -9.2233720368547758E+18 (Double)
' 9223372036854775807 (Int64) --> 9.2233720368547758E+18 (Double)
' -128 (SByte) --> -128 (Double)
' 127 (SByte) --> 127 (Double)
' -3.402823E+38 (Single) --> -3.4028234663852886E+38 (Double)
' 3.402823E+38 (Single) --> 3.4028234663852886E+38 (Double)
' 0 (UInt16) --> 0 (Double)
' 65535 (UInt16) --> 65535 (Double)
' 0 (UInt32) --> 0 (Double)
' 4294967295 (UInt32) --> 4294967295 (Double)
' 0 (UInt64) --> 0 (Double)
' 18446744073709551615 (UInt64) --> 1.8446744073709552E+19 (Double)
Selain itu, nilai SingleSingle.NaN, Single.PositiveInfinity, dan Single.NegativeInfinity dikonversi ke Double.NaN, Double.PositiveInfinity, dan Double.NegativeInfinity, masing-masing.
Perhatikan bahwa konversi nilai beberapa jenis numerik ke nilai Double dapat melibatkan hilangnya presisi. Seperti yang diilustrasikan, hilangnya presisi dimungkinkan saat mengonversi nilai Decimal, Int64, dan UInt64 menjadi nilai Double, sebagaimana ditunjukkan oleh contoh.
Konversi nilai Double ke nilai jenis data numerik primitif lainnya adalah konversi yang menyempit dan memerlukan operator cast (dalam C#), metode konversi (dalam Visual Basic), atau panggilan ke metode Convert. Nilai yang berada di luar rentang tipe data target, yang ditentukan oleh properti MinValue dan MaxValue jenis target, berulah seperti yang ditunjukkan dalam tabel berikut.
| Jenis target | Result |
|---|---|
| Jenis integral apa pun | Pengecualian OverflowException jika konversi terjadi dalam konteks yang diperiksa. Jika konversi terjadi dalam konteks yang tidak dicentang (default dalam C#), operasi konversi berhasil tetapi nilai meluap. |
| Decimal | Sebuah pengecualian OverflowException. |
| Single |
Single.NegativeInfinity untuk nilai negatif. Single.PositiveInfinity untuk nilai positif. |
Selain itu, Double.NaN, Double.PositiveInfinity, dan Double.NegativeInfinity melemparkan OverflowException untuk konversi ke bilangan bulat dalam konteks yang diperiksa, tetapi nilai-nilai ini meluap saat dikonversi ke bilangan bulat dalam konteks yang tidak dicentang. Untuk konversi ke Decimal, mereka selalu melemparkan OverflowException. Untuk konversi ke Single, mereka masing-masing dikonversi ke Single.NaN, Single.PositiveInfinity, dan Single.NegativeInfinity.
Hilangnya presisi dapat mengakibatkan konversi Double nilai ke jenis numerik lain. Dalam kasus konversi ke salah satu jenis integral, seperti yang ditunjukkan output dari contoh, komponen pecahan hilang ketika nilai Double dibulatkan (seperti dalam Visual Basic) atau dipotong (seperti dalam C#). Untuk konversi ke nilai Decimal dan Single, nilai Double mungkin tidak memiliki representasi yang tepat dalam jenis data target.
Contoh berikut mengonversi sejumlah nilai Double ke beberapa jenis numerik lainnya. Konversi terjadi dalam konteks yang diperiksa dalam Visual Basic (default), di C# (karena kata kunci checked), dan di F# (karena Modul Checked). Output dari contoh menunjukkan hasil untuk konversi dalam konteks yang dicentang dan tidak dicentang. Anda dapat melakukan konversi dalam konteks yang tidak dicentang di Visual Basic dengan mengkompilasi dengan sakelar kompilator /removeintchecks+, di C# dengan mengomentari pernyataan checked, dan di F# dengan mengomentari pernyataan open Checked.
using System;
public class Example5
{
public static void Main()
{
Double[] values = { Double.MinValue, -67890.1234, -12345.6789,
12345.6789, 67890.1234, Double.MaxValue,
Double.NaN, Double.PositiveInfinity,
Double.NegativeInfinity };
checked
{
foreach (var value in values)
{
try
{
Int64 lValue = (long)value;
Console.WriteLine($"{value} ({value.GetType().Name}) --> {lValue} (0x{lValue:X16}) ({lValue.GetType().Name})");
}
catch (OverflowException)
{
Console.WriteLine($"Unable to convert {value} to Int64.");
}
try
{
UInt64 ulValue = (ulong)value;
Console.WriteLine($"{value} ({value.GetType().Name}) --> {ulValue} (0x{ulValue:X16}) ({ulValue.GetType().Name})");
}
catch (OverflowException)
{
Console.WriteLine($"Unable to convert {value} to UInt64.");
}
try
{
Decimal dValue = (decimal)value;
Console.WriteLine($"{value} ({value.GetType().Name}) --> {dValue} ({dValue.GetType().Name})");
}
catch (OverflowException)
{
Console.WriteLine($"Unable to convert {value} to Decimal.");
}
try
{
Single sValue = (float)value;
Console.WriteLine($"{value} ({value.GetType().Name}) --> {sValue} ({sValue.GetType().Name})");
}
catch (OverflowException)
{
Console.WriteLine($"Unable to convert {value} to Single.");
}
Console.WriteLine();
}
}
}
}
// The example displays the following output for conversions performed
// in a checked context:
// Unable to convert -1.79769313486232E+308 to Int64.
// Unable to convert -1.79769313486232E+308 to UInt64.
// Unable to convert -1.79769313486232E+308 to Decimal.
// -1.79769313486232E+308 (Double) --> -Infinity (Single)
//
// -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
// Unable to convert -67890.1234 to UInt64.
// -67890.1234 (Double) --> -67890.1234 (Decimal)
// -67890.1234 (Double) --> -67890.13 (Single)
//
// -12345.6789 (Double) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
// Unable to convert -12345.6789 to UInt64.
// -12345.6789 (Double) --> -12345.6789 (Decimal)
// -12345.6789 (Double) --> -12345.68 (Single)
//
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (Int64)
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (UInt64)
// 12345.6789 (Double) --> 12345.6789 (Decimal)
// 12345.6789 (Double) --> 12345.68 (Single)
//
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
// 67890.1234 (Double) --> 67890.1234 (Decimal)
// 67890.1234 (Double) --> 67890.13 (Single)
//
// Unable to convert 1.79769313486232E+308 to Int64.
// Unable to convert 1.79769313486232E+308 to UInt64.
// Unable to convert 1.79769313486232E+308 to Decimal.
// 1.79769313486232E+308 (Double) --> Infinity (Single)
//
// Unable to convert NaN to Int64.
// Unable to convert NaN to UInt64.
// Unable to convert NaN to Decimal.
// NaN (Double) --> NaN (Single)
//
// Unable to convert Infinity to Int64.
// Unable to convert Infinity to UInt64.
// Unable to convert Infinity to Decimal.
// Infinity (Double) --> Infinity (Single)
//
// Unable to convert -Infinity to Int64.
// Unable to convert -Infinity to UInt64.
// Unable to convert -Infinity to Decimal.
// -Infinity (Double) --> -Infinity (Single)
// The example displays the following output for conversions performed
// in an unchecked context:
// -1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// -1.79769313486232E+308 (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
// Unable to convert -1.79769313486232E+308 to Decimal.
// -1.79769313486232E+308 (Double) --> -Infinity (Single)
//
// -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
// -67890.1234 (Double) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
// -67890.1234 (Double) --> -67890.1234 (Decimal)
// -67890.1234 (Double) --> -67890.13 (Single)
//
// -12345.6789 (Double) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
// -12345.6789 (Double) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (UInt64)
// -12345.6789 (Double) --> -12345.6789 (Decimal)
// -12345.6789 (Double) --> -12345.68 (Single)
//
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (Int64)
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (UInt64)
// 12345.6789 (Double) --> 12345.6789 (Decimal)
// 12345.6789 (Double) --> 12345.68 (Single)
//
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
// 67890.1234 (Double) --> 67890.1234 (Decimal)
// 67890.1234 (Double) --> 67890.13 (Single)
//
// 1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// 1.79769313486232E+308 (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert 1.79769313486232E+308 to Decimal.
// 1.79769313486232E+308 (Double) --> Infinity (Single)
//
// NaN (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// NaN (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert NaN to Decimal.
// NaN (Double) --> NaN (Single)
//
// Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// Infinity (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert Infinity to Decimal.
// Infinity (Double) --> Infinity (Single)
//
// -Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// -Infinity (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
// Unable to convert -Infinity to Decimal.
// -Infinity (Double) --> -Infinity (Single)
open System
open Checked
let values =
[| Double.MinValue; -67890.1234; -12345.6789
12345.6789; 67890.1234; Double.MaxValue
Double.NaN; Double.PositiveInfinity;
Double.NegativeInfinity |]
for value in values do
try
let lValue = int64 value
printfn $"{value} ({value.GetType().Name}) --> {lValue} (0x{lValue:X16}) ({lValue.GetType().Name})"
with :? OverflowException ->
printfn $"Unable to convert {value} to Int64."
try
let ulValue = uint64 value
printfn $"{value} ({value.GetType().Name}) --> {ulValue} (0x{ulValue:X16}) ({ulValue.GetType().Name})"
with :? OverflowException ->
printfn $"Unable to convert {value} to UInt64."
try
let dValue = decimal value
printfn $"{value} ({value.GetType().Name}) --> {dValue} ({dValue.GetType().Name})"
with :? OverflowException ->
printfn $"Unable to convert {value} to Decimal."
try
let sValue = float32 value
printfn $"{value} ({value.GetType().Name}) --> {sValue} ({sValue.GetType().Name})"
with :? OverflowException ->
printfn $"Unable to convert {value} to Single."
printfn ""
// The example displays the following output for conversions performed
// in a checked context:
// Unable to convert -1.79769313486232E+308 to Int64.
// Unable to convert -1.79769313486232E+308 to UInt64.
// Unable to convert -1.79769313486232E+308 to Decimal.
// -1.79769313486232E+308 (Double) --> -Infinity (Single)
//
// -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
// Unable to convert -67890.1234 to UInt64.
// -67890.1234 (Double) --> -67890.1234 (Decimal)
// -67890.1234 (Double) --> -67890.13 (Single)
//
// -12345.6789 (Double) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
// Unable to convert -12345.6789 to UInt64.
// -12345.6789 (Double) --> -12345.6789 (Decimal)
// -12345.6789 (Double) --> -12345.68 (Single)
//
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (Int64)
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (UInt64)
// 12345.6789 (Double) --> 12345.6789 (Decimal)
// 12345.6789 (Double) --> 12345.68 (Single)
//
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
// 67890.1234 (Double) --> 67890.1234 (Decimal)
// 67890.1234 (Double) --> 67890.13 (Single)
//
// Unable to convert 1.79769313486232E+308 to Int64.
// Unable to convert 1.79769313486232E+308 to UInt64.
// Unable to convert 1.79769313486232E+308 to Decimal.
// 1.79769313486232E+308 (Double) --> Infinity (Single)
//
// Unable to convert NaN to Int64.
// Unable to convert NaN to UInt64.
// Unable to convert NaN to Decimal.
// NaN (Double) --> NaN (Single)
//
// Unable to convert Infinity to Int64.
// Unable to convert Infinity to UInt64.
// Unable to convert Infinity to Decimal.
// Infinity (Double) --> Infinity (Single)
//
// Unable to convert -Infinity to Int64.
// Unable to convert -Infinity to UInt64.
// Unable to convert -Infinity to Decimal.
// -Infinity (Double) --> -Infinity (Single)
// The example displays the following output for conversions performed
// in an unchecked context:
// -1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// -1.79769313486232E+308 (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
// Unable to convert -1.79769313486232E+308 to Decimal.
// -1.79769313486232E+308 (Double) --> -Infinity (Single)
//
// -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
// -67890.1234 (Double) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
// -67890.1234 (Double) --> -67890.1234 (Decimal)
// -67890.1234 (Double) --> -67890.13 (Single)
//
// -12345.6789 (Double) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
// -12345.6789 (Double) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (UInt64)
// -12345.6789 (Double) --> -12345.6789 (Decimal)
// -12345.6789 (Double) --> -12345.68 (Single)
//
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (Int64)
// 12345.6789 (Double) --> 12345 (0x0000000000003039) (UInt64)
// 12345.6789 (Double) --> 12345.6789 (Decimal)
// 12345.6789 (Double) --> 12345.68 (Single)
//
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
// 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
// 67890.1234 (Double) --> 67890.1234 (Decimal)
// 67890.1234 (Double) --> 67890.13 (Single)
//
// 1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// 1.79769313486232E+308 (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert 1.79769313486232E+308 to Decimal.
// 1.79769313486232E+308 (Double) --> Infinity (Single)
//
// NaN (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// NaN (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert NaN to Decimal.
// NaN (Double) --> NaN (Single)
//
// Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// Infinity (Double) --> 0 (0x0000000000000000) (UInt64)
// Unable to convert Infinity to Decimal.
// Infinity (Double) --> Infinity (Single)
//
// -Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
// -Infinity (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
// Unable to convert -Infinity to Decimal.
// -Infinity (Double) --> -Infinity (Single)
Module Example6
Public Sub Run()
Dim values() As Double = {Double.MinValue, -67890.1234, -12345.6789,
12345.6789, 67890.1234, Double.MaxValue,
Double.NaN, Double.PositiveInfinity,
Double.NegativeInfinity}
For Each value In values
Try
Dim lValue As Int64 = CLng(value)
Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
value, value.GetType().Name,
lValue, lValue.GetType().Name)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0} to Int64.", value)
End Try
Try
Dim ulValue As UInt64 = CULng(value)
Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
value, value.GetType().Name,
ulValue, ulValue.GetType().Name)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0} to UInt64.", value)
End Try
Try
Dim dValue As Decimal = CDec(value)
Console.WriteLine("{0} ({1}) --> {2} ({3})",
value, value.GetType().Name,
dValue, dValue.GetType().Name)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0} to Decimal.", value)
End Try
Try
Dim sValue As Single = CSng(value)
Console.WriteLine("{0} ({1}) --> {2} ({3})",
value, value.GetType().Name,
sValue, sValue.GetType().Name)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0} to Single.", value)
End Try
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output for conversions performed
' in a checked context:
' Unable to convert -1.79769313486232E+308 to Int64.
' Unable to convert -1.79769313486232E+308 to UInt64.
' Unable to convert -1.79769313486232E+308 to Decimal.
' -1.79769313486232E+308 (Double) --> -Infinity (Single)
'
' -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
' Unable to convert -67890.1234 to UInt64.
' -67890.1234 (Double) --> -67890.1234 (Decimal)
' -67890.1234 (Double) --> -67890.13 (Single)
'
' -12345.6789 (Double) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
' Unable to convert -12345.6789 to UInt64.
' -12345.6789 (Double) --> -12345.6789 (Decimal)
' -12345.6789 (Double) --> -12345.68 (Single)
'
' 12345.6789 (Double) --> 12346 (0x000000000000303A) (Int64)
' 12345.6789 (Double) --> 12346 (0x000000000000303A) (UInt64)
' 12345.6789 (Double) --> 12345.6789 (Decimal)
' 12345.6789 (Double) --> 12345.68 (Single)
'
' 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
' 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
' 67890.1234 (Double) --> 67890.1234 (Decimal)
' 67890.1234 (Double) --> 67890.13 (Single)
'
' Unable to convert 1.79769313486232E+308 to Int64.
' Unable to convert 1.79769313486232E+308 to UInt64.
' Unable to convert 1.79769313486232E+308 to Decimal.
' 1.79769313486232E+308 (Double) --> Infinity (Single)
'
' Unable to convert NaN to Int64.
' Unable to convert NaN to UInt64.
' Unable to convert NaN to Decimal.
' NaN (Double) --> NaN (Single)
'
' Unable to convert Infinity to Int64.
' Unable to convert Infinity to UInt64.
' Unable to convert Infinity to Decimal.
' Infinity (Double) --> Infinity (Single)
'
' Unable to convert -Infinity to Int64.
' Unable to convert -Infinity to UInt64.
' Unable to convert -Infinity to Decimal.
' -Infinity (Double) --> -Infinity (Single)
' The example displays the following output for conversions performed
' in an unchecked context:
' -1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
' -1.79769313486232E+308 (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
' Unable to convert -1.79769313486232E+308 to Decimal.
' -1.79769313486232E+308 (Double) --> -Infinity (Single)
'
' -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
' -67890.1234 (Double) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
' -67890.1234 (Double) --> -67890.1234 (Decimal)
' -67890.1234 (Double) --> -67890.13 (Single)
'
' -12345.6789 (Double) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
' -12345.6789 (Double) --> 18446744073709539270 (0xFFFFFFFFFFFFCFC6) (UInt64)
' -12345.6789 (Double) --> -12345.6789 (Decimal)
' -12345.6789 (Double) --> -12345.68 (Single)
'
' 12345.6789 (Double) --> 12346 (0x000000000000303A) (Int64)
' 12345.6789 (Double) --> 12346 (0x000000000000303A) (UInt64)
' 12345.6789 (Double) --> 12345.6789 (Decimal)
' 12345.6789 (Double) --> 12345.68 (Single)
'
' 67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
' 67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
' 67890.1234 (Double) --> 67890.1234 (Decimal)
' 67890.1234 (Double) --> 67890.13 (Single)
'
' 1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
' 1.79769313486232E+308 (Double) --> 0 (0x0000000000000000) (UInt64)
' Unable to convert 1.79769313486232E+308 to Decimal.
' 1.79769313486232E+308 (Double) --> Infinity (Single)
'
' NaN (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
' NaN (Double) --> 0 (0x0000000000000000) (UInt64)
' Unable to convert NaN to Decimal.
' NaN (Double) --> NaN (Single)
'
' Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
' Infinity (Double) --> 0 (0x0000000000000000) (UInt64)
' Unable to convert Infinity to Decimal.
' Infinity (Double) --> Infinity (Single)
'
' -Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
' -Infinity (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
' Unable to convert -Infinity to Decimal.
' -Infinity (Double) --> -Infinity (Single)
Untuk informasi selengkapnya tentang konversi jenis numerik, lihat Konversi Jenis di .NET dan Tabel Konversi Tipe .
Fungsionalitas bilangan riil bergerak
Struktur Double dan jenis terkait menyediakan metode untuk melakukan operasi di area berikut:
Perbandingan nilai. Anda dapat memanggil metode Equals untuk menentukan apakah dua nilai Double sama, atau metode CompareTo untuk menentukan hubungan antara dua nilai.
Struktur Double juga mendukung serangkaian operator perbandingan lengkap. Misalnya, Anda dapat menguji kesetaraan atau ketidaksetaraan, atau menentukan apakah satu nilai lebih besar dari atau sama dengan nilai lainnya. Jika salah satu operand adalah jenis numerik selain Double, itu dikonversi ke Double sebelum melakukan perbandingan.
Warning
Karena perbedaan presisi, dua Double nilai yang Anda harapkan sama mungkin berubah menjadi tidak sama, yang memengaruhi hasil perbandingan. Untuk informasi tentang membandingkan dua Double nilai, lihat bagian Uji untuk kesetaraan .
Anda juga dapat memanggil metode IsNaN, IsInfinity, IsPositiveInfinity, dan IsNegativeInfinity untuk menguji nilai khusus ini.
operasi matematika. Operasi aritmatika umum, seperti penambahan, pengurangan, perkalian, dan pembagian, diimplementasikan oleh pengkompilasi bahasa dan instruksi Common Intermediate Language (CIL), bukan dengan Double metode. Jika salah satu operand dalam operasi matematika adalah jenis numerik selain Double, itu dikonversi ke Double sebelum melakukan operasi. Hasil dari operasi juga merupakan nilai Double.
Operasi matematika lainnya dapat dilakukan dengan memanggil metode
static(Shareddalam Visual Basic) di kelas System.Math. Ini termasuk metode tambahan yang umum digunakan untuk aritmetika (seperti Math.Abs, , Math.Signdan Math.Sqrt), geometri (seperti Math.Cos dan Math.Sin), dan kalkulus (seperti Math.Log).Anda juga dapat memanipulasi bit individual dalam nilai Double. Metode BitConverter.DoubleToInt64Bits mengawetkan pola bit Double dari sebuah nilai dalam bilangan bulat 64-bit. Metode BitConverter.GetBytes(Double) mengembalikan pola bitnya dalam sebuah array byte.
Pembulatan. Pembulatan sering digunakan sebagai teknik untuk mengurangi dampak perbedaan antara nilai yang muncul akibat masalah representasi dan presisi floating-point. Anda dapat membulatkan nilai Double dengan memanggil metode Math.Round.
Pemformatan. Anda dapat mengonversi Double nilai ke representasi stringnya dengan memanggil ToString metode atau dengan menggunakan fitur pemformatan komposit. Untuk informasi tentang bagaimana string format mengontrol representasi string nilai floating-point, lihat String Format Numerik Standar dan String Format Numerik Kustom.
Mengurai teks. Anda dapat mengonversi representasi string dari nilai floating-point menjadi nilai Double dengan memanggil metode Parse atau TryParse. Jika operasi penguraian gagal, metode Parse melempar pengecualian, sedangkan metode TryParse mengembalikan
false.Konversi jenis. Struktur Double menyediakan implementasi antarmuka eksplisit untuk antarmuka IConvertible, yang mendukung konversi antara dua jenis data .NET standar. Pengkompilasi bahasa juga mendukung konversi implisit nilai dari semua jenis numerik standar lainnya ke Double nilai. Konversi nilai dari jenis numerik standar apa pun ke Double adalah konversi pelebaran dan tidak memerlukan penggunaan operator pengecoran atau metode konversi.
Namun, konversi nilai Int64 dan Single dapat melibatkan hilangnya presisi. Tabel berikut ini mencantumkan perbedaan presisi untuk masing-masing jenis ini:
Tipe Presisi maksimum Presisi internal Double 15 17 Int64 19 digit desimal 19 digit desimal Single 7 angka desimal 9 digit desimal Masalah presisi paling sering memengaruhi nilai Single yang dikonversi ke nilai Double. Dalam contoh berikut, dua nilai yang dihasilkan oleh operasi pembagian yang identik tidak sama karena salah satu nilainya adalah nilai floating point presisi tunggal yang dikonversi ke Double.
using System; public class Example13 { public static void Main() { Double value = .1; Double result1 = value * 10; Double result2 = 0; for (int ctr = 1; ctr <= 10; ctr++) result2 += value; Console.WriteLine($".1 * 10: {result1:R}"); Console.WriteLine($".1 Added 10 times: {result2:R}"); } } // The example displays the following output: // .1 * 10: 1 // .1 Added 10 times: 0.99999999999999989let value = 0.1 let result1 = value * 10. let mutable result2 = 0. for i = 1 to 10 do result2 <- result2 + value printfn $".1 * 10: {result1:R}" printfn $".1 Added 10 times: {result2:R}" // The example displays the following output: // .1 * 10: 1 // .1 Added 10 times: 0.99999999999999989Module Example14 Public Sub Run() Dim value As Double = 0.1 Dim result1 As Double = value * 10 Dim result2 As Double For ctr As Integer = 1 To 10 result2 += value Next Console.WriteLine(".1 * 10: {0:R}", result1) Console.WriteLine(".1 Added 10 times: {0:R}", result2) End Sub End Module ' The example displays the following output: ' .1 * 10: 1 ' .1 Added 10 times: 0.99999999999999989
Bidang
| Nama | Deskripsi |
|---|---|
| E |
Mewakili basis logaritma alami, yang ditentukan oleh konstanta, e. |
| Epsilon |
Mewakili nilai positif Double terkecil yang lebih besar dari nol. Bidang ini konstan. |
| MaxValue |
Mewakili nilai terbesar yang mungkin dari .Double Bidang ini konstan. |
| MinValue |
Mewakili nilai sekecil mungkin dari Double. Bidang ini konstan. |
| NaN |
Mewakili nilai yang bukan angka ( |
| NegativeInfinity |
Mewakili tak terbatas negatif. Bidang ini konstan. |
| NegativeZero |
Mewakili angka nol negatif (-0). |
| Pi |
Mewakili rasio lingkar lingkaran terhadap diameternya, yang ditentukan oleh konstanta, π. |
| PositiveInfinity |
Mewakili tak terbatas positif. Bidang ini konstan. |
| Tau |
Mewakili jumlah radian dalam satu giliran, yang ditentukan oleh konstanta, Ï„. |
Metode
| Nama | Deskripsi |
|---|---|
| Abs(Double) |
Menghitung absolut nilai. |
| Acos(Double) |
Menghitung arc-cosine dari nilai. |
| Acosh(Double) |
Menghitung kosinus busur hiperbolik dari nilai. |
| AcosPi(Double) |
Menghitung arc-cosine dari nilai dan membagi hasilnya dengan |
| Asin(Double) |
Menghitung sinus busur dari nilai. |
| Asinh(Double) |
Menghitung sinus busur hiperbolik dari nilai. |
| AsinPi(Double) |
Menghitung sinus busur dari nilai dan membagi hasilnya dengan |
| Atan(Double) |
Menghitung tangen busur dari nilai. |
| Atan2(Double, Double) |
Menghitung tangen busur dari kuota dua nilai. |
| Atan2Pi(Double, Double) |
Menghitung tangen busur untuk kuota dua nilai dan membagi hasilnya dengan |
| Atanh(Double) |
Menghitung tangen busur hiperbolik dari nilai. |
| AtanPi(Double) |
Menghitung tangen busur dari nilai dan membagi hasilnya dengan pi. |
| BitDecrement(Double) |
Mengembalikan nilai terbesar yang membandingkan kurang dari nilai yang ditentukan. |
| BitIncrement(Double) |
Mengembalikan nilai terkecil yang membandingkan lebih besar dari nilai yang ditentukan. |
| Cbrt(Double) |
Menghitung akar kubus dari nilai. |
| Ceiling(Double) |
Menghitung langit-langit nilai. |
| Clamp(Double, Double, Double) |
Menjepit nilai ke nilai minimum dan maksimum inklusif. |
| ClampNative(Double, Double, Double) |
Menjepit nilai ke nilai minimum dan maksimum inklusif menggunakan perilaku khusus platform untuk |
| CompareTo(Double) |
Membandingkan instans ini dengan angka floating-point presisi ganda yang ditentukan dan mengembalikan bilangan bulat yang menunjukkan apakah nilai instans ini kurang dari, sama dengan, atau lebih besar dari nilai angka floating-point presisi ganda yang ditentukan. |
| CompareTo(Object) |
Membandingkan instans ini dengan objek tertentu dan mengembalikan bilangan bulat yang menunjukkan apakah nilai instans ini kurang dari, sama dengan, atau lebih besar dari nilai objek yang ditentukan. |
| ConvertToInteger<TInteger>(Double) |
Mengonversi nilai ke jenis bilangan bulat tertentu menggunakan saturasi saat luapan |
| ConvertToIntegerNative<TInteger>(Double) |
Mengonversi nilai menjadi jenis bilangan bulat tertentu menggunakan perilaku spesifik platform saat luapan. |
| CopySign(Double, Double) |
Menyalin tanda nilai ke tanda nilai lain. |
| Cos(Double) |
Menghitung kosinus nilai. |
| Cosh(Double) |
Menghitung kosinus hiperbolik dari nilai. |
| CosPi(Double) |
Menghitung kosinus nilai yang telah dikalikan dengan |
| CreateChecked<TOther>(TOther) |
Membuat instans jenis saat ini dari nilai, melemparkan pengecualian luapan untuk nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| CreateSaturating<TOther>(TOther) |
Membuat instans jenis saat ini dari nilai, menjenuhkan nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| CreateTruncating<TOther>(TOther) |
Membuat instans jenis saat ini dari nilai, memotong nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| DegreesToRadians(Double) |
Mengonversi nilai tertentu dari derajat ke radian. |
| Equals(Double) |
Mengembalikan nilai yang menunjukkan apakah instans ini dan objek tertentu Double mewakili nilai yang sama. |
| Equals(Object) |
Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu. |
| Exp(Double) |
Komputasi |
| Exp10(Double) |
Komputasi |
| Exp10M1(Double) |
|
| Exp2(Double) |
Komputasi |
| Exp2M1(Double) |
|
| ExpM1(Double) |
|
| Floor(Double) |
Menghitung lantai nilai. |
| FusedMultiplyAdd(Double, Double, Double) |
Menghitung penambahan perkalian yang menyatu dari tiga nilai. |
| GetHashCode() |
Mengembalikan kode hash untuk instans ini. |
| GetTypeCode() | |
| Hypot(Double, Double) |
Menghitung hipotenus yang diberikan dua nilai yang mewakili panjang sisi yang lebih pendek dalam segitiga sudut kanan. |
| Ieee754Remainder(Double, Double) |
Menghitung sisa dua nilai seperti yang ditentukan oleh IEEE 754. |
| ILogB(Double) |
Menghitung logaritma bilangan bulat dari nilai. |
| IsEvenInteger(Double) |
Menentukan apakah nilai mewakili angka integral genap. |
| IsFinite(Double) |
Menentukan apakah nilai yang ditentukan terbatas (nol, subnormal, atau normal). |
| IsInfinity(Double) |
Mengembalikan nilai yang menunjukkan apakah angka yang ditentukan dievaluasi ke negatif atau tidak terbatas positif. |
| IsInteger(Double) |
Menentukan apakah nilai mewakili nilai integral. |
| IsNaN(Double) |
Mengembalikan nilai yang menunjukkan apakah nilai yang ditentukan bukan angka (NaN). |
| IsNegative(Double) |
Menentukan apakah nilai yang ditentukan negatif. |
| IsNegativeInfinity(Double) |
Mengembalikan nilai yang menunjukkan apakah angka yang ditentukan dievaluasi ke tak terbatas negatif. |
| IsNormal(Double) |
Menentukan apakah nilai yang ditentukan normal. |
| IsOddInteger(Double) |
Menentukan apakah nilai mewakili angka integral ganjil. |
| IsPositive(Double) |
Menentukan apakah nilai positif. |
| IsPositiveInfinity(Double) |
Mengembalikan nilai yang menunjukkan apakah angka yang ditentukan dievaluasi ke tak terbatas positif. |
| IsPow2(Double) |
Menentukan apakah nilai adalah kekuatan dua. |
| IsRealNumber(Double) |
Menentukan apakah nilai mewakili angka riil. |
| IsSubnormal(Double) |
Menentukan apakah nilai yang ditentukan adalah subnormal. |
| Lerp(Double, Double, Double) |
Melakukan interpolasi linier antara dua nilai berdasarkan bobot yang diberikan. |
| Log(Double, Double) |
Menghitung logaritma nilai dalam basis yang ditentukan. |
| Log(Double) |
Menghitung alami ( |
| Log10(Double) |
Menghitung logaritma base-10 dari suatu nilai. |
| Log10P1(Double) |
Menghitung logaritma base-10 dari nilai ditambah satu. |
| Log2(Double) |
Menghitung log2 dari nilai. |
| Log2P1(Double) |
Menghitung logaritma base-2 dari nilai plus satu. |
| LogP1(Double) |
Menghitung logaritma alami ( |
| Max(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih besar. |
| MaxMagnitude(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih besar. |
| MaxMagnitudeNumber(Double, Double) |
Membandingkan dua nilai dengan komputasi yang memiliki besaran lebih besar dan mengembalikan nilai lain jika input adalah |
| MaxNative(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih besar menggunakan perilaku khusus platform untuk |
| MaxNumber(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih besar dan mengembalikan nilai lain jika input adalah |
| Min(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih rendah. |
| MinMagnitude(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih rendah. |
| MinMagnitudeNumber(Double, Double) |
Membandingkan dua nilai dengan komputasi yang memiliki besaran lebih kecil dan mengembalikan nilai lain jika input adalah |
| MinNative(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih sedikit menggunakan perilaku khusus platform untuk |
| MinNumber(Double, Double) |
Membandingkan dua nilai dengan komputasi yang lebih kecil dan mengembalikan nilai lain jika input adalah |
| MultiplyAddEstimate(Double, Double, Double) |
Menghitung perkiraan ( |
| Parse(ReadOnlySpan<Byte>, IFormatProvider) |
Mengurai rentang karakter UTF-8 menjadi nilai. |
| Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider) |
Mengurai rentang karakter UTF-8 menjadi nilai. |
| Parse(ReadOnlySpan<Char>, IFormatProvider) |
Mengurai rentang karakter menjadi nilai. |
| Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
Mengonversi rentang karakter yang berisi representasi string angka dalam gaya tertentu dan format khusus budaya ke angka floating-point presisi ganda yang setara. |
| Parse(String, IFormatProvider) |
Mengonversi representasi string dari angka dalam format khusus budaya tertentu ke angka floating-point presisi ganda yang setara. |
| Parse(String, NumberStyles, IFormatProvider) |
Mengonversi representasi string angka dalam gaya tertentu dan format khusus budaya ke angka floating-point presisi ganda yang setara. |
| Parse(String, NumberStyles) |
Mengonversi representasi string dari angka dalam gaya tertentu ke angka floating-point presisi ganda yang setara. |
| Parse(String) |
Mengonversi representasi string dari angka ke angka floating-point presisi ganda yang setara. |
| Pow(Double, Double) |
Menghitung nilai yang dinaikkan ke kekuatan tertentu. |
| RadiansToDegrees(Double) |
Mengonversi nilai tertentu dari radian ke derajat. |
| ReciprocalEstimate(Double) |
Menghitung perkiraan timbal balik nilai. |
| ReciprocalSqrtEstimate(Double) |
Menghitung perkiraan akar kuadrat timbal balik dari suatu nilai. |
| RootN(Double, Int32) |
Menghitung akar n-th dari nilai. |
| Round(Double, Int32, MidpointRounding) |
Membulatkan nilai ke jumlah digit pecahan tertentu menggunakan mode pembulatan default (ToEven). |
| Round(Double, Int32) |
Membulatkan nilai ke jumlah digit pecahan tertentu menggunakan mode pembulatan default (ToEven). |
| Round(Double, MidpointRounding) |
Membulatkan nilai ke bilangan bulat terdekat menggunakan mode pembulatan yang ditentukan. |
| Round(Double) |
Membulatkan nilai ke bilangan bulat terdekat menggunakan mode pembulatan default (ToEven). |
| ScaleB(Double, Int32) |
Menghitung produk dari nilai dan radix dasarnya dinaikkan ke daya yang ditentukan. |
| Sign(Double) |
Menghitung tanda nilai. |
| Sin(Double) |
Menghitung sinus nilai. |
| SinCos(Double) |
Menghitung sinus dan kosinus nilai. |
| SinCosPi(Double) |
Menghitung sinus dan kosinus nilai. |
| Sinh(Double) |
Menghitung sinus hiperbolik dari nilai. |
| SinPi(Double) |
Menghitung sinus nilai yang telah dikalikan dengan |
| Sqrt(Double) |
Menghitung akar kuadrat dari nilai. |
| Tan(Double) |
Menghitung tangen nilai. |
| Tanh(Double) |
Menghitung tangen hiperbolik dari nilai. |
| TanPi(Double) |
Menghitung tangen nilai yang telah dikalikan dengan |
| ToString() |
Mengonversi nilai numerik instans ini ke representasi string yang setara. |
| ToString(IFormatProvider) |
Mengonversi nilai numerik instans ini ke representasi string yang setara menggunakan informasi format khusus budaya yang ditentukan. |
| ToString(String, IFormatProvider) |
Mengonversi nilai numerik instans ini ke representasi string yang setara menggunakan format yang ditentukan dan informasi format khusus budaya. |
| ToString(String) |
Mengonversi nilai numerik instans ini ke representasi string yang setara, menggunakan format yang ditentukan. |
| Truncate(Double) |
Memotong nilai. |
| TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
Mencoba memformat nilai instans saat ini sebagai UTF-8 ke dalam rentang byte yang disediakan. |
| TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
Mencoba memformat nilai instans ganda saat ini ke dalam rentang karakter yang disediakan. |
| TryParse(ReadOnlySpan<Byte>, Double) |
Mencoba mengonversi rentang karakter UTF-8 yang berisi representasi string angka ke angka floating-point presisi ganda yang setara. |
| TryParse(ReadOnlySpan<Byte>, IFormatProvider, Double) |
Mencoba mengurai rentang karakter UTF-8 ke dalam nilai. |
| TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Double) |
Mencoba mengurai rentang karakter UTF-8 ke dalam nilai. |
| TryParse(ReadOnlySpan<Char>, Double) |
Mengonversi representasi rentang angka dalam gaya tertentu dan format khusus budaya ke angka floating-point presisi ganda yang setara. Nilai pengembalian menunjukkan apakah konversi berhasil atau gagal. |
| TryParse(ReadOnlySpan<Char>, IFormatProvider, Double) |
Mencoba mengurai rentang karakter menjadi nilai. |
| TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Double) |
Mengonversi rentang karakter yang berisi representasi string angka dalam gaya tertentu dan format khusus budaya ke angka floating-point presisi ganda yang setara. Nilai pengembalian menunjukkan apakah konversi berhasil atau gagal. |
| TryParse(String, Double) |
Mengonversi representasi string dari angka ke angka floating-point presisi ganda yang setara. Nilai pengembalian menunjukkan apakah konversi berhasil atau gagal. |
| TryParse(String, IFormatProvider, Double) |
Mencoba mengurai string ke dalam nilai. |
| TryParse(String, NumberStyles, IFormatProvider, Double) |
Mengonversi representasi string angka dalam gaya tertentu dan format khusus budaya ke angka floating-point presisi ganda yang setara. Nilai pengembalian menunjukkan apakah konversi berhasil atau gagal. |
Operator
| Nama | Deskripsi |
|---|---|
| Equality(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah dua nilai yang ditentukan Double sama. |
| GreaterThan(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah nilai yang ditentukan Double lebih besar dari nilai lain yang ditentukan Double . |
| GreaterThanOrEqual(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah nilai yang ditentukan Double lebih besar dari atau sama dengan nilai lain yang ditentukan Double . |
| Inequality(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah dua nilai yang ditentukan Double tidak sama. |
| LessThan(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah nilai yang ditentukan Double kurang dari nilai lain yang ditentukan Double . |
| LessThanOrEqual(Double, Double) |
Mengembalikan nilai yang menunjukkan apakah nilai yang ditentukan Double kurang dari atau sama dengan nilai lain yang ditentukan Double . |
Implementasi Antarmuka Eksplisit
| Nama | Deskripsi |
|---|---|
| IAdditionOperators<Double,Double,Double>.Addition(Double, Double) |
Menambahkan dua nilai bersama-sama untuk menghitung jumlahnya. |
| IAdditiveIdentity<Double,Double>.AdditiveIdentity |
Mendapatkan identitas aditif dari jenis saat ini. |
| IBinaryNumber<Double>.AllBitsSet |
Mendapatkan instans jenis biner tempat semua bit diatur. |
| IBitwiseOperators<Double,Double,Double>.BitwiseAnd(Double, Double) |
Menghitung bitwise-dan dari dua nilai. |
| IBitwiseOperators<Double,Double,Double>.BitwiseOr(Double, Double) |
Menghitung bitwise-atau dari dua nilai. |
| IBitwiseOperators<Double,Double,Double>.ExclusiveOr(Double, Double) |
Menghitung nilai eksklusif atau dari dua nilai. |
| IBitwiseOperators<Double,Double,Double>.OnesComplement(Double) |
Menghitung representasi pelengkap seseorang dari nilai tertentu. |
| IComparable.CompareTo(Object) |
Membandingkan instans saat ini dengan objek lain dengan jenis yang sama dan mengembalikan bilangan bulat yang menunjukkan apakah instans saat ini mendahului, mengikuti, atau terjadi dalam posisi yang sama dalam urutan pengurutan seperti objek lainnya. |
| IConvertible.GetTypeCode() |
Mengembalikan untuk instans TypeCode ini. |
| IConvertible.ToBoolean(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToBoolean(IFormatProvider). |
| IConvertible.ToByte(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToByte(IFormatProvider). |
| IConvertible.ToChar(IFormatProvider) |
Konversi ini tidak didukung. Mencoba menggunakan metode ini melempar .InvalidCastException |
| IConvertible.ToDateTime(IFormatProvider) |
Konversi ini tidak didukung. Mencoba menggunakan metode ini melempar .InvalidCastException |
| IConvertible.ToDecimal(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToDecimal(IFormatProvider). |
| IConvertible.ToDouble(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToDouble(IFormatProvider). |
| IConvertible.ToInt16(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToInt16(IFormatProvider). |
| IConvertible.ToInt32(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToInt32(IFormatProvider). |
| IConvertible.ToInt64(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToInt64(IFormatProvider). |
| IConvertible.ToSByte(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToSByte(IFormatProvider). |
| IConvertible.ToSingle(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToSingle(IFormatProvider). |
| IConvertible.ToType(Type, IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToType(Type, IFormatProvider). |
| IConvertible.ToUInt16(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToUInt16(IFormatProvider). |
| IConvertible.ToUInt32(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToUInt32(IFormatProvider). |
| IConvertible.ToUInt64(IFormatProvider) |
Untuk deskripsi anggota ini, lihat ToUInt64(IFormatProvider). |
| IDecrementOperators<Double>.Decrement(Double) |
Mengurangi nilai. |
| IDivisionOperators<Double,Double,Double>.Division(Double, Double) |
Membagi satu nilai dengan nilai lainnya untuk menghitung kuotanya. |
| IFloatingPoint<Double>.GetExponentByteCount() |
Mendapatkan jumlah byte yang akan ditulis sebagai bagian TryWriteExponentLittleEndian(Span<Byte>, Int32)dari . |
| IFloatingPoint<Double>.GetExponentShortestBitLength() |
Mendapatkan panjang, dalam bit, dari representasi pelengkap dua terpendek dari eksponen saat ini. |
| IFloatingPoint<Double>.GetSignificandBitLength() |
Mendapatkan panjang, dalam bit, dari significand saat ini. |
| IFloatingPoint<Double>.GetSignificandByteCount() |
Mendapatkan jumlah byte yang akan ditulis sebagai bagian TryWriteSignificandLittleEndian(Span<Byte>, Int32)dari . |
| IFloatingPoint<Double>.TryWriteExponentBigEndian(Span<Byte>, Int32) |
Mencoba menulis eksponen saat ini, dalam format big-endian, ke rentang tertentu. |
| IFloatingPoint<Double>.TryWriteExponentLittleEndian(Span<Byte>, Int32) |
Mencoba menulis eksponen saat ini, dalam format little-endian, ke rentang tertentu. |
| IFloatingPoint<Double>.TryWriteSignificandBigEndian(Span<Byte>, Int32) |
Mencoba menulis significand saat ini, dalam format big-endian, ke rentang tertentu. |
| IFloatingPoint<Double>.TryWriteSignificandLittleEndian(Span<Byte>, Int32) |
Mencoba menulis significand saat ini, dalam format little-endian, ke rentang tertentu. |
| IFloatingPointConstants<Double>.E |
Mendapatkan konstanta |
| IFloatingPointConstants<Double>.Pi |
Mendapatkan konstanta |
| IFloatingPointConstants<Double>.Tau |
Mendapatkan konstanta |
| IFloatingPointIeee754<Double>.Epsilon |
Mendapatkan nilai terkecil sehingga dapat ditambahkan ke |
| IFloatingPointIeee754<Double>.NaN |
Mendapatkan nilai yang mewakili |
| IFloatingPointIeee754<Double>.NegativeInfinity |
Mendapatkan nilai yang mewakili negatif |
| IFloatingPointIeee754<Double>.NegativeZero |
Mendapatkan nilai yang mewakili negatif |
| IFloatingPointIeee754<Double>.PositiveInfinity |
Mendapatkan nilai yang mewakili positif |
| IIncrementOperators<Double>.Increment(Double) |
Menaikkan nilai. |
| IMinMaxValue<Double>.MaxValue |
Mendapatkan nilai maksimum dari jenis saat ini. |
| IMinMaxValue<Double>.MinValue |
Mendapatkan nilai minimum dari jenis saat ini. |
| IModulusOperators<Double,Double,Double>.Modulus(Double, Double) |
Membagi dua nilai bersama-sama untuk menghitung modulus atau sisanya. |
| IMultiplicativeIdentity<Double,Double>.MultiplicativeIdentity |
Mendapatkan identitas multiplikatif dari jenis saat ini. |
| IMultiplyOperators<Double,Double,Double>.Multiply(Double, Double) |
Mengalikan dua nilai bersama-sama untuk menghitung produknya. |
| INumberBase<Double>.IsCanonical(Double) |
Menentukan apakah nilai berada dalam representasi kanonisnya. |
| INumberBase<Double>.IsComplexNumber(Double) |
Menentukan apakah nilai mewakili bilangan kompleks. |
| INumberBase<Double>.IsImaginaryNumber(Double) |
Menentukan apakah nilai mewakili angka imajiner murni. |
| INumberBase<Double>.IsZero(Double) |
Menentukan apakah nilai adalah nol. |
| INumberBase<Double>.One |
Mendapatkan nilai |
| INumberBase<Double>.Radix |
Mendapatkan radix, atau basis, untuk tipe tersebut. |
| INumberBase<Double>.TryConvertFromChecked<TOther>(TOther, Double) |
Mewakili bilangan titik-mengambang presisi ganda. |
| INumberBase<Double>.TryConvertFromSaturating<TOther>(TOther, Double) |
Mewakili bilangan titik-mengambang presisi ganda. |
| INumberBase<Double>.TryConvertFromTruncating<TOther>(TOther, Double) |
Mewakili bilangan titik-mengambang presisi ganda. |
| INumberBase<Double>.TryConvertToChecked<TOther>(Double, TOther) |
Mencoba mengonversi instans jenis saat ini ke jenis lain, melemparkan pengecualian luapan untuk nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| INumberBase<Double>.TryConvertToSaturating<TOther>(Double, TOther) |
Mencoba mengonversi instans jenis saat ini ke jenis lain, menjenuhkan nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| INumberBase<Double>.TryConvertToTruncating<TOther>(Double, TOther) |
Mencoba mengonversi instans jenis saat ini ke jenis lain, memotong nilai apa pun yang berada di luar rentang yang dapat diwakili dari jenis saat ini. |
| INumberBase<Double>.Zero |
Mendapatkan nilai |
| ISignedNumber<Double>.NegativeOne |
Mendapatkan nilai |
| ISubtractionOperators<Double,Double,Double>.Subtraction(Double, Double) |
Mengurangi dua nilai untuk menghitung perbedaannya. |
| IUnaryNegationOperators<Double,Double>.UnaryNegation(Double) |
Menghitung negasi nilai yang tidak biasa. |
| IUnaryPlusOperators<Double,Double>.UnaryPlus(Double) |
Menghitung nilai plus unary. |
Berlaku untuk
Keamanan Thread
Semua anggota jenis ini aman utas. Anggota yang tampaknya mengubah status instans benar-benar mengembalikan instans baru yang diinisialisasi dengan nilai baru. Seperti halnya jenis lain, membaca dan menulis ke variabel bersama yang berisi instans jenis ini harus dilindungi oleh kunci untuk menjamin keamanan utas.