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 e308 から正の 1.79769313486232 e308 までの値を持ち、正または負の0、 PositiveInfinityNegativeInfinity、およびではない値を持つ倍精度64ビット数値を表します (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). これは、非常に大きな値 (惑星または galaxies 間の距離など) または非常に小さい値 (キログラムにおける物質の分子質量) を表すことを目的としており、多くの場合、(地球から他の太陽システムへの距離など) 不正確になることがあります。Double type は、バイナリ浮動小数点演算の 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 BitsBits
有効桁または仮数Significand or mantissa 0-510-51
累乗Exponent 52-6252-62
符号 (0 = 正、1 = 負)Sign (0 = Positive, 1 = Negative) 6363

10分の分数では、一部の小数部 (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 によって正確に表される1/10 は、001100110011によって "0011" というパターンで無限大として表現されます。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. たとえば、0.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. この不均衡は、"R"標準の数値書式指定文字列を使用して2つDouble Doubleの値を表示する場合にのみ表示されます。必要に応じて、型でサポートされている17桁のすべての有効桁数が表示されます。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. Double値の有効桁数は最大で15桁ですが、内部的には最大17桁が保持されます。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. 非常に大きな浮動小数点値を定義し、の積と1つDouble.Epsilonの quadrillion を追加します。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. 最下位桁は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)ステートメント内の書式項目をおよび{1}から{0}{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. 前の例では、0.1 を10で乗算し、を1回追加した結果を表示しています。A previous example illustrated this by displaying the result of multiplying .1 by 10 and adding .1 times.

    小数部の値を持つ数値演算の精度が重要な場合はDecimalDouble型ではなくを使用できます。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. 次の例では、 Double 3 つの値が文字列に変換され、ファイルに保存されます。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
    

    この場合、次の例に示すように、値のDouble完全な有効桁数を保持するために "G17" 標準の数値書式指定文字列を使用すると、値が正常にラウンドトリップされることがあります。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. 多くの場合、一見同等DoubleSingle値に変換される値は、精度が異なるため、値と等しくありません。DoubleA Single value that is converted to a seemingly equivalent Double often does not equal the Double value because of differences in precision. 次の例では、同じ除算演算の結果がDouble Singleとの値に割り当てられています。In the following example, the result of identical division operations is assigned to a Double and a Single value. 値がにキャストされた後、2つの値の比較によって等しくないことが示されます。Double SingleAfter 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.42330604244772 e-305 と、値が-4.42330604244772 e-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

等しいと見なされるためにDoubleは、2つの値が同一の値を表す必要があります。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. 結果として、2つEqualsの値が等しいかどうかを判断するためにメソッド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つの目に等しい値は、最初の精度が15桁で、2番目の値が17であるため、等しくないようになります。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. 次の例では、 Double 1 つの値が二乗で、平方根が計算され、元の値が復元されます。In the following example, one Double value is squared, and then the square root is calculated to restore the original value. 2番Double目のは、結果の平方根が3.51 で除算され、元の値が復元される前に、3.51 と二乗が乗算されます。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. "R" 標準書式指定文字列を使用して、各 Double 値のすべての有効桁数を表示する結果文字列を返すと、2番目の値が .0000000000001 未満であることが示されます。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:

  • 2つ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できる最小値を測定します。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.MinValueする操作NegativeInfinityの結果はになります。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以上の値または負の値を持つメソッドを呼び出した場合と同じです。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)

また、、、 SingleおよびSingle.NaN Double.NegativeInfinity Double.NaN Double.PositiveInfinityの各Single.PositiveInfinity値は、それぞれ、、およびにSingle.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. 例に示すように、 Decimal Single、、、およびUInt64Int64値を値にDouble変換する場合、精度が低下する可能性があります。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. 対象のデータ型の範囲外の値 (対象の型のMinValueおよびMaxValueプロパティによって定義される) は、次の表に示すように動作します。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 Checked コンテキストで変換が発生した場合の例外。OverflowExceptionAn 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.NaN Double.NegativeInfinity OverflowException 、、、およびは、checked コンテキストで整数への変換のためにをスローしますが、これらの値は unchecked コンテキストで整数に変換されるとオーバーフローします。 Double.PositiveInfinityIn 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#). 値およびDecimal Single値への変換で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). この例の出力は、チェックされていないコンテキストでの変換の結果を示しています。The output from the example shows the result for conversions in both a checked an unchecked context. /removeintchecks+コンパイラスイッチを使用してコンパイルし、でC# checkedステートメントをコメントアウトすることで、Visual Basic の unchecked コンテキストで変換を実行できます。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. たとえば、等値または非等値をテストしたり、一方の値がもう一方の値以上かどうかを調べたりすることができます。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.

    警告

    精度の違いにより、等しいDoubleと予想される2つの値が等しくないと見なされることがあります。これは、比較の結果に影響します。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.

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

  • 算術演算Mathematical operations. 加算、減算、乗算、除算などの一般的な算術演算は、言語コンパイラと、メソッドでDoubleはなく、共通中間言語 (CIL) 命令によって実装されます。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 System.MathクラスでShared (Visual Basic) メソッドを呼び出すことによって実行できます。Other mathematical operations can be performed by calling static (Shared in Visual Basic) methods in the System.Math class. Math.Absこれには、 Math.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. 値はDoubleMath.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. 書式指定文字列による浮動小数点値の文字列形式の制御方法の詳細については、「標準の数値書式指定文字列」および「カスタム数値書式指定文字列」を参照してください。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. ParseまたDoubleTryParseメソッドを呼び出すことにより、浮動小数点値の文字列形式を値に変換できます。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体は、任意の2つのIConvertible標準 .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,

    ただし、値とInt64 Single値の変換には精度の低下が伴います。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 1515 1717
    Int64 19桁の10進数19 decimal digits 19桁の10進数19 decimal digits
    Single 7桁の10進数7 decimal digits 9桁の10進数9 decimal digits

    精度の問題は、値にSingle変換される値にDouble最も頻繁に影響を及ぼします。The problem of precision most frequently affects Single values that are converted to Double values. 次の例では、値の1つがにDouble変換された単精度浮動小数点値であるため、同一の除算演算によって生成される2つの値が等しくありません。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)

指定の値が有限 (ゼロ、非正規、または正規) かどうかを判断します。Determines whether the specified value is finite (zero, subnormal, or normal).

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)

指定した値が負かどうかを判断します。Determines whether the specified value is negative.

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)

指定した値が正規かどうかを判断します。Determines whether the specified value is normal.

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)

指定した値が非正規かどうかを判断します。Determines whether the specified value is subnormal.

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.

こちらもご覧ください