Double Double Double Double Struct

定義

倍精度浮動小数点数を表します。Represents a double-precision floating-point number.

public value class Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Double : IComparable, IComparable<double>, IConvertible, IEquatable<double>, IFormattable
type double = struct
    interface IFormattable
    interface IConvertible
Public Structure Double
Implements IComparable, IComparable(Of Double), IConvertible, IEquatable(Of Double), IFormattable
継承
属性
実装

次のコード例は、の使用を示していますDouble:。The following code example illustrates the use of Double:

// The Temperature class stores the temperature as a Double
// and delegates most of the functionality to the Double 
// implementation.
public ref class Temperature: public IComparable, public IFormattable
{
   // IComparable.CompareTo implementation.
public:
   virtual int CompareTo( Object^ obj )
   {
      if (obj == nullptr) return 1;
      
      if (dynamic_cast<Temperature^>(obj) )
      {
         Temperature^ temp = (Temperature^)(obj);
         return m_value.CompareTo( temp->m_value );
      }
      throw gcnew ArgumentException( "object is not a Temperature" );
   }

   // IFormattable.ToString implementation.
   virtual String^ ToString( String^ format, IFormatProvider^ provider )
   {
      if ( format != nullptr )
      {
         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]
   static Temperature^ Parse( String^ s, NumberStyles styles, IFormatProvider^ provider )
   {
      Temperature^ temp = gcnew Temperature;

      if ( s->TrimEnd(nullptr)->EndsWith( "'F" ) )
      {
         temp->Value = Double::Parse( s->Remove( s->LastIndexOf( '\'' ), 2 ), styles, provider );
      }
      else
      if ( s->TrimEnd(nullptr)->EndsWith( "'C" ) )
      {
         temp->Celsius = Double::Parse( s->Remove( s->LastIndexOf( '\'' ), 2 ), styles, provider );
      }
      else
      {
         temp->Value = Double::Parse( s, styles, provider );
      }
      return temp;
   }

protected:
   double m_value;

public:
   property double Value 
   {
      double get()
      {
         return m_value;
      }

      void set( double value )
      {
         m_value = value;
      }
   }

   property double Celsius 
   {
      double get()
      {
         return (m_value - 32.0) / 1.8;
      }

      void set( double value )
      {
         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.
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;
		}
	}
}
' 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(Nothing).EndsWith("'F") Then
            temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
        Else
            If s.TrimEnd(Nothing).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

注釈

Double値型は、負 1.79769313486232 e 308 から 1.79769313486232 e 308 と正または負のゼロに至るまでの値を倍精度の 64 ビットの数値を表しますPositiveInfinityNegativeInfinity、および非数 (NaN).The Double value type represents a double-precision 64-bit number with values ranging from negative 1.79769313486232e308 to positive 1.79769313486232e308, as well as positive or negative zero, PositiveInfinity, NegativeInfinity, and not a number (NaN). 非常に高くなって (惑星または銀河系間の距離) など、または非常に小さい (キログラムの物質の分子の質量) とする多くの場合がないこと (などからの距離地球別太陽系)、正確な値を表すものでは、Double IEC 60559: 1989 (IEEE 754) バイナリ浮動小数点演算の標準に準拠している型。It is intended to represent values that are extremely large (such as distances between planets or galaxies) or extremely small (the molecular mass of a substance in kilograms) and that often are imprecise (such as the distance from earth to another solar system), The Double type complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.

このトピックは、次のセクションで構成されています。This topic consists of the following sections:

精度の浮動小数点表現Floating-Point Representation and Precision

Doubleデータ型は、次の表に示すように、64 ビットのバイナリ形式で倍精度浮動小数点値を格納します。The Double data type stores double-precision floating-point values in a 64-bit binary format, as shown in the following table:

パーツPart ビットBits
仮数または仮数部Significand or mantissa 0-510-51
指数Exponent 52-6252-62
サインイン (0 1、正の数値を = = 負の値)Sign (0 = Positive, 1 = Negative) 6363

小数がいくつかの小数部の値を正確に表すことがない場合と同様 (1/3 などまたはMath.PI)、バイナリの分数は、いくつかの小数部の値を表すことはできません。Just as decimal fractions are unable to precisely represent some fractional values (such as 1/3 or Math.PI), binary fractions are unable to represent some fractional values. たとえば、1/10、小数として.1 で正確に表されるは、無限大パターン「0011」繰り返しのバイナリの分数として.001100110011 で表されます。For example, 1/10, which is represented precisely by .1 as a decimal fraction, is represented by .001100110011 as a binary fraction, with the pattern "0011" repeating to infinity. この場合、浮動小数点値は、それが表す番号の不正確な表現を提供します。In this case, the floating-point value provides an imprecise representation of the number that it represents. 元の浮動小数点値で追加の数学的な操作を実行する多くの場合は、精度を向上する傾向があります。Performing additional mathematical operations on the original floating-point value often tends to increase its lack of precision. たとえば、.1 で 10 を乗算した結果を比較し、.1 に.1 を 9 回追加すると、表示をさらに、8 個より多くの操作が行われて、ためが生成より精度の低い結果。For example, if we compare the result of multiplying .1 by 10 and adding .1 to .1 nine times, we see that addition, because it has involved eight more operations, has produced the less precise result. このような違いは、2 つ表示の場合のみ、 Double "R"を使用して値標準数値書式指定文字列、必要なかどうかはでサポートされている有効桁数の 17 桁がすべて表示されます、Double型。Note that this disparity is apparent only if we display the two Double values by using the "R" standard numeric format string, which if necessary displays all 17 digits of precision supported by the Double type.

using System;

public class Example
{
   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:           {0:R}", result1);
      Console.WriteLine(".1 Added 10 times: {0:R}", result2);
   }
}
// The example displays the following output:
//       .1 * 10:           1
//       .1 Added 10 times: 0.99999999999999989
Module Example
   Public Sub Main()
      Dim value As Double = .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

いくつかの数字は、バイナリ値の小数部として正確に表されることはできません、ため、浮動小数点数には、おおよその実数のみことができます。Because some numbers cannot be represented exactly as fractional binary values, floating-point numbers can only approximate real numbers.

すべての浮動小数点数には、どれだけ正確に浮動小数点値に近い実数も決定する限られた数の有効桁数もがあります。All floating-point numbers also have a limited number of significant digits, which also determines how accurately a floating-point value approximates a real number. ADouble最大 17 桁が内部的に保持されて、値が有効桁数、最大で 15 個の 10 進数字。A Double value has up to 15 decimal digits of precision, although a maximum of 17 digits is maintained internally. つまり、浮動小数点演算が浮動を変更する有効桁数をれない可能性があります値をポイントします。This means that some floating-point operations may lack the precision to change a floating point value. 具体的な例を次に示します。The following example provides an illustration. 非常に大きなの浮動小数点値を定義し、次の製品を追加Double.Epsilonと 1,000兆にします。It defines a very large floating-point value, and then adds the product of Double.Epsilon and one quadrillion to it. ただし、製品が元の浮動小数点値を変更するには小さすぎます。The product, however, is too small to modify the original floating-point value. その最下位の桁は 1/10、1/100、1/1000、製品の最上位桁は 10-309します。Its least significant digit is thousandths, whereas the most significant digit in the product is 10-309.

using System;

public class Example
{
   public static void Main()
   {
      Double value = 123456789012.34567;
      Double additional = Double.Epsilon * 1e15;
      Console.WriteLine("{0} + {1} = {2}", value, additional, 
                                           value + additional);
   }
}
// The example displays the following output:
//    123456789012.346 + 4.94065645841247E-309 = 123456789012.346
Module Example
   Public Sub Main()
      Dim value As Double = 123456789012.34567
      Dim additional As Double = Double.Epsilon * 1e15
      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

浮動小数点数の制限された有効桁数には、複数の結果があります。The limited precision of a floating-point number has several consequences:

  • 特定の有効桁数で等しく見える 2 つの浮動小数点数が等しくない有効桁数が異なるためです。Two floating-point numbers that appear equal for a particular precision might not compare equal because their least significant digits are different. 次の例では、一連の数字を加算し、その合計が、予想される合計と比較されます。In the following example, a series of numbers are added together, and their total is compared with their expected total. 2 つの値は同じであるへの呼び出しに見えますが、Equalsメソッドがないことを示します。Although the two values appear to be the same, a call to the Equals method indicates that they are not.

    using System;
    
    public class Example
    {
       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 ({0}) does not equal the total ({1}).",
                               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 Example
       Public Sub Main()
          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).   
    

    書式項目を変更する場合、Console.WriteLine(String, Object, Object)ステートメントから{0}{1}{0:R}{1:R}、2 つのすべての有効桁数を表示するDouble値、2 つの値が等しくないことは明らかですので、追加の操作中に有効桁数が失われる。If you change the format items in the Console.WriteLine(String, Object, Object) statement from {0} and {1} to {0:R} and {1:R} to display all significant digits of the two Double values, it is clear that the two values are unequal because of a loss of precision during the addition operations. 問題を解決して呼び出すことによって、ここで、Math.Round(Double, Int32)丸めるメソッド、Double比較を実行する前に必要な有効桁数の値。In this case, the issue can be resolved by calling the Math.Round(Double, Int32) method to round the Double values to the desired precision before performing the comparison.

  • 浮動小数点数を使用する数学的演算または比較操作が生成されない、同じ結果を 10 進数を使用する場合バイナリ浮動小数点数が 10 進数と等しくないため、します。A mathematical or comparison operation that uses a floating-point number might not yield the same result if a decimal number is used, because the binary floating-point number might not equal the decimal number. 前の例では、.1 で 10 を乗算することと、.1 回の追加の結果を表示することでこれを説明します。A previous example illustrated this by displaying the result of multiplying .1 by 10 and adding .1 times.

    小数部の値を持つ数値演算の精度が重要なときに使用できます、DecimalなくDouble型。When accuracy in numeric operations with fractional values is important, you can use the Decimal rather than the Double type. ときに精度数値演算の範囲外の整数値で、Int64またはUInt64使用の種類は重要では、BigInteger型。When accuracy in numeric operations with integral values beyond the range of the Int64 or UInt64 types is important, use the BigInteger type.

  • 値のラウンドト リップしない場合は、浮動小数点数が含まれている可能性があります。A value might not round-trip if a floating-point number is involved. 操作は、元の浮動小数点数を別の形式に変換します、逆の操作が、浮動小数点数に変換されたフォームを変換し、最終的な浮動小数点数が元と等しくない場合、値がラウンドト リップさせると言います浮動小数点数。A value is said to round-trip if an operation converts an original floating-point number to another form, an inverse operation transforms the converted form back to a floating-point number, and the final floating-point number is not equal to the original floating-point number. 1 つ以上の最小有効桁数が紛失または変換で変更されたために、ラウンド トリップが失敗することがあります。The round trip might fail because one or more least significant digits are lost or changed in a conversion. 次の例では、次の 3 つDouble値が文字列に変換され、ファイルに保存します。In the following example, three Double values are converted to strings and saved in a file. 出力をただしは同じで、値が表示される場合でも、復元された値が元の値に等しくないです。As the output shows, however, even though the values appear to be identical, the restored values are not equal to the original values.

    using System;
    using System.IO;
    
    public class Example
    {
       public static void Main()
       {
          StreamWriter sw = new StreamWriter(@".\Doubles.dat");
          Double[] values = { 2.2/1.01, 1.0/3, Math.PI };
          for (int ctr = 0; ctr < values.Length; ctr++) {
             sw.Write(values[ctr].ToString());
             if (ctr != values.Length - 1)
                sw.Write("|");
          }      
          sw.Close();
          
          Double[] restoredValues = new Double[values.Length];
          StreamReader sr = new StreamReader(@".\Doubles.dat");
          string temp = sr.ReadToEnd();
          string[] tempStrings = temp.Split('|');
          for (int ctr = 0; ctr < tempStrings.Length; ctr++)
             restoredValues[ctr] = Double.Parse(tempStrings[ctr]);   
    
    
          for (int ctr = 0; ctr < values.Length; ctr++)
             Console.WriteLine("{0} {2} {1}", values[ctr], 
                               restoredValues[ctr],
                               values[ctr].Equals(restoredValues[ctr]) ? "=" : "<>");
       }
    }
    // The example displays the following output:
    //       2.17821782178218 <> 2.17821782178218
    //       0.333333333333333 <> 0.333333333333333
    //       3.14159265358979 <> 3.14159265358979
    
    Imports System.IO
    
    Module Example
       Public Sub Main()
          Dim sw As New StreamWriter(".\Doubles.dat")
          Dim values() As Double = { 2.2/1.01, 1.0/3, Math.PI }
          For ctr As Integer = 0 To values.Length - 1
             sw.Write(values(ctr).ToString())
             If ctr <> values.Length - 1 Then sw.Write("|")
          Next      
          sw.Close()
          
          Dim restoredValues(values.Length - 1) As Double
          Dim sr As New StreamReader(".\Doubles.dat")
          Dim temp As String = sr.ReadToEnd()
          Dim tempStrings() As String = temp.Split("|"c)
          For ctr As Integer = 0 To tempStrings.Length - 1
             restoredValues(ctr) = Double.Parse(tempStrings(ctr))   
          Next 
    
          For ctr As Integer = 0 To values.Length - 1
             Console.WriteLine("{0} {2} {1}", values(ctr), 
                               restoredValues(ctr),
                               If(values(ctr).Equals(restoredValues(ctr)), "=", "<>"))
          Next
       End Sub
    End Module
    ' The example displays the following output:
    '       2.17821782178218 <> 2.17821782178218
    '       0.333333333333333 <> 0.333333333333333
    '       3.14159265358979 <> 3.14159265358979
    

    この場合、値が正常にラウンドト リップを使用してできます"G17"標準数値書式指定文字列の完全な有効桁数を保持するためにDouble値は、次の例を示します。In this case, the values can be successfully round-tripped by using the "G17" standard numeric format string to preserve the full precision of Double values, as the following example shows.

    using System;
    using System.IO;
    
    public class Example
    {
       public static void Main()
       {
          StreamWriter sw = new StreamWriter(@".\Doubles.dat");
          Double[] values = { 2.2/1.01, 1.0/3, Math.PI };
          for (int ctr = 0; ctr < values.Length; ctr++) 
             sw.Write("{0:G17}{1}", values[ctr], ctr < values.Length - 1 ? "|" : "" );
    
          sw.Close();
          
          Double[] restoredValues = new Double[values.Length];
          StreamReader sr = new StreamReader(@".\Doubles.dat");
          string temp = sr.ReadToEnd();
          string[] tempStrings = temp.Split('|');
          for (int ctr = 0; ctr < tempStrings.Length; ctr++)
             restoredValues[ctr] = Double.Parse(tempStrings[ctr]);   
    
    
          for (int ctr = 0; ctr < values.Length; ctr++)
             Console.WriteLine("{0} {2} {1}", values[ctr], 
                               restoredValues[ctr],
                               values[ctr].Equals(restoredValues[ctr]) ? "=" : "<>");
       }
    }
    // The example displays the following output:
    //       2.17821782178218 = 2.17821782178218
    //       0.333333333333333 = 0.333333333333333
    //       3.14159265358979 = 3.14159265358979
    
    Imports System.IO
    
    Module Example
       Public Sub Main()
          Dim sw As New StreamWriter(".\Doubles.dat")
          Dim values() As Double = { 2.2/1.01, 1.0/3, Math.PI }
          For ctr As Integer = 0 To values.Length - 1
             sw.Write("{0:G17}{1}", values(ctr), 
                      If(ctr < values.Length - 1, "|", ""))
          Next      
          sw.Close()
          
          Dim restoredValues(values.Length - 1) As Double
          Dim sr As New StreamReader(".\Doubles.dat")
          Dim temp As String = sr.ReadToEnd()
          Dim tempStrings() As String = temp.Split("|"c)
          For ctr As Integer = 0 To tempStrings.Length - 1
             restoredValues(ctr) = Double.Parse(tempStrings(ctr))   
          Next 
    
          For ctr As Integer = 0 To values.Length - 1
             Console.WriteLine("{0} {2} {1}", values(ctr), 
                               restoredValues(ctr),
                               If(values(ctr).Equals(restoredValues(ctr)), "=", "<>"))
          Next
       End Sub
    End Module
    ' The example displays the following output:
    '       2.17821782178218 = 2.17821782178218
    '       0.333333333333333 = 0.333333333333333
    '       3.14159265358979 = 3.14159265358979
    

重要

使用すると、Double元の値のラウンドト リップに失敗した値、場合によっては、"R"書式指定子。When used with a Double value, the "R" format specifier in some cases fails to successfully round-trip the original value. いることを確認するDouble"G17"書式指定子を使用して、値のラウンドト リップに失敗します。To ensure that Double values successfully round-trip, use the "G17" format specifier.

  • Single 値があるよりも精度が低いDouble値。Single values have less precision than Double values. ASingle一見同等に変換される値Double多くの場合と一致しません、Double有効桁数の違いのための値。A Single value that is converted to a seemingly equivalent Double often does not equal the Double value because of differences in precision. 次の例では、同一の除算演算の結果が割り当てられている、DoubleSingle値。In the following example, the result of identical division operations is assigned to a Double and a Single value. 後に、Singleに値がキャストをDouble、2 つの値の比較は、それらが等しくないことを示しています。After the Single value is cast to a Double, a comparison of the two values shows that they are unequal.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          Double value1 = 1/3.0;
          Single sValue2 = 1/3.0f;
          Double value2 = (Double) sValue2;
          Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, 
                                              value1.Equals(value2));
       }
    }
    // The example displays the following output:
    //        0.33333333333333331 = 0.3333333432674408: False
    
    Module Example
       Public Sub Main()
          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: False
    

    この問題を回避するには、いずれかを使用、Doubleの代わりに、Singleデータ型、または使用して、Roundメソッド両方の値が同じの有効桁数を含めるようにします。To avoid this problem, use either the Double in place of the Single data type, or use the Round method so that both values have the same precision.

さらに、算術演算子および代入で、操作の結果Double値プラットフォームでの有効桁数の損失が原因が若干異なる、Double型。In addition, the result of arithmetic and assignment operations with Double values may differ slightly by platform because of the loss of precision of the Double type. たとえば、リテラルを割り当てることの結果Double.NET Framework の 32 ビットおよび 64 ビット バージョンの値が異なる場合があります。For example, the result of assigning a literal Double value may differ in the 32-bit and 64-bit versions of the .NET Framework. 次の例を示しますの差。 ときに、リテラル値 - 4.42330604244772E-305 と変数の値は - 4.42330604244772E-に割り当てられている 305、Double変数。The following example illustrates this difference when the literal value -4.42330604244772E-305 and a variable whose value is -4.42330604244772E-305 are assigned to a Double variable. 注意の結果、Parse(String)メソッドでも低下しない精度の損失から。Note that the result of the Parse(String) method in this case does not suffer from a loss of precision.

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);      
// 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.42330604244772E-305

Dim fromLiteral As Double = -4.42330604244772E-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)      
' 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      

等しいかどうかテストTesting for Equality

等しいと見なされる 2 つDouble値が同一の値を表す必要があります。To be considered equal, two Double values must represent identical values. ただし、有効桁数値の間の違いにより、または 1 つまたは両方の値によって精度が失われるのためには、多くの場合と同じで予想される浮動小数点値に有効桁数の違いによりは等しくない場合します。However, because of differences in precision between values, or because of a loss of precision by one or both values, floating-point values that are expected to be identical often turn out to be unequal because of differences in their least significant digits. 結果として、呼び出し、Equalsする 2 つの値が等しいかどうかを判断するメソッドまたはへの呼び出し、CompareToする 2 つの間のリレーションシップを判断するメソッドDouble値、多くの場合、予期しない結果を生成します。As a result, calls to the Equals method to determine whether two values are equal, or calls to the CompareTo method to determine the relationship between two Double values, often yield unexpected results. 明らかに等しい 2 つ、これは次の例では、明らかなDouble値が等しくないと、2 つ目が 17、1 つ目が 15 桁の精度、わかった。This is evident in the following example, where two apparently equal Double values turn out to be unequal because the first has 15 digits of precision, while the second has 17.

using System;

public class Example
{
   public static void Main()
   {
      double value1 = .333333333333333;
      double value2 = 1.0/3;
      Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2));
   }
}
// The example displays the following output:
//        0.333333333333333 = 0.33333333333333331: False
Module Example
   Public Sub Main()
      Dim value1 As Double = .333333333333333
      Dim value2 As Double = 1/3
      Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2))
   End Sub
End Module
' The example displays the following output:
'       0.333333333333333 = 0.33333333333333331: False

等しくないと計算値を次のコード パスが異なると、多くの場合、さまざまな方法で操作するを証明します。Calculated values that follow different code paths and that are manipulated in different ways often prove to be unequal. 次の例では、1 つDouble値が 2 乗し、元の値を復元する平方根が計算されます。In the following example, one Double value is squared, and then the square root is calculated to restore the original value. 1 秒あたりDouble3.51 で乗算され、前に、結果の平方根が元の値を復元する 3.51 で割った値を 2 乗します。A second Double is multiplied by 3.51 and squared before the square root of the result is divided by 3.51 to restore the original value. 同じに見えますが、2 つの値への呼び出し、Equals(Double)メソッドでは、それらが等しくないことを示します。Although the two values appear to be identical, a call to the Equals(Double) method indicates that they are not equal. 2 番目の値が.0000000000001 を示しています、"R"標準書式指定文字列を使用して Double 値の有効桁数がすべてを表示する結果文字列を返す最初よりも少ない。Using the "R" standard format string to return a result string that displays all the significant digits of each Double value shows that the second value is .0000000000001 less than the first.

using System;

public class Example
{
   public static void Main()
   {
      double value1 = 100.10142;
      value1 = Math.Sqrt(Math.Pow(value1, 2));
      double value2 = Math.Pow(value1 * 3.51, 2);
      value2 = Math.Sqrt(value2) / 3.51;
      Console.WriteLine("{0} = {1}: {2}\n", 
                        value1, value2, value1.Equals(value2)); 
      Console.WriteLine("{0:R} = {1:R}", value1, value2); 
   }
}
// The example displays the following output:
//    100.10142 = 100.10142: False
//    
//    100.10142 = 100.10141999999999
Module Example
   Public Sub Main()
      Dim value1 As Double = 100.10142
      value1 = Math.Sqrt(Math.Pow(value1, 2))
      Dim value2 As Double = Math.Pow(value1 * 3.51, 2)
      value2 = Math.Sqrt(value2) / 3.51
      Console.WriteLine("{0} = {1}: {2}", 
                        value1, value2, value1.Equals(value2)) 
      Console.WriteLine()
      Console.WriteLine("{0:R} = {1:R}", value1, value2) 
   End Sub
End Module
' The example displays the following output:
'    100.10142 = 100.10142: False
'    
'    100.10142 = 100.10141999999999

精度の損失が比較の結果に影響する可能性がある場合、次を呼び出すことのいずれかを採用できる、EqualsまたはCompareToメソッド。In cases where a loss of precision is likely to affect the result of a comparison, you can adopt any of the following alternatives to calling the Equals or CompareTo method:

  • 呼び出す、Math.Round両方の値は、同じ精度でいることを確認します。Call the Math.Round method to ensure that both values have the same precision. 次の例は、2 つの小数部の値が等しいされるように、このアプローチを使用する前の例を変更します。The following example modifies a previous example to use this approach so that two fractional values are equivalent.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          double value1 = .333333333333333;
          double value2 = 1.0/3;
          int precision = 7;
          value1 = Math.Round(value1, precision);
          value2 = Math.Round(value2, precision);
          Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2));
       }
    }
    // The example displays the following output:
    //        0.3333333 = 0.3333333: True
    
    Module Example
       Public Sub Main()
          Dim value1 As Double = .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:R} = {1:R}: {2}", value1, value2, value1.Equals(value2))
       End Sub
    End Module
    ' The example displays the following output:
    '       0.3333333 = 0.3333333: True
    

    ただし、中間値の丸め処理に精度の問題が引き続き適用されることに注意してください。Note, though, that the problem of precision still applies to rounding of midpoint values. 詳細については、Math.Round(Double, Int32, MidpointRounding) メソッドを参照してください。For more information, see the Math.Round(Double, Int32, MidpointRounding) method.

  • おおよそ等しいかどうかテスト等値ではなく。Test for approximate equality rather than equality. いずれか絶対パスを定義する必要があります 2 つの値は異なるが、それでもするされる量は等しいものかをより小さい値が大きい方の値から分岐できます相対的な量を定義します。This requires that you define either an absolute amount by which the two values can differ but still be equal, or that you define a relative amount by which the smaller value can diverge from the larger value.

    警告

    Double.Epsilon 2 つの間の距離の絶対的な測定値として提供される場合がありますDouble等しいかどうかをテストするときの値します。Double.Epsilon is sometimes used as an absolute measure of the distance between two Double values when testing for equality. ただし、Double.Epsilon追加、またはから減算できる最小有効値を測定するDouble値が 0 です。However, Double.Epsilon measures the smallest possible value that can be added to, or subtracted from, a Double whose value is zero. ほとんどの正と負Double値、値のDouble.Epsilonが小さすぎてを検出します。For most positive and negative Double values, the value of Double.Epsilon is too small to be detected. そのため、ゼロ値を除くしないでの等価性テストで使用します。Therefore, except for values that are zero, we do not recommend its use in tests for equality.

    次の例では、後者のアプローチを使用して、定義、 IsApproximatelyEqual 2 つの値の相対的な差をテストするメソッド。The following example uses the latter approach to define an IsApproximatelyEqual method that tests the relative difference between two values. 呼び出しの結果も対照的です、IsApproximatelyEqualメソッドとEquals(Double)メソッド。It also contrasts the result of calls to the IsApproximatelyEqual method and the Equals(Double) method.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          double one1 = .1 * 10;
          double one2 = 0;
          for (int ctr = 1; ctr <= 10; ctr++)
             one2 += .1;
    
          Console.WriteLine("{0:R} = {1:R}: {2}", one1, one2, one1.Equals(one2));
          Console.WriteLine("{0:R} is approximately equal to {1:R}: {2}", 
                            one1, 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: True
    
    Module Example
       Public Sub Main()
          Dim one1 As Double = .1 * 10
          Dim one2 As Double = 0
          For ctr As Integer = 1 To 10
             one2 += .1
          Next
          Console.WriteLine("{0:R} = {1:R}: {2}", one1, one2, one1.Equals(one2))
          Console.WriteLine("{0:R} is approximately equal to {1:R}: {2}", 
                            one1, one2, 
                            IsApproximatelyEqual(one1, one2, .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)
          Else If Double.IsInfinity(value2) Or Double.IsNaN(value2)
             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
    

浮動小数点値と例外Floating-Point Values and Exceptions

操作とオーバーフローや除算などの無効な操作の場合は 0 で例外がスローの整数の型とは異なり浮動小数点値を持つ操作は例外をスローしません。Unlike operations with integral types, which throw exceptions in cases of overflow or illegal operations such as division by zero, operations with floating-point values do not throw exceptions. 代わりに、例外的な状況は、浮動小数点演算の結果は 0、正の無限大、負の無限大、または非数 (NaN)。Instead, in exceptional situations, the result of a floating-point operation is zero, positive infinity, negative infinity, or not a number (NaN):

  • 浮動小数点演算の結果が小さすぎる変換先の形式の場合、結果は 0 です。If the result of a floating-point operation is too small for the destination format, the result is zero. これは、次の例のように、2 つの非常に小さい数値が乗算される場合に発生します。This can occur when two very small numbers are multiplied, as the following example shows.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          Double value1 = 1.1632875981534209e-225;
          Double value2 = 9.1642346778e-175;
          Double result = value1 * value2;
          Console.WriteLine("{0} * {1} = {2}", value1, value2, result);
          Console.WriteLine("{0} = 0: {1}", result, result.Equals(0.0));
       }
    }
    // The example displays the following output:
    //       1.16328759815342E-225 * 9.1642346778E-175 = 0
    //       0 = 0: True
    
    Module Example
       Public Sub Main()
          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: True
    
  • 浮動小数点演算の結果の大きさが変換先の形式の範囲を超えている場合、操作の結果はPositiveInfinityまたはNegativeInfinity、必要に応じて、結果の符号にします。If the magnitude of the result of a floating-point operation exceeds the range of the destination format, the result of the operation is PositiveInfinity or NegativeInfinity, as appropriate for the sign of the result. オーバーフローが発生する操作の結果Double.MaxValuePositiveInfinity、オーバーフローが発生する操作の結果とDouble.MinValueNegativeInfinity次の例に示すように、します。The result of an operation that overflows Double.MaxValue is PositiveInfinity, and the result of an operation that overflows Double.MinValue is NegativeInfinity, as the following example shows.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          Double value1 = 4.565e153;
          Double value2 = 6.9375e172;
          Double result = value1 * value2;
          Console.WriteLine("PositiveInfinity: {0}", 
                             Double.IsPositiveInfinity(result));
          Console.WriteLine("NegativeInfinity: {0}\n", 
                            Double.IsNegativeInfinity(result));
    
          value1 = -value1;
          result = value1 * value2;
          Console.WriteLine("PositiveInfinity: {0}", 
                             Double.IsPositiveInfinity(result));
          Console.WriteLine("NegativeInfinity: {0}", 
                            Double.IsNegativeInfinity(result));
       }
    }                                                                 
    
    // The example displays the following output:
    //       PositiveInfinity: True
    //       NegativeInfinity: False
    //       
    //       PositiveInfinity: False
    //       NegativeInfinity: True
    
    Module Example
       Public Sub Main()
          Dim value1 As Double = 4.565e153
          Dim value2 As Double = 6.9375e172
          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: True
    

    PositiveInfinity 正の被除数と 0 で除算によっても発生し、NegativeInfinity被除数を負の値に 0 による除算の結果します。PositiveInfinity also results from a division by zero with a positive dividend, and NegativeInfinity results from a division by zero with a negative dividend.

  • 浮動小数点演算が有効でない場合、操作の結果はNaNします。If a floating-point operation is invalid, the result of the operation is NaN. たとえば、NaN次の操作の結果します。For example, NaN results from the following operations:

  • 浮動小数点の操作を入力が無効です。Any floating-point operation with an invalid input. たとえば、呼び出し、Math.Sqrt負の値を持つメソッドを返しますNaN呼び出すと、Math.Acosが 1 よりも以下より大きい負の 1 つの値を持つメソッド。For example, calling the Math.Sqrt method with a negative value returns NaN, as does calling the Math.Acos method with a value that is greater than one or less than negative one.

  • 値が引数を持つすべての操作Double.NaNします。Any operation with an argument whose value is Double.NaN.

型変換と Double 構造体Type conversions and the Double structure

Double構造体は、明示的または暗黙的な変換演算子を定義していません; 代わりに、変換は、コンパイラによって実装されます。The Double structure does not define any explicit or implicit conversion operators; instead, conversions are implemented by the compiler.

任意のプリミティブ数値型の値の変換、Doubleが拡大変換したがっては明示的なキャスト演算子が必要ですか、コンパイラが明示的に要求しない限り、変換メソッドを呼び出します。The conversion of the value of any primitive numeric type to a Double is a widening conversion and therefore does not require an explicit cast operator or call to a conversion method unless a compiler explicitly requires it. C# コンパイラでからの変換、キャスト演算子が必要などDecimalDouble、Visual Basic コンパイラではありません。For example, the C# compiler requires a casting operator for conversions from Decimal to Double, while the Visual Basic compiler does not. 次の例に、他のプリミティブ数値型の最小値または最大値の変換、Doubleします。The following example converts the minimum or maximum value of other primitive numeric types to a Double.

using System;

public class Example
{
   public static void Main()
   {
      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 (var value in values) {
         if (value.GetType() == typeof(Decimal))
            dblValue = (Double) value;
         else
            dblValue = value;
         Console.WriteLine("{0} ({1}) --> {2:R} ({3})",
                           value, value.GetType().Name,
                           dblValue, 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 Example
   Public Sub Main()
      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)

さらに、SingleSingle.NaNSingle.PositiveInfinity、およびSingle.NegativeInfinityを隠ぺいされたDouble.NaNDouble.PositiveInfinity、およびDouble.NegativeInfinity、それぞれします。In addition, the Single values Single.NaN, Single.PositiveInfinity, and Single.NegativeInfinity covert to Double.NaN, Double.PositiveInfinity, and Double.NegativeInfinity, respectively.

注意するいくつかの数値型の値の変換、Double値は、精度の損失を伴うことができます。Note that the conversion of the value of some numeric types to a Double value can involve a loss of precision. 変換するときに、例に示すように、精度が失われることはDecimalInt64Single、およびUInt64Double値。As the example illustrates, a loss of precision is possible when converting Decimal, Int64, Single, and UInt64 values to Double values.

変換、Doubleの値を他のプリミティブ数値データ型の値は縮小変換とキャスト演算子 (c# で)、(Visual Basic の場合) で変換メソッドの呼び出しが必要なConvertメソッド。The conversion of a Double value to a value of any other primitive numeric data type is a narrowing conversion and requires a cast operator (in C#), a conversion method (in Visual Basic), or a call to a Convert method. 対象の種類が定義されている対象のデータ型の範囲外にある値MinValueMaxValueプロパティ、動作は次の表に示すようにします。Values that are outside the range of the target data type, which are defined by the target type's MinValue and MaxValue properties, behave as shown in the following table.

変換後の型Target type 結果Result
任意の整数型Any integral type OverflowException変換は checked コンテキストで発生した場合は例外です。An OverflowException exception if the conversion occurs in a checked context.

Unchecked コンテキスト (c# で既定値) に変換する場合は、変換操作は成功しますが、値をオーバーフローしています。If the conversion occurs in an unchecked context (the default in C#), the conversion operation succeeds but the value overflows.
Decimal OverflowException 例外。An OverflowException exception.
Single Single.NegativeInfinity 負の値。Single.NegativeInfinity for negative values.

Single.PositiveInfinity 正の値。Single.PositiveInfinity for positive values.

さらに、 Double.NaNDouble.PositiveInfinity、およびDouble.NegativeInfinityスロー、 OverflowException checked コンテキストがこれらの値のオーバーフロー unchecked コンテキストで整数に変換されるときの整数に変換します。In addition, Double.NaN, Double.PositiveInfinity, and Double.NegativeInfinity throw an OverflowException for conversions to integers in a checked context, but these values overflow when converted to integers in an unchecked context. 変換Decimal、常にスローされます、OverflowExceptionします。For conversions to Decimal, they always throw an OverflowException. 変換Singleには変換Single.NaNSingle.PositiveInfinity、およびSingle.NegativeInfinity、それぞれします。For conversions to Single, they convert to Single.NaN, Single.PositiveInfinity, and Single.NegativeInfinity, respectively.

変換によって精度の損失が可能性に注意してください、Doubleを別の数値型の値。Note that a loss of precision may result from converting a Double value to another numeric type. 変換の整数以外の場合Double値、例の出力に示す、小数部はときに失われます、Double値が (Visual Basic) のように丸められますまたは (c#) のように切り捨てられます。In the case of converting non-integral Double values, as the output from the example shows, the fractional component is lost when the Double value is either rounded (as in Visual Basic) or truncated (as in C#). 変換DecimalSingle値、Double値では、対象のデータ型を正確に表現できません。For conversions to Decimal and Single values, the Double value may not have a precise representation in the target data type.

次の例の数の変換Double他のいくつかの数値型の値。The following example converts a number of Double values to several other numeric types. Visual Basic (既定値) と c# では、checked コンテキストで、変換が行われます (のため、チェックキーワード)。The conversions occur in a checked context in Visual Basic (the default) and in C# (because of the checked keyword). 例の出力が両方チェックで変換の結果を示しています unchecked コンテキスト。The output from the example shows the result for conversions in both a checked an unchecked context. コンパイルする Visual Basic で unchecked コンテキストでの変換を行うことができます、/removeintchecks+コンパイラ スイッチと c# コメント アウトすることによって、checkedステートメント。You can perform conversions in an unchecked context in Visual Basic by compiling with the /removeintchecks+ compiler switch and in C# by commenting out the checked statement.

using System;

public class Example
{
   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("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
                                  value, value.GetType().Name,
                                  lValue, lValue.GetType().Name);
            }
            catch (OverflowException) {
               Console.WriteLine("Unable to convert {0} to Int64.", value);
            }
            try {
                UInt64 ulValue = (ulong) value;
                Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
                                  value, value.GetType().Name,
                                  ulValue, ulValue.GetType().Name);
            }
            catch (OverflowException) {
               Console.WriteLine("Unable to convert {0} to UInt64.", value);
            }
            try {
                Decimal dValue = (decimal) value;
                Console.WriteLine("{0} ({1}) --> {2} ({3})",
                                  value, value.GetType().Name,
                                  dValue, dValue.GetType().Name);
            }
            catch (OverflowException) {
               Console.WriteLine("Unable to convert {0} to Decimal.", value);
            }
            try {
                Single sValue = (float) value;
                Console.WriteLine("{0} ({1}) --> {2} ({3})",
                                  value, value.GetType().Name,
                                  sValue, sValue.GetType().Name);
            }
            catch (OverflowException) {
               Console.WriteLine("Unable to convert {0} to Single.", value);
            }
            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)
Module Example
   Public Sub Main()
      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)

数値型の変換の詳細については、次を参照してください。 .NET Framework における型変換型変換の表します。For more information on the conversion of numeric types, see Type Conversion in the .NET Framework and Type Conversion Tables.

浮動小数点の機能Floating-Point Functionality

Double構造および関連する型は、次の領域で操作を実行するメソッドを提供します。The Double structure and related types provide methods to perform operations in the following areas:

  • 値の比較します。Comparison of values. 呼び出すことができます、Equalsする 2 つかどうかを判断するメソッドDouble値が等しいか、またはCompareToメソッドを 2 つの値の間の関係を決定します。You can call the Equals method to determine whether two Double values are equal, or the CompareTo method to determine the relationship between two values.

    Double構造体には、比較演算子の完全なセットもサポートしています。The Double structure also supports a complete set of comparison operators. たとえば、等値または非等値、テストしたり、1 つの値がより大きいまたは相互に等しいかどうかを確認できます。For example, you can test for equality or inequality, or determine whether one value is greater than or equal to another. オペランドの 1 つは、数値型以外の場合、Doubleに変換されます、Double比較を実行する前にします。If one of the operands is a numeric type other than a Double, it is converted to a Double before performing the comparison.

    警告

    有効桁数の違いにより 2 つDouble値と同じと想定している可能性がありますに、等しくない場合、比較の結果に影響します。Because of differences in precision, two Double values that you expect to be equal may turn out to be unequal, which affects the result of the comparison. 参照してください、等しいかどうかテスト比較する 2 つの詳細については、セクションDouble値。See the Testing for Equality section for more information about comparing two Double values.

    呼び出すことも、 IsNaNIsInfinityIsPositiveInfinity、およびIsNegativeInfinityこれらの特殊な値をテストするメソッド。You can also call the IsNaN, IsInfinity, IsPositiveInfinity, and IsNegativeInfinity methods to test for these special values.

  • 数値演算します。Mathematical operations. 加算、減算、乗算、除算、およびなどの一般的な算術演算実装ではなく、言語コンパイラおよび共通中間言語 (CIL) の手順についてでDoubleメソッド。Common arithmetic operations, such as addition, subtraction, multiplication, and division, are implemented by language compilers and Common Intermediate Language (CIL) instructions, rather than by Double methods. 数学的演算のオペランドの 1 つは、数値型以外の場合、Doubleに変換されます、Double操作を実行する前にします。If one of the operands in a mathematical operation is a numeric type other than a Double, it is converted to a Double before performing the operation. 操作の結果も、Double値。The result of the operation is also a Double value.

    呼び出すことによって、他の算術演算を実行できるstatic(Shared Visual Basic で) 内のメソッド、System.Mathクラス。Other mathematical operations can be performed by calling static (Shared in Visual Basic) methods in the System.Math class. 演算に一般的に使用される追加のメソッドが含まれています (などMath.AbsMath.Sign、およびMath.Sqrt)、geometry (などMath.CosMath.Sin)、および微積分 (などMath.Log)。It includes additional methods commonly used for arithmetic (such as Math.Abs, Math.Sign, and Math.Sqrt), geometry (such as Math.Cos and Math.Sin), and calculus (such as Math.Log).

    内の個々 のビットを操作することも、Double値。You can also manipulate the individual bits in a Double value. BitConverter.DoubleToInt64Bitsメソッドが保持されます、 Double 64 ビット整数値ビット パターンです。The BitConverter.DoubleToInt64Bits method preserves a Double value's bit pattern in a 64-bit integer. BitConverter.GetBytes(Double)メソッドは、バイト配列内のビット パターンを返します。The BitConverter.GetBytes(Double) method returns its bit pattern in a byte array.

  • 丸め処理を行うします。Rounding. 丸め処理としてよく使用する手法と精度の浮動小数点表現の問題が原因で値の間の相違点の影響を軽減できます。Rounding is often used as a technique for reducing the impact of differences between values caused by problems of floating-point representation and precision. 丸めることができます、Double値を呼び出すことによって、Math.Roundメソッド。You can round a Double value by calling the Math.Round method.

  • 書式設定します。Formatting. 変換することができます、Doubleを呼び出すことによって文字列形式の値、ToStringメソッドまたは複合書式指定機能を使用しています。You can convert a Double value to its string representation by calling the ToString method or by using the composite formatting feature. 書式指定文字列で浮動小数点値の文字列形式を制御する方法については、次を参照してください。、 Standard Numeric Format Stringsカスタム数値書式指定文字列トピック。For information about how format strings control the string representation of floating-point values, see the Standard Numeric Format Strings and Custom Numeric Format Strings topics.

  • 文字列の解析します。Parsing strings. 浮動小数点値の文字列形式に変換することができます、Double値がいずれかを呼び出すことによって、ParseまたはTryParseメソッド。You can convert the string representation of a floating-point value to a Double value by calling either the Parse or TryParse method. 解析操作に失敗した場合、Parseメソッドは、例外をスローする、TryParseメソッドを返します。falseします。If the parse operation fails, the Parse method throws an exception, whereas the TryParse method returns false.

  • 変換の入力します。Type conversion. Double構造体の明示的なインターフェイス実装を提供する、IConvertibleインターフェイスで、2 つの標準的な .NET Framework データ型間の変換をサポートしています。The Double structure provides an explicit interface implementation for the IConvertible interface, which supports conversion between any two standard .NET Framework data types. 言語コンパイラはすべて他の標準的な数値型に値の暗黙的な変換もサポートDouble値。Language compilers also support the implicit conversion of values of all other standard numeric types to Double values. 変換する標準的な数値型の値のDouble拡大変換は、キャスト演算子または変換メソッドのユーザーは不要Conversion of a value of any standard numeric type to a Double is a widening conversion and does not require the user of a casting operator or conversion method,

    ただし、変換のInt64Single値は、精度の損失を伴うことができます。However, conversion of Int64 and Single values can involve a loss of precision. 次の表は、これらの型の有効桁数の違いを示します。The following table lists the differences in precision for each of these types:

    Type 最大有効桁数Maximum precision 内部の有効桁数Internal precision
    Double 1615 1717
    Int64 19 の 10 進数字19 decimal digits 19 の 10 進数字19 decimal digits
    Single 7 桁の 10 進数字7 decimal digits 10 進数字の 99 decimal digits

    有効桁数の問題に最も頻繁に影響Single値に変換されるDouble値。The problem of precision most frequently affects Single values that are converted to Double values. 次の例では、同一の除算演算によって生成された 2 つの値が等しくないため、値のいずれかに変換された単精度浮動小数点値をDoubleします。In the following example, two values produced by identical division operations are unequal because one of the values is a single-precision floating point value converted to a Double.

    using System;
    
    public class Example
    {
       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:           {0:R}", result1);
          Console.WriteLine(".1 Added 10 times: {0:R}", result2);
       }
    }
    // The example displays the following output:
    //       .1 * 10:           1
    //       .1 Added 10 times: 0.99999999999999989
    
    Module Example
       Public Sub Main()
          Dim value As Double = .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
    

フィールド

Epsilon Epsilon Epsilon Epsilon

ゼロより大きい最小の Double 値を表します。Represents the smallest positive Double value that is greater than zero. このフィールドは定数です。This field is constant.

MaxValue MaxValue MaxValue MaxValue

Double の最大有効値を表します。Represents the largest possible value of a Double. このフィールドは定数です。This field is constant.

MinValue MinValue MinValue MinValue

Double の最小有効値を表します。Represents the smallest possible value of a Double. このフィールドは定数です。This field is constant.

NaN NaN NaN NaN

非数 (NaN) の値を表します。Represents a value that is not a number (NaN). このフィールドは定数です。This field is constant.

NegativeInfinity NegativeInfinity NegativeInfinity NegativeInfinity

負の無限大を表します。Represents negative infinity. このフィールドは定数です。This field is constant.

PositiveInfinity PositiveInfinity PositiveInfinity PositiveInfinity

正の無限大を表します。Represents positive infinity. このフィールドは定数です。This field is constant.

方法

CompareTo(Double) CompareTo(Double) CompareTo(Double) CompareTo(Double)

このインスタンスと指定した倍精度浮動小数点数を比較し、このインスタンスの値が指定した倍精度浮動小数点数の値よりも小さいか、同じか、または大きいかを示す整数を返します。Compares this instance to a specified double-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified double-precision floating-point number.

CompareTo(Object) CompareTo(Object) CompareTo(Object) CompareTo(Object)

このインスタンスと指定したオブジェクトを比較し、このインスタンスの値が指定したオブジェクトの値よりも小さいか、同じか、または大きいかを示す整数を返します。Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.

Equals(Double) Equals(Double) Equals(Double) Equals(Double)

このインスタンスと指定した Double オブジェクトが同じ値を表しているかどうかを示す値を返します。Returns a value indicating whether this instance and a specified Double object represent the same value.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このインスタンスが指定されたオブジェクトに等しいかどうかを示す値を返します。Returns a value indicating whether this instance is equal to a specified object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

GetTypeCode() GetTypeCode() GetTypeCode() GetTypeCode()

TypeCode 値型の Double を返します。Returns the TypeCode for value type Double.

IsFinite(Double) IsFinite(Double) IsFinite(Double) IsFinite(Double)
IsInfinity(Double) IsInfinity(Double) IsInfinity(Double) IsInfinity(Double)

指定した数値が負または正の無限大と評価されるかどうかを示す値を返します。Returns a value indicating whether the specified number evaluates to negative or positive infinity

IsNaN(Double) IsNaN(Double) IsNaN(Double) IsNaN(Double)

指定した値が非数値 (NaN) かどうかを示す値を返します。Returns a value that indicates whether the specified value is not a number (NaN).

IsNegative(Double) IsNegative(Double) IsNegative(Double) IsNegative(Double)
IsNegativeInfinity(Double) IsNegativeInfinity(Double) IsNegativeInfinity(Double) IsNegativeInfinity(Double)

指定した数値が負の無限大と評価されるかどうかを示す値を返します。Returns a value indicating whether the specified number evaluates to negative infinity.

IsNormal(Double) IsNormal(Double) IsNormal(Double) IsNormal(Double)
IsPositiveInfinity(Double) IsPositiveInfinity(Double) IsPositiveInfinity(Double) IsPositiveInfinity(Double)

指定した数値が正の無限大と評価されるかどうかを示す値を返します。Returns a value indicating whether the specified number evaluates to positive infinity.

IsSubnormal(Double) IsSubnormal(Double) IsSubnormal(Double) IsSubnormal(Double)
Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の書式での数値の文字列形式を、等価の倍精度浮動小数点数に変換します。Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

指定したカルチャに固有の書式による数値の文字列形式を、それと等価な倍精度浮動小数点数に変換します。Converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Parse(String) Parse(String) Parse(String) Parse(String)

数値の文字列形式を、等価の倍精度浮動小数点数に変換します。Converts the string representation of a number to its double-precision floating-point number equivalent.

Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

数値の指定したスタイルでの文字列形式を、それと等価な倍精度浮動小数点数に変換します。Converts the string representation of a number in a specified style to its double-precision floating-point number equivalent.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

ToString(String) ToString(String) ToString(String) ToString(String)

指定した書式を使用して、このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation, using the specified format.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

ToString() ToString() ToString() ToString()

このインスタンスの数値を、それと等価な文字列形式に変換します。Converts the numeric value of this instance to its equivalent string representation.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Double) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Double) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Double) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Double)
TryParse(String, Double) TryParse(String, Double) TryParse(String, Double) TryParse(String, Double)

数値の文字列形式を、等価の倍精度浮動小数点数に変換します。Converts the string representation of a number to its double-precision floating-point number equivalent. 戻り値は変換が成功したか失敗したかを示します。A return value indicates whether the conversion succeeded or failed.

TryParse(ReadOnlySpan<Char>, Double) TryParse(ReadOnlySpan<Char>, Double) TryParse(ReadOnlySpan<Char>, Double) TryParse(ReadOnlySpan<Char>, Double)
TryParse(String, NumberStyles, IFormatProvider, Double) TryParse(String, NumberStyles, IFormatProvider, Double) TryParse(String, NumberStyles, IFormatProvider, Double) TryParse(String, NumberStyles, IFormatProvider, Double)

指定したスタイルおよびカルチャ固有の書式での数値の文字列形式を、等価の倍精度浮動小数点数に変換します。Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. 戻り値は変換が成功したか失敗したかを示します。A return value indicates whether the conversion succeeded or failed.

演算子

Equality(Double, Double) Equality(Double, Double) Equality(Double, Double) Equality(Double, Double)

指定した 2 つの Double 値が等しいかどうかを示す値を返します。Returns a value that indicates whether two specified Double values are equal.

GreaterThan(Double, Double) GreaterThan(Double, Double) GreaterThan(Double, Double) GreaterThan(Double, Double)

指定した Double 値が、指定したもう 1 つの Double 値より大きいかどうかを示す値を返します。Returns a value that indicates whether a specified Double value is greater than another specified Double value.

GreaterThanOrEqual(Double, Double) GreaterThanOrEqual(Double, Double) GreaterThanOrEqual(Double, Double) GreaterThanOrEqual(Double, Double)

指定した Double 値が、指定したもう 1 つの Double 値以上かどうかを示す値を返します。Returns a value that indicates whether a specified Double value is greater than or equal to another specified Double value.

Inequality(Double, Double) Inequality(Double, Double) Inequality(Double, Double) Inequality(Double, Double)

指定した 2 つの Double 値が等しくないかどうかを示す値を返します。Returns a value that indicates whether two specified Double values are not equal.

LessThan(Double, Double) LessThan(Double, Double) LessThan(Double, Double) LessThan(Double, Double)

指定した Double 値が、指定したもう 1 つの Double 値より小さいかどうかを示す値を返します。Returns a value that indicates whether a specified Double value is less than another specified Double value.

LessThanOrEqual(Double, Double) LessThanOrEqual(Double, Double) LessThanOrEqual(Double, Double) LessThanOrEqual(Double, Double)

指定した Double 値が、指定したもう 1 つの Double 値以下かどうかを示す値を返します。Returns a value that indicates whether a specified Double value is less than or equal to another specified Double value.

明示的なインターフェイスの実装

IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object)
IConvertible.GetTypeCode() IConvertible.GetTypeCode() IConvertible.GetTypeCode() IConvertible.GetTypeCode()
IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider)

このメンバーの詳細については、「ToBoolean(IFormatProvider)」をご覧ください。For a description of this member, see ToBoolean(IFormatProvider).

IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider)

このメンバーの詳細については、「ToByte(IFormatProvider)」をご覧ください。For a description of this member, see ToByte(IFormatProvider).

IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider)

この変換はサポートされていません。This conversion is not supported. このメソッドを使用しようとすると、InvalidCastException がスローされます。Attempting to use this method throws an InvalidCastException.

IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider)

この変換はサポートされていません。This conversion is not supported. このメソッドを使用しようとすると、InvalidCastException がスローされます。Attempting to use this method throws an InvalidCastException

IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider)

このメンバーの詳細については、「ToDecimal(IFormatProvider)」をご覧ください。For a description of this member, see ToDecimal(IFormatProvider).

IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider)

このメンバーの詳細については、「ToDouble(IFormatProvider)」をご覧ください。For a description of this member, see ToDouble(IFormatProvider).

IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider)

このメンバーの詳細については、「ToInt16(IFormatProvider)」をご覧ください。For a description of this member, see ToInt16(IFormatProvider).

IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider)

このメンバーの詳細については、「ToInt32(IFormatProvider)」をご覧ください。For a description of this member, see ToInt32(IFormatProvider).

IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider)

このメンバーの詳細については、「ToInt64(IFormatProvider)」をご覧ください。For a description of this member, see ToInt64(IFormatProvider).

IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider)

このメンバーの詳細については、「ToSByte(IFormatProvider)」をご覧ください。For a description of this member, see ToSByte(IFormatProvider).

IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider)

このメンバーの詳細については、「ToSingle(IFormatProvider)」をご覧ください。For a description of this member, see ToSingle(IFormatProvider).

IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider)

このメンバーの詳細については、「ToType(Type, IFormatProvider)」をご覧ください。For a description of this member, see ToType(Type, IFormatProvider).

IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider)

このメンバーの詳細については、「ToUInt16(IFormatProvider)」をご覧ください。For a description of this member, see ToUInt16(IFormatProvider).

IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider)

このメンバーの詳細については、「ToUInt32(IFormatProvider)」をご覧ください。For a description of this member, see ToUInt32(IFormatProvider).

IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider)

このメンバーの詳細については、「ToUInt64(IFormatProvider)」をご覧ください。For a description of this member, see ToUInt64(IFormatProvider).

適用対象

スレッド セーフ

この種類のすべてのメンバーは、スレッド セーフです。All members of this type are thread safe. インスタンスの状態を変更する表示されるメンバーは、実際に新しい値で初期化された新しいインスタンスを返します。Members that appear to modify instance state actually return a new instance initialized with the new value. として、他の種類と読み取りと書き込みをこの型のインスタンスを含む共有変数を保護する必要があるスレッド セーフを確保するロックによって。As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.

こちらもご覧ください