Single 구조체

정의

단정밀도 부동 소수점 숫자를 나타냅니다.

public value class float : IComparable, IComparable<float>, IConvertible, IEquatable<float>, IFormattable
public value class float : IComparable, IComparable<float>, IConvertible, IEquatable<float>, ISpanFormattable
public value class float : IComparable<float>, IConvertible, IEquatable<float>, IParsable<float>, ISpanParsable<float>, System::Numerics::IAdditionOperators<float, float, float>, System::Numerics::IAdditiveIdentity<float, float>, System::Numerics::IBinaryFloatingPointIeee754<float>, System::Numerics::IBinaryNumber<float>, System::Numerics::IBitwiseOperators<float, float, float>, System::Numerics::IComparisonOperators<float, float, bool>, System::Numerics::IDecrementOperators<float>, System::Numerics::IDivisionOperators<float, float, float>, System::Numerics::IEqualityOperators<float, float, bool>, System::Numerics::IExponentialFunctions<float>, System::Numerics::IFloatingPoint<float>, System::Numerics::IFloatingPointConstants<float>, System::Numerics::IFloatingPointIeee754<float>, System::Numerics::IHyperbolicFunctions<float>, System::Numerics::IIncrementOperators<float>, System::Numerics::ILogarithmicFunctions<float>, System::Numerics::IMinMaxValue<float>, System::Numerics::IModulusOperators<float, float, float>, System::Numerics::IMultiplicativeIdentity<float, float>, System::Numerics::IMultiplyOperators<float, float, float>, System::Numerics::INumber<float>, System::Numerics::INumberBase<float>, System::Numerics::IPowerFunctions<float>, System::Numerics::IRootFunctions<float>, System::Numerics::ISignedNumber<float>, System::Numerics::ISubtractionOperators<float, float, float>, System::Numerics::ITrigonometricFunctions<float>, System::Numerics::IUnaryNegationOperators<float, float>, System::Numerics::IUnaryPlusOperators<float, float>
public value class float : IComparable<float>, IConvertible, IEquatable<float>, IParsable<float>, ISpanParsable<float>, IUtf8SpanFormattable, IUtf8SpanParsable<float>, System::Numerics::IAdditionOperators<float, float, float>, System::Numerics::IAdditiveIdentity<float, float>, System::Numerics::IBinaryFloatingPointIeee754<float>, System::Numerics::IBinaryNumber<float>, System::Numerics::IBitwiseOperators<float, float, float>, System::Numerics::IComparisonOperators<float, float, bool>, System::Numerics::IDecrementOperators<float>, System::Numerics::IDivisionOperators<float, float, float>, System::Numerics::IEqualityOperators<float, float, bool>, System::Numerics::IExponentialFunctions<float>, System::Numerics::IFloatingPoint<float>, System::Numerics::IFloatingPointConstants<float>, System::Numerics::IFloatingPointIeee754<float>, System::Numerics::IHyperbolicFunctions<float>, System::Numerics::IIncrementOperators<float>, System::Numerics::ILogarithmicFunctions<float>, System::Numerics::IMinMaxValue<float>, System::Numerics::IModulusOperators<float, float, float>, System::Numerics::IMultiplicativeIdentity<float, float>, System::Numerics::IMultiplyOperators<float, float, float>, System::Numerics::INumber<float>, System::Numerics::INumberBase<float>, System::Numerics::IPowerFunctions<float>, System::Numerics::IRootFunctions<float>, System::Numerics::ISignedNumber<float>, System::Numerics::ISubtractionOperators<float, float, float>, System::Numerics::ITrigonometricFunctions<float>, System::Numerics::IUnaryNegationOperators<float, float>, System::Numerics::IUnaryPlusOperators<float, float>
public value class float : IComparable, IConvertible, IFormattable
public value class float : IComparable, IComparable<float>, IEquatable<float>, IFormattable
public struct Single : IComparable, IComparable<float>, IConvertible, IEquatable<float>, IFormattable
public readonly struct Single : IComparable, IComparable<float>, IConvertible, IEquatable<float>, IFormattable
public readonly struct Single : IComparable, IComparable<float>, IConvertible, IEquatable<float>, ISpanFormattable
public readonly struct Single : IComparable<float>, IConvertible, IEquatable<float>, IParsable<float>, ISpanParsable<float>, System.Numerics.IAdditionOperators<float,float,float>, System.Numerics.IAdditiveIdentity<float,float>, System.Numerics.IBinaryFloatingPointIeee754<float>, System.Numerics.IBinaryNumber<float>, System.Numerics.IBitwiseOperators<float,float,float>, System.Numerics.IComparisonOperators<float,float,bool>, System.Numerics.IDecrementOperators<float>, System.Numerics.IDivisionOperators<float,float,float>, System.Numerics.IEqualityOperators<float,float,bool>, System.Numerics.IExponentialFunctions<float>, System.Numerics.IFloatingPoint<float>, System.Numerics.IFloatingPointConstants<float>, System.Numerics.IFloatingPointIeee754<float>, System.Numerics.IHyperbolicFunctions<float>, System.Numerics.IIncrementOperators<float>, System.Numerics.ILogarithmicFunctions<float>, System.Numerics.IMinMaxValue<float>, System.Numerics.IModulusOperators<float,float,float>, System.Numerics.IMultiplicativeIdentity<float,float>, System.Numerics.IMultiplyOperators<float,float,float>, System.Numerics.INumber<float>, System.Numerics.INumberBase<float>, System.Numerics.IPowerFunctions<float>, System.Numerics.IRootFunctions<float>, System.Numerics.ISignedNumber<float>, System.Numerics.ISubtractionOperators<float,float,float>, System.Numerics.ITrigonometricFunctions<float>, System.Numerics.IUnaryNegationOperators<float,float>, System.Numerics.IUnaryPlusOperators<float,float>
public readonly struct Single : IComparable<float>, IConvertible, IEquatable<float>, IParsable<float>, ISpanParsable<float>, IUtf8SpanFormattable, IUtf8SpanParsable<float>, System.Numerics.IAdditionOperators<float,float,float>, System.Numerics.IAdditiveIdentity<float,float>, System.Numerics.IBinaryFloatingPointIeee754<float>, System.Numerics.IBinaryNumber<float>, System.Numerics.IBitwiseOperators<float,float,float>, System.Numerics.IComparisonOperators<float,float,bool>, System.Numerics.IDecrementOperators<float>, System.Numerics.IDivisionOperators<float,float,float>, System.Numerics.IEqualityOperators<float,float,bool>, System.Numerics.IExponentialFunctions<float>, System.Numerics.IFloatingPoint<float>, System.Numerics.IFloatingPointConstants<float>, System.Numerics.IFloatingPointIeee754<float>, System.Numerics.IHyperbolicFunctions<float>, System.Numerics.IIncrementOperators<float>, System.Numerics.ILogarithmicFunctions<float>, System.Numerics.IMinMaxValue<float>, System.Numerics.IModulusOperators<float,float,float>, System.Numerics.IMultiplicativeIdentity<float,float>, System.Numerics.IMultiplyOperators<float,float,float>, System.Numerics.INumber<float>, System.Numerics.INumberBase<float>, System.Numerics.IPowerFunctions<float>, System.Numerics.IRootFunctions<float>, System.Numerics.ISignedNumber<float>, System.Numerics.ISubtractionOperators<float,float,float>, System.Numerics.ITrigonometricFunctions<float>, System.Numerics.IUnaryNegationOperators<float,float>, System.Numerics.IUnaryPlusOperators<float,float>
[System.Serializable]
public struct Single : IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Single : IComparable, IComparable<float>, IConvertible, IEquatable<float>, IFormattable
public struct Single : IComparable, IComparable<float>, IEquatable<float>, IFormattable
type single = struct
    interface IConvertible
    interface IFormattable
type single = struct
    interface IConvertible
    interface ISpanFormattable
    interface IFormattable
type single = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<single>
    interface ISpanFormattable
    interface ISpanParsable<single>
    interface IAdditionOperators<single, single, single>
    interface IAdditiveIdentity<single, single>
    interface IBinaryFloatingPointIeee754<single>
    interface IBinaryNumber<single>
    interface IBitwiseOperators<single, single, single>
    interface IComparisonOperators<single, single, bool>
    interface IEqualityOperators<single, single, bool>
    interface IDecrementOperators<single>
    interface IDivisionOperators<single, single, single>
    interface IIncrementOperators<single>
    interface IModulusOperators<single, single, single>
    interface IMultiplicativeIdentity<single, single>
    interface IMultiplyOperators<single, single, single>
    interface INumber<single>
    interface INumberBase<single>
    interface ISubtractionOperators<single, single, single>
    interface IUnaryNegationOperators<single, single>
    interface IUnaryPlusOperators<single, single>
    interface IExponentialFunctions<single>
    interface IFloatingPointConstants<single>
    interface IFloatingPoint<single>
    interface ISignedNumber<single>
    interface IFloatingPointIeee754<single>
    interface IHyperbolicFunctions<single>
    interface ILogarithmicFunctions<single>
    interface IPowerFunctions<single>
    interface IRootFunctions<single>
    interface ITrigonometricFunctions<single>
    interface IMinMaxValue<single>
type single = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<single>
    interface ISpanFormattable
    interface ISpanParsable<single>
    interface IAdditionOperators<single, single, single>
    interface IAdditiveIdentity<single, single>
    interface IBinaryFloatingPointIeee754<single>
    interface IBinaryNumber<single>
    interface IBitwiseOperators<single, single, single>
    interface IComparisonOperators<single, single, bool>
    interface IEqualityOperators<single, single, bool>
    interface IDecrementOperators<single>
    interface IDivisionOperators<single, single, single>
    interface IIncrementOperators<single>
    interface IModulusOperators<single, single, single>
    interface IMultiplicativeIdentity<single, single>
    interface IMultiplyOperators<single, single, single>
    interface INumber<single>
    interface INumberBase<single>
    interface ISubtractionOperators<single, single, single>
    interface IUnaryNegationOperators<single, single>
    interface IUnaryPlusOperators<single, single>
    interface IUtf8SpanParsable<single>
    interface IExponentialFunctions<single>
    interface IFloatingPointConstants<single>
    interface IFloatingPoint<single>
    interface ISignedNumber<single>
    interface IFloatingPointIeee754<single>
    interface IHyperbolicFunctions<single>
    interface ILogarithmicFunctions<single>
    interface IPowerFunctions<single>
    interface IRootFunctions<single>
    interface ITrigonometricFunctions<single>
    interface IMinMaxValue<single>
    interface IUtf8SpanFormattable
[<System.Serializable>]
type single = struct
    interface IFormattable
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type single = struct
    interface IFormattable
    interface IConvertible
type single = struct
    interface IFormattable
Public Structure Single
Implements IComparable, IComparable(Of Single), IConvertible, IEquatable(Of Single), IFormattable
Public Structure Single
Implements IComparable, IComparable(Of Single), IConvertible, IEquatable(Of Single), ISpanFormattable
Public Structure Single
Implements IAdditionOperators(Of Single, Single, Single), IAdditiveIdentity(Of Single, Single), IBinaryFloatingPointIeee754(Of Single), IBinaryNumber(Of Single), IBitwiseOperators(Of Single, Single, Single), IComparable(Of Single), IComparisonOperators(Of Single, Single, Boolean), IConvertible, IDecrementOperators(Of Single), IDivisionOperators(Of Single, Single, Single), IEqualityOperators(Of Single, Single, Boolean), IEquatable(Of Single), IExponentialFunctions(Of Single), IFloatingPoint(Of Single), IFloatingPointConstants(Of Single), IFloatingPointIeee754(Of Single), IHyperbolicFunctions(Of Single), IIncrementOperators(Of Single), ILogarithmicFunctions(Of Single), IMinMaxValue(Of Single), IModulusOperators(Of Single, Single, Single), IMultiplicativeIdentity(Of Single, Single), IMultiplyOperators(Of Single, Single, Single), INumber(Of Single), INumberBase(Of Single), IParsable(Of Single), IPowerFunctions(Of Single), IRootFunctions(Of Single), ISignedNumber(Of Single), ISpanParsable(Of Single), ISubtractionOperators(Of Single, Single, Single), ITrigonometricFunctions(Of Single), IUnaryNegationOperators(Of Single, Single), IUnaryPlusOperators(Of Single, Single)
Public Structure Single
Implements IAdditionOperators(Of Single, Single, Single), IAdditiveIdentity(Of Single, Single), IBinaryFloatingPointIeee754(Of Single), IBinaryNumber(Of Single), IBitwiseOperators(Of Single, Single, Single), IComparable(Of Single), IComparisonOperators(Of Single, Single, Boolean), IConvertible, IDecrementOperators(Of Single), IDivisionOperators(Of Single, Single, Single), IEqualityOperators(Of Single, Single, Boolean), IEquatable(Of Single), IExponentialFunctions(Of Single), IFloatingPoint(Of Single), IFloatingPointConstants(Of Single), IFloatingPointIeee754(Of Single), IHyperbolicFunctions(Of Single), IIncrementOperators(Of Single), ILogarithmicFunctions(Of Single), IMinMaxValue(Of Single), IModulusOperators(Of Single, Single, Single), IMultiplicativeIdentity(Of Single, Single), IMultiplyOperators(Of Single, Single, Single), INumber(Of Single), INumberBase(Of Single), IParsable(Of Single), IPowerFunctions(Of Single), IRootFunctions(Of Single), ISignedNumber(Of Single), ISpanParsable(Of Single), ISubtractionOperators(Of Single, Single, Single), ITrigonometricFunctions(Of Single), IUnaryNegationOperators(Of Single, Single), IUnaryPlusOperators(Of Single, Single), IUtf8SpanFormattable, IUtf8SpanParsable(Of Single)
Public Structure Single
Implements IComparable, IConvertible, IFormattable
Public Structure Single
Implements IComparable, IComparable(Of Single), IEquatable(Of Single), IFormattable
상속
Single
특성
구현
IComparable IComparable<Single> IConvertible IEquatable<Single> IFormattable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Single> IParsable<TSelf> ISpanParsable<Single> ISpanParsable<TSelf> IAdditionOperators<Single,Single,Single> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Single,Single> IAdditiveIdentity<TSelf,TSelf> IBinaryFloatingPointIeee754<Single> IBinaryNumber<Single> IBinaryNumber<TSelf> IBitwiseOperators<Single,Single,Single> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<Single,Single,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Single> IDecrementOperators<TSelf> IDivisionOperators<Single,Single,Single> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Single,Single,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IExponentialFunctions<Single> IExponentialFunctions<TSelf> IFloatingPoint<Single> IFloatingPoint<TSelf> IFloatingPointConstants<Single> IFloatingPointConstants<TSelf> IFloatingPointIeee754<Single> IFloatingPointIeee754<TSelf> IHyperbolicFunctions<Single> IHyperbolicFunctions<TSelf> IIncrementOperators<Single> IIncrementOperators<TSelf> ILogarithmicFunctions<Single> ILogarithmicFunctions<TSelf> IMinMaxValue<Single> IModulusOperators<Single,Single,Single> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Single,Single> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Single,Single,Single> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Single> INumber<TSelf> INumberBase<Single> INumberBase<TSelf> IPowerFunctions<Single> IPowerFunctions<TSelf> IRootFunctions<Single> IRootFunctions<TSelf> ISignedNumber<Single> ISignedNumber<TSelf> ISubtractionOperators<Single,Single,Single> ISubtractionOperators<TSelf,TSelf,TSelf> ITrigonometricFunctions<Single> ITrigonometricFunctions<TSelf> IUnaryNegationOperators<Single,Single> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Single,Single> IUnaryPlusOperators<TSelf,TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Single> IUtf8SpanParsable<TSelf>

설명

값 형식은 Single 음수 3.402823e38에서 양수 3.402823e38까지의 값과 숫자(NaN)가 아닌 양수 또는 음수 0, PositiveInfinity, , NegativeInfinity등으로 구성된 단정밀도 32비트 숫자를 나타냅니다. 이는 매우 크거나(예: 행성이나 은하 사이의 거리) 또는 매우 작은 값(예: 킬로그램의 물질의 분자 질량)과 종종 부정확한 값(예: 지구에서 다른 태양계까지의 거리)을 나타내기 위한 것입니다. 형식은 이 Single 진 부동 소수점 산술에 대한 IEC 60559:1989(IEEE 754) 표준을 준수합니다.

이 문서는 다음 섹션으로 구성됩니다.

System.Single는 이 형식의 인스턴스를 비교하고, instance 값을 해당 문자열 표현으로 변환하고, 숫자의 문자열 표현을 이 형식의 instance 변환하는 메서드를 제공합니다. 서식 사양 코드가 값 형식의 문자열 표현을 제어하는 방법에 대한 자세한 내용은 서식 형식, 표준 숫자 형식 문자열사용자 지정 숫자 서식 문자열을 참조하세요.

부동 소수점 표현 및 정밀도

데이터 형식은 Single 다음 표와 같이 단정밀도 부동 소수점 값을 32비트 이진 형식으로 저장합니다.

파트 비트
Significand 또는 mantissa 0-22
지수 23-30
기호(0 = 긍정, 1 = 음수) 31

소수 자릿수가 일부 소수 값(예: 1/3 또는 Math.PI)을 정확하게 나타낼 수 없는 것처럼 이진 분수는 일부 소수 값을 나타낼 수 없습니다. 예를 들어 .2로 정확하게 10진수로 표현되는 2/10은 .0011111001001100 이진 분수로 표현되며 무한대로 반복되는 패턴은 "1100"입니다. 이 경우 부동 소수점 값은 나타내는 숫자의 부정확한 표현을 제공합니다. 원래 부동 소수점 값에 대해 추가 수학 연산을 수행하면 정밀도가 부족한 경우가 많습니다. 예를 들어 .3을 10으로 곱하고 .3을 .3에 9번 추가하는 결과를 비교하면 곱하기보다 8개의 연산이 더 많이 포함되기 때문에 더하기가 정확하지 않은 결과를 생성하는 것을 볼 수 있습니다. 이 차이는 "R" 표준 숫자 형식 문자열을 사용하여 두 Single 값을 표시하는 경우에만 명백합니다. 필요한 경우 형식에서 지원하는 Single 전체 자릿수의 9자리를 모두 표시합니다.

using System;

public class Example
{
   public static void Main()
   {
      Single value = .2f;
      Single result1 = value * 10f;
      Single result2 = 0f;
      for (int ctr = 1; ctr <= 10; ctr++)
         result2 += value;

      Console.WriteLine(".2 * 10:           {0:R}", result1);
      Console.WriteLine(".2 Added 10 times: {0:R}", result2);
   }
}
// The example displays the following output:
//       .2 * 10:           2
//       .2 Added 10 times: 2.00000024
let value = 0.2f
let result1 = value * 10f
let mutable result2 = 0f
for _ = 1 to 10 do
    result2 <- result2 + value

printfn $".2 * 10:           {result1:R}"
printfn $".2 Added 10 times: {result2:R}"
// The example displays the following output:
//       .2 * 10:           2
//       .2 Added 10 times: 2.00000024
Module Example
   Public Sub Main()
      Dim value As Single = .2
      Dim result1 As Single = value * 10
      Dim result2 As Single
      For ctr As Integer = 1 To 10
         result2 += value
      Next
      Console.WriteLine(".2 * 10:           {0:R}", result1)
      Console.WriteLine(".2 Added 10 times: {0:R}", result2)
   End Sub
End Module
' The example displays the following output:
'       .2 * 10:           2
'       .2 Added 10 times: 2.00000024

일부 숫자는 소수점 이진 값으로 정확하게 나타낼 수 없으므로 부동 소수점 숫자는 대략적인 실수만 할 수 있습니다.

모든 부동 소수점 숫자는 제한된 수의 유효 자릿수를 가지며, 이는 부동 소수점 값이 실제 숫자와 얼마나 정확하게 일치하는지를 결정합니다. Single 값의 전체 자릿수는 최대 7자리이지만 내부적으로는 최대 9자리가 유지됩니다. 즉, 일부 부동 소수점 연산에는 부동 소수점 값을 변경할 정밀도가 부족할 수 있습니다. 다음 예제에서는 큰 단정밀도 부동 소수점 값을 정의한 다음 의 곱 Single.Epsilon 과 1개의 사분면을 추가합니다. 그러나 제품이 너무 작아서 원래 부동 소수점 값을 수정할 수 없습니다. 가장 중요한 숫자는 천 자리인 반면 제품에서 가장 중요한 숫자는 10-30입니다.

using System;

public class Example
{
   public static void Main()
   {
      Single value = 123.456f;
      Single additional = Single.Epsilon * 1e15f;
      Console.WriteLine($"{value} + {additional} = {value + additional}");
   }
}
// The example displays the following output:
//    123.456 + 1.401298E-30 = 123.456
open System

let value = 123.456f
let additional = Single.Epsilon * 1e15f
printfn $"{value} + {additional} = {value + additional}"
// The example displays the following output:
//    123.456 + 1.401298E-30 = 123.456
Module Example
   Public Sub Main()
      Dim value As Single = 123.456
      Dim additional As Single = Single.Epsilon * 1e15
      Console.WriteLine($"{value} + {additional} = {value + additional}")
   End Sub
End Module
' The example displays the following output:
'   123.456 + 1.401298E-30 = 123.456

부동 소수점 수의 제한된 정밀도에는 다음과 같은 몇 가지 결과가 있습니다.

  • 특정 전체 자릿수에서 동일하게 나타나는 두 개의 부동 소수점 숫자는 최소 유효 자릿수가 다르므로 동일하게 비교되지 않을 수 있습니다. 다음 예제에서는 일련의 숫자가 함께 추가되고 합계가 예상 합계와 비교됩니다. 두 값이 같은 것처럼 보이지만 메서드를 호출하면 Equals 그렇지 않음을 나타냅니다.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          Single[] values = { 10.01f, 2.88f, 2.88f, 2.88f, 9.0f };
          Single result = 27.65f;
          Single total = 0f;
          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 (27.65) does not equal the total (27.65).   
    //
    // 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.6500015) does not equal the total (27.65).
    
    let values = [| 10.01f; 2.88f; 2.88f; 2.88f; 9f |]
    let result = 27.65f
    let mutable total = 0f
    for value in values do
        total <- total + value
    
    if total.Equals result then
        printfn "The sum of the values equals the total."
    else
        printfn "The sum of the values ({total}) does not equal the total ({result})."
    // The example displays the following output:
    //      The sum of the values (27.65) does not equal the total (27.65).   
    //
    // 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.6500015) does not equal the total (27.65).
    
    Module Example
       Public Sub Main()
          Dim values() As Single = { 10.01, 2.88, 2.88, 2.88, 9.0 }
          Dim result As Single = 27.65
          Dim total As Single
          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 (27.65) does not equal the total (27.65).   
    '
    ' 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}{0:R}{1}{1:R} 로 변경하여 두 Single 값의 모든 중요한 숫자를 표시하는 경우 추가 작업 중에 전체 자릿수가 손실되어 두 값이 같지 않은 것이 분명합니다. 이 경우 비교를 수행하기 전에 메서드를 호출 Math.Round(Double, Int32) 하여 값을 원하는 전체 자릿수로 반올림 Single 하여 문제를 해결할 수 있습니다.

  • 부동 소수점 숫자를 사용하는 수학 또는 비교 연산은 이진 부동 소수점 숫자가 10진수와 같지 않을 수 있기 때문에 소수점 숫자를 사용하는 경우 동일한 결과를 생성하지 못할 수 있습니다. 이전 예제에서는 .3을 10으로 곱하고 .3을 .3에 9번 추가하는 결과를 표시하여 이를 설명했습니다.

    소수 값이 있는 숫자 연산의 정확도가 중요한 경우 형식 대신 형식을 Single 사용합니다Decimal. 정수 값이 또는 UInt64 형식 범위를 벗어나는 숫자 연산의 Int64 정확도가 중요한 경우 형식을 BigInteger 사용합니다.

  • 부동 소수점 숫자가 포함된 경우 값이 왕복하지 않을 수 있습니다. 값은 연산이 원래 부동 소수점 숫자를 다른 폼으로 변환하고, 역 연산이 변환된 폼을 부동 소수점 숫자로 다시 변환하고, 최종 부동 소수점 숫자가 원래 부동 소수점 숫자와 같으면 왕복이라고 합니다. 변환 시 하나 이상의 유효 자릿수가 손실되거나 변경되어 왕복이 실패할 수 있습니다. 다음 예제에서는 세 Single 가지 값이 문자열로 변환되고 파일에 저장됩니다. 출력에서 보여 주듯이 값이 동일해 보이지만 복원된 값은 원래 값과 같지 않습니다.

    using System;
    using System.IO;
    
    public class Example
    {
       public static void Main()
       {
          StreamWriter sw = new StreamWriter(@".\Singles.dat");
          Single[] values = { 3.2f/1.11f, 1.0f/3f, (float) Math.PI };
          for (int ctr = 0; ctr < values.Length; ctr++) {
             sw.Write(values[ctr].ToString());
             if (ctr != values.Length - 1)
                sw.Write("|");
          }      
          sw.Close();
          
          Single[] restoredValues = new Single[values.Length];
          StreamReader sr = new StreamReader(@".\Singles.dat");
          string temp = sr.ReadToEnd();
          string[] tempStrings = temp.Split('|');
          for (int ctr = 0; ctr < tempStrings.Length; ctr++)
             restoredValues[ctr] = Single.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.882883 <> 2.882883
    //       0.3333333 <> 0.3333333
    //       3.141593 <> 3.141593
    
    open System
    open System.IO
    
    let values = [| 3.2f / 1.11f; 1f / 3f; MathF.PI |]
    
    do
        use sw = new StreamWriter(@".\Singles.dat")
        for i = 0 to values.Length - 1 do
            sw.Write(string values[i])
            if i <> values.Length - 1 then
                sw.Write "|"
    
    let restoredValues =
        use sr = new StreamReader(@".\Singles.dat")
        sr.ReadToEnd().Split '|'
        |> Array.map Single.Parse
    
    for i = 0 to values.Length - 1 do
        printfn $"""{values[i]} {if values[i].Equals restoredValues[i] then "=" else "<>"} {restoredValues[i]}"""
                        
    // The example displays the following output:
    //       2.882883 <> 2.882883
    //       0.3333333 <> 0.3333333
    //       3.141593 <> 3.141593
    
    Imports System.IO
    
    Module Example
       Public Sub Main()
          Dim sw As New StreamWriter(".\Singles.dat")
          Dim values() As Single = { 3.2/1.11, 1.0/3, CSng(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 Single
          Dim sr As New StreamReader(".\Singles.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) = Single.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.882883 <> 2.882883
    '        0.3333333 <> 0.3333333
    '        3.141593 <> 3.141593
    

    이 경우 다음 예제와 같이 "G9" 표준 숫자 형식 문자열 을 사용하여 값의 Single 전체 전체 전체 자릿수를 유지하여 값을 성공적으로 라운드트립할 수 있습니다.

    using System;
    using System.IO;
    
    public class Example
    {
       public static void Main()
       {
          StreamWriter sw = new StreamWriter(@".\Singles.dat");
          Single[] values = { 3.2f/1.11f, 1.0f/3f, (float) Math.PI };
          for (int ctr = 0; ctr < values.Length; ctr++) 
             sw.Write("{0:G9}{1}", values[ctr], ctr < values.Length - 1 ? "|" : "" );
          
          sw.Close();
          
          Single[] restoredValues = new Single[values.Length];
          StreamReader sr = new StreamReader(@".\Singles.dat");
          string temp = sr.ReadToEnd();
          string[] tempStrings = temp.Split('|');
          for (int ctr = 0; ctr < tempStrings.Length; ctr++)
             restoredValues[ctr] = Single.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.882883 = 2.882883
    //       0.3333333 = 0.3333333
    //       3.141593 = 3.141593
    
    open System
    open System.IO
    
    let values = [| 3.2f / 1.11f; 1f / 3f; MathF.PI |]
    
    do
        use sw = new StreamWriter(@".\Singles.dat")
        for i = 0 to values.Length - 1 do
            sw.Write $"""{values[i]:G9}{if i < values.Length - 1 then "|" else ""}"""
        
        
    let restoredValues =
        use sr = new StreamReader(@".\Singles.dat")
        sr.ReadToEnd().Split '|'
        |> Array.map Single.Parse
    
    for i = 0 to values.Length - 1 do
        printfn $"""{values[i]} {if values[i].Equals restoredValues[i] then "=" else "<>"} {restoredValues[i]}"""
    // The example displays the following output:
    //       2.882883 = 2.882883
    //       0.3333333 = 0.3333333
    //       3.141593 = 3.141593
    
    Imports System.IO
    
    Module Example
       Public Sub Main()
          Dim sw As New StreamWriter(".\Singles.dat")
          Dim values() As Single = { 3.2/1.11, 1.0/3, CSng(Math.PI)  }
          For ctr As Integer = 0 To values.Length - 1
             sw.Write("{0:G9}{1}", values(ctr), 
                      If(ctr < values.Length - 1, "|", ""))
          Next      
          sw.Close()
          
          Dim restoredValues(values.Length - 1) As Single
          Dim sr As New StreamReader(".\Singles.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) = Single.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.882883 = 2.882883
    '       0.3333333 = 0.3333333
    '       3.141593 = 3.141593
    
  • Single 값은 값보다 Double 정밀도가 낮습니다. Single 겉보기에 동등한 Double 값으로 변환되는 값은 정밀도 차이로 인해 값과 같지 Double 않은 경우가 많습니다. 다음 예제에서는 동일한 나누기 작업의 결과가 값과 Single 값에 Double 할당됩니다. 값이 Single 로 캐스팅 Double된 후 두 값을 비교하면 같지 않음을 알 수 있습니다.

    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
    
    open System
    
    let value1 = 1. / 3.
    let sValue2 = 1f /3f
    
    let value2 = double sValue2
    printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
    // The example displays the following output:
    //        0.33333333333333331 = 0.3333333432674408: 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
    

    이 문제를 방지하려면 데이터 형식 대신 데이터 형식을 Single 사용 Double 하거나 두 값의 전체 자릿수가 같도록 메서드를 사용합니다Round.

같음 테스트

같음으로 간주하려면 두 Single 값이 동일한 값을 나타내야 합니다. 그러나 값 간의 정밀도 차이 또는 하나 또는 두 값 모두의 정밀도 손실로 인해 동일할 것으로 예상되는 부동 소수점 값은 가장 작은 숫자의 차이로 인해 같지 않은 것으로 판명되는 경우가 많습니다. 따라서 메서드를 호출하여 Equals 두 값이 같은지 여부를 확인하거나 메서드를 호출하여 CompareToSingle 값 간의 관계를 확인하면 예기치 않은 결과가 발생하는 경우가 많습니다. 첫 번째 값의 전체 자릿수는 7자리이고 두 번째 값은 9이기 때문에 두 개의 분명히 같은 Single 값이 같지 않은 것으로 판명되는 다음 예제에서 분명하게 알 수 있습니다.

using System;

public class Example
{
   public static void Main()
   {
      float value1 = .3333333f;
      float value2 = 1.0f/3;
      Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2));
   }
}
// The example displays the following output:
//        0.3333333 = 0.333333343: False
let value1 = 0.3333333f
let value2 = 1f / 3f
printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
// The example displays the following output:
//        0.3333333 = 0.333333343: False
Module Example
   Public Sub Main()
      Dim value1 As Single = .3333333
      Dim value2 As Single = 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.3333333 = 0.333333343: False

서로 다른 코드 경로를 따르고 다른 방식으로 조작되는 계산된 값은 종종 같지 않은 것으로 판명됩니다. 다음 예제에서는 한 Single 값이 제곱되고 제곱근이 계산되어 원래 값을 복원합니다. 두 번째는 Single 3.51을 곱하고 결과의 제곱근을 3.51로 나누어 원래 값을 복원하기 전에 제곱합니다. 두 값이 동일한 것처럼 보이지만 메서드를 호출하면 Equals(Single) 값이 같지 않음을 나타냅니다. "G9" 표준 형식 문자열을 사용하여 각 Single 값의 모든 중요한 숫자를 표시하는 결과 문자열을 반환하면 두 번째 값이 .0000000000001 첫 번째 값보다 작음이 표시됩니다.

using System;

public class Example
{
   public static void Main()
   {
      float value1 = 10.201438f;
      value1 = (float) Math.Sqrt((float) Math.Pow(value1, 2));
      float value2 = (float) Math.Pow((float) value1 * 3.51f, 2);
      value2 = ((float) Math.Sqrt(value2)) / 3.51f;
      Console.WriteLine("{0} = {1}: {2}\n", 
                        value1, value2, value1.Equals(value2)); 
      Console.WriteLine("{0:G9} = {1:G9}", value1, value2); 
   }
}
// The example displays the following output:
//       10.20144 = 10.20144: False
//       
//       10.201438 = 10.2014389
let value1 = 
    10.201438f ** 2f
    |> sqrt

let value2 =
   ((value1 * 3.51f) ** 2f |> sqrt) / 3.51f

printfn $"{value1} = {value2}: {value1.Equals value2}\n" 
printfn $"{value1:G9} = {value2:G9}"
// The example displays the following output:
//       10.20144 = 10.20144: False
//       
//       10.201438 = 10.2014389
Module Example
   Public Sub Main()
      Dim value1 As Single = 10.201438
      value1 = CSng(Math.Sqrt(CSng(Math.Pow(value1, 2))))
      Dim value2 As Single = CSng(Math.Pow(value1 * CSng(3.51), 2))
      value2 = CSng(Math.Sqrt(value2) / CSng(3.51))
      Console.WriteLine("{0} = {1}: {2}", 
                        value1, value2, value1.Equals(value2)) 
      Console.WriteLine()
      Console.WriteLine("{0:G9} = {1:G9}", value1, value2) 
   End Sub
End Module
' The example displays the following output:
'       10.20144 = 10.20144: False
'       
'       10.201438 = 10.2014389

정밀도 손실이 비교 결과에 영향을 줄 수 있는 경우 또는 CompareTo 메서드를 호출 Equals 하는 대신 다음 기술을 사용할 수 있습니다.

  • 메서드를 Math.Round 호출하여 두 값의 전체 자릿수가 같은지 확인합니다. 다음 예제에서는 두 개의 소수 값이 동일하도록 이 방법을 사용하도록 이전 예제를 수정합니다.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          float value1 = .3333333f;
          float value2 = 1.0f/3;
          int precision = 7;
          value1 = (float) Math.Round(value1, precision);
          value2 = (float) 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
    
    open System
    
    let value1 = 0.3333333f
    let value2 = 1f / 3f
    let precision = 7
    let value1r = Math.Round(float value1, precision) |> float32
    let value2r = Math.Round(float value2, precision) |> float32
    printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
    // The example displays the following output:
    //        0.3333333 = 0.3333333: True
    
    Module Example
       Public Sub Main()
          Dim value1 As Single = .3333333
          Dim value2 As Single = 1/3
          Dim precision As Integer = 7
          value1 = CSng(Math.Round(value1, precision))
          value2 = CSng(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
    

    정밀도 문제는 여전히 중간점 값의 반올림에 적용됩니다. 자세한 내용은 Math.Round(Double, Int32, MidpointRounding) 메서드를 참조하세요.

  • 같음 대신 대략적인 같음을 테스트합니다. 이 기술을 사용하려면 두 값이 다를 수 있지만 여전히 같을 수 있는 절대 금액을 정의하거나 더 작은 값이 더 큰 값과 다를 수 있는 상대 크기를 정의해야 합니다.

    경고

    Single.Epsilon 는 같음을 테스트할 때 두 Single 값 사이의 거리를 절대 측정값으로 사용하는 경우가 있습니다. 그러나 Single.Epsilon 값이 0인 에 추가하거나 빼기할 수 있는 Single 가능한 가장 작은 값을 측정합니다. 대부분의 양수 및 음 Single 수 값의 경우 값 Single.Epsilon 이 너무 작아 검색할 수 없습니다. 따라서 값이 0인 경우를 제외하고 같음 테스트에는 사용하지 않는 것이 좋습니다.

    다음 예제에서는 후자의 접근 방식을 사용하여 두 값 간의 상대적 차이를 테스트하는 메서드를 정의 IsApproximatelyEqual 합니다. 또한 메서드 및 메서드에 대한 IsApproximatelyEqual 호출의 결과와 대조됩니다 Equals(Single) .

    using System;
    
    public class Example
    {
       public static void Main()
       {
          float one1 = .1f * 10;
          float one2 = 0f;
          for (int ctr = 1; ctr <= 10; ctr++)
             one2 += .1f;
    
          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, .000001f));   
       }
    
       static bool IsApproximatelyEqual(float value1, float value2, float 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 = 1.00000012: False
    //       1 is approximately equal to 1.00000012: True
    
    open System
    
    let isApproximatelyEqual value1 value2 epsilon =
        // If they are equal anyway, just return True.
        if value1.Equals value2 then 
            true
        // Handle NaN, Infinity.
        elif Single.IsInfinity value1 || Single.IsNaN value1 then
            value1.Equals value2
        elif Single.IsInfinity value2 || Single.IsNaN value2 then
            value1.Equals value2
        else
            // Handle zero to avoid division by zero
            let divisor = max value1 value2
            let divisor = 
                if divisor.Equals 0 then
                    min value1 value2
                else divisor
            abs (value1 - value2) / divisor <= epsilon           
    
    
    let one1 = 0.1f * 10f
    let mutable one2 = 0f
    for _ = 1 to 10 do
       one2 <- one2 + 0.1f
    
    printfn $"{one1:R} = {one2:R}: {one1.Equals one2}"
    printfn $"{one1:R} is approximately equal to {one2:R}: {isApproximatelyEqual one1 one2 0.000001f}" 
    // The example displays the following output:
    //       1 = 1.00000012: False
    //       1 is approximately equal to 1.00000012: True
    
    Module Example
       Public Sub Main()
          Dim one1 As Single = .1 * 10
          Dim one2 As Single = 0
          For ctr As Integer = 1 To 10
             one2 += CSng(.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, .000001))   
       End Sub
    
       Function IsApproximatelyEqual(value1 As Single, value2 As Single, 
                                     epsilon As Single) As Boolean
          ' If they are equal anyway, just return True.
          If value1.Equals(value2) Then Return True
          
          ' Handle NaN, Infinity.
          If Single.IsInfinity(value1) Or Single.IsNaN(value1) Then
             Return value1.Equals(value2)
          Else If Single.IsInfinity(value2) Or Single.IsNaN(value2)
             Return value1.Equals(value2)
          End If
          
          ' Handle zero to avoid division by zero
          Dim divisor As Single = 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 = 1.00000012: False
    '       1 is approximately equal to 1.00000012: True
    

부동 소수점 값 및 예외

부동 소수점 값이 있는 작업은 정수 형식이 있는 작업과 달리 예외를 throw하지 않습니다. 이 연산은 0으로 나누기 또는 오버플로와 같은 잘못된 작업의 경우 예외를 throw합니다. 대신, 이러한 상황에서 부동 소수점 연산의 결과는 0, 양수 무한대, 음의 무한대 또는 숫자(NaN)가 아닙니다.

  • 부동 소수점 작업의 결과가 대상 형식에 비해 너무 작으면 결과는 0입니다. 이 문제는 다음 예제와 같이 두 개의 매우 작은 부동 소수점 숫자를 곱할 때 발생할 수 있습니다.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          float value1 = 1.163287e-36f;
          float value2 = 9.164234e-25f;
          float result = value1 * value2;
          Console.WriteLine("{0} * {1} = {2}", value1, value2, result);
          Console.WriteLine("{0} = 0: {1}", result, result.Equals(0.0f));
       }
    }
    // The example displays the following output:
    //       1.163287E-36 * 9.164234E-25 = 0
    //       0 = 0: True
    
    let value1 = 1.163287e-36f
    let value2 = 9.164234e-25f
    let result = value1 * value2
    printfn $"{value1} * {value2} = {result}"
    printfn $"{result} = 0: {result.Equals(0f)}"
    // The example displays the following output:
    //       1.163287E-36 * 9.164234E-25 = 0
    //       0 = 0: True
    
    Module Example
       Public Sub Main()
          Dim value1 As Single = 1.163287e-36
          Dim value2 As Single = 9.164234e-25
          Dim result As Single = value1 * value2
          Console.WriteLine("{0} * {1} = {2:R}", value1, value2, result)
          Console.WriteLine("{0} = 0: {1}", result, result.Equals(0))
       End Sub
    End Module
    ' The example displays the following output:
    '       1.163287E-36 * 9.164234E-25 = 0
    '       0 = 0: True
    
  • 부동 소수점 작업의 결과 크기가 대상 형식의 범위를 초과하는 경우 작업의 결과는 결과의 기호에 적합한 또는 NegativeInfinity입니다PositiveInfinity. 오버플로 Single.MaxValuePositiveInfinity되는 작업의 결과는 이고 오버플로 Single.MinValue 되는 작업의 결과는 다음 예제와 같이 입니다 NegativeInfinity.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          float value1 = 3.065e35f;
          float value2 = 6.9375e32f;
          float result = value1 * value2;
          Console.WriteLine("PositiveInfinity: {0}", 
                             Single.IsPositiveInfinity(result));
          Console.WriteLine("NegativeInfinity: {0}\n", 
                            Single.IsNegativeInfinity(result));
    
          value1 = -value1;
          result = value1 * value2;
          Console.WriteLine("PositiveInfinity: {0}", 
                             Single.IsPositiveInfinity(result));
          Console.WriteLine("NegativeInfinity: {0}", 
                            Single.IsNegativeInfinity(result));
       }
    }                                                                 
    
    // The example displays the following output:
    //       PositiveInfinity: True
    //       NegativeInfinity: False
    //       
    //       PositiveInfinity: False
    //       NegativeInfinity: True
    
    open System
    
    let value1 = 3.065e35f
    let value2 = 6.9375e32f
    let result = value1 * value2
    printfn $"PositiveInfinity: {Single.IsPositiveInfinity result}" 
    printfn $"NegativeInfinity: {Single.IsNegativeInfinity result}\n"
    
    let value3 = -value1
    let result2 = value3 * value2
    printfn $"PositiveInfinity: {Single.IsPositiveInfinity result}" 
    printfn $"NegativeInfinity: {Single.IsNegativeInfinity result}" 
    
    // The example displays the following output:
    //       PositiveInfinity: True
    //       NegativeInfinity: False
    //       
    //       PositiveInfinity: False
    //       NegativeInfinity: True
    
    Module Example
       Public Sub Main()
          Dim value1 As Single = 3.065e35
          Dim value2 As Single = 6.9375e32
          Dim result As Single = value1 * value2
          Console.WriteLine("PositiveInfinity: {0}", 
                             Single.IsPositiveInfinity(result))
          Console.WriteLine("NegativeInfinity: {0}", 
                            Single.IsNegativeInfinity(result))
          Console.WriteLine()                  
          value1 = -value1
          result = value1 * value2
          Console.WriteLine("PositiveInfinity: {0}", 
                             Single.IsPositiveInfinity(result))
          Console.WriteLine("NegativeInfinity: {0}", 
                            Single.IsNegativeInfinity(result))
       End Sub
    End Module
    ' The example displays the following output:
    '       PositiveInfinity: True
    '       NegativeInfinity: False
    '       
    '       PositiveInfinity: False
    '       NegativeInfinity: True
    

    PositiveInfinity 양수 배당을 가진 0으로 나누기에서 발생하며 NegativeInfinity , 음수 배당을 가진 0으로 나누기 결과입니다.

  • 부동 소수점 연산이 잘못된 경우 작업의 결과는 입니다 NaN. 예를 들어 NaN 다음 작업의 결과가 표시됩니다.

    • 배당금이 0인 0으로 나뉘어 니다. 다른 경우를 0으로 나누면 또는 NegativeInfinity가 발생 PositiveInfinity 합니다.

    • 잘못된 입력이 있는 모든 부동 소수점 작업입니다. 예를 들어 음수 값의 제곱근을 찾으려고 시도하면 가 반환됩니다 NaN.

    • 값이 인 인수가 있는 모든 연산입니다 Single.NaN.

형식 변환 및 단일 구조체

구조체는 Single 명시적 또는 암시적 변환 연산자를 정의하지 않고 대신 컴파일러에서 변환을 구현합니다.

다음 표에서는 다른 기본 숫자 형식의 값을 값으로 변환할 Single 수 있는 방법을 나열합니다. 또한 변환이 확대 또는 축소 중인지 여부와 결과 Single 에서 원래 값보다 정밀도가 낮을 수 있는지 여부를 나타냅니다.

B*에서 A*로의 변환이 확대/축소 정밀도 손실 가능성
Byte Widening 아니요
Decimal Widening

C#에는 캐스트 연산자가 필요합니다.
예. Decimal 는 29자리의 정밀도를 지원합니다. Single 는 9를 지원합니다.
Double 축소; 범위를 벗어난 값은 또는 Double.PositiveInfinityDouble.NegativeInfinity 변환됩니다. 예. Double 는 17진수의 정밀도를 지원합니다. Single 는 9를 지원합니다.
Int16 Widening 아니요
Int32 Widening 예. Int32 는 10진수의 정밀도를 지원합니다. Single 는 9를 지원합니다.
Int64 Widening 예. Int64 는 19진수의 정밀도를 지원합니다. Single 는 9를 지원합니다.
SByte Widening 아니요
UInt16 Widening 아니요
UInt32 Widening 예. UInt32 는 10진수의 정밀도를 지원합니다. Single 는 9를 지원합니다.
UInt64 Widening 예. Int64 는 10진수의 정밀도를 지원합니다. Single 는 9를 지원합니다.

다음 예제에서는 다른 기본 숫자 형식의 최소값 또는 최대값을 값으로 Single 변환합니다.

using System;

public class Example
{
   public static void Main()
   {
      dynamic[] values = { Byte.MinValue, Byte.MaxValue, Decimal.MinValue,
                           Decimal.MaxValue, Double.MinValue, Double.MaxValue,
                           Int16.MinValue, Int16.MaxValue, Int32.MinValue,
                           Int32.MaxValue, Int64.MinValue, Int64.MaxValue,
                           SByte.MinValue, SByte.MaxValue, UInt16.MinValue,
                           UInt16.MaxValue, UInt32.MinValue, UInt32.MaxValue,
                           UInt64.MinValue, UInt64.MaxValue };
      float sngValue;
      foreach (var value in values) {
         if (value.GetType() == typeof(Decimal) ||
             value.GetType() == typeof(Double))
            sngValue = (float) value;
         else
            sngValue = value;
         Console.WriteLine("{0} ({1}) --> {2:R} ({3})",
                           value, value.GetType().Name,
                           sngValue, sngValue.GetType().Name);
      }
   }
}
// The example displays the following output:
//       0 (Byte) --> 0 (Single)
//       255 (Byte) --> 255 (Single)
//       -79228162514264337593543950335 (Decimal) --> -7.92281625E+28 (Single)
//       79228162514264337593543950335 (Decimal) --> 7.92281625E+28 (Single)
//       -1.79769313486232E+308 (Double) --> -Infinity (Single)
//       1.79769313486232E+308 (Double) --> Infinity (Single)
//       -32768 (Int16) --> -32768 (Single)
//       32767 (Int16) --> 32767 (Single)
//       -2147483648 (Int32) --> -2.14748365E+09 (Single)
//       2147483647 (Int32) --> 2.14748365E+09 (Single)
//       -9223372036854775808 (Int64) --> -9.223372E+18 (Single)
//       9223372036854775807 (Int64) --> 9.223372E+18 (Single)
//       -128 (SByte) --> -128 (Single)
//       127 (SByte) --> 127 (Single)
//       0 (UInt16) --> 0 (Single)
//       65535 (UInt16) --> 65535 (Single)
//       0 (UInt32) --> 0 (Single)
//       4294967295 (UInt32) --> 4.2949673E+09 (Single)
//       0 (UInt64) --> 0 (Single)
//       18446744073709551615 (UInt64) --> 1.84467441E+19 (Single)
open System

let values: obj list = 
    [ Byte.MinValue; Byte.MaxValue; Decimal.MinValue
      Decimal.MaxValue; Double.MinValue; Double.MaxValue
      Int16.MinValue; Int16.MaxValue; Int32.MinValue
      Int32.MaxValue; Int64.MinValue; Int64.MaxValue
      SByte.MinValue; SByte.MaxValue; UInt16.MinValue
      UInt16.MaxValue; UInt32.MinValue; UInt32.MaxValue
      UInt64.MinValue; UInt64.MaxValue ]

for value in values do
    let sngValue = 
        match value with
        | :? byte as v -> float32 v
        | :? decimal as v -> float32 v
        | :? double as v -> float32 v
        | :? int16 as v -> float32 v
        | :? int as v -> float32 v
        | :? int64 as v -> float32 v
        | :? int8 as v -> float32 v
        | :? uint16 as v -> float32 v
        | :? uint as v -> float32 v
        | :? uint64 as v -> float32 v
        | _ -> raise (NotImplementedException "Unknown Type")
    printfn $"{value} ({value.GetType().Name}) --> {sngValue:R} ({sngValue.GetType().Name})"
// The example displays the following output:
//       0 (Byte) --> 0 (Single)
//       255 (Byte) --> 255 (Single)
//       -79228162514264337593543950335 (Decimal) --> -7.92281625E+28 (Single)
//       79228162514264337593543950335 (Decimal) --> 7.92281625E+28 (Single)
//       -1.79769313486232E+308 (Double) --> -Infinity (Single)
//       1.79769313486232E+308 (Double) --> Infinity (Single)
//       -32768 (Int16) --> -32768 (Single)
//       32767 (Int16) --> 32767 (Single)
//       -2147483648 (Int32) --> -2.14748365E+09 (Single)
//       2147483647 (Int32) --> 2.14748365E+09 (Single)
//       -9223372036854775808 (Int64) --> -9.223372E+18 (Single)
//       9223372036854775807 (Int64) --> 9.223372E+18 (Single)
//       -128 (SByte) --> -128 (Single)
//       127 (SByte) --> 127 (Single)
//       0 (UInt16) --> 0 (Single)
//       65535 (UInt16) --> 65535 (Single)
//       0 (UInt32) --> 0 (Single)
//       4294967295 (UInt32) --> 4.2949673E+09 (Single)
//       0 (UInt64) --> 0 (Single)
//       18446744073709551615 (UInt64) --> 1.84467441E+19 (Single)
Module Example
   Public Sub Main()
      Dim values() As Object = { Byte.MinValue, Byte.MaxValue, Decimal.MinValue,
                                 Decimal.MaxValue, Double.MinValue, Double.MaxValue,
                                 Int16.MinValue, Int16.MaxValue, Int32.MinValue,
                                 Int32.MaxValue, Int64.MinValue, Int64.MaxValue,
                                 SByte.MinValue, SByte.MaxValue, UInt16.MinValue,
                                 UInt16.MaxValue, UInt32.MinValue, UInt32.MaxValue,
                                 UInt64.MinValue, UInt64.MaxValue }
      Dim sngValue As Single
      For Each value In values
         If value.GetType() = GetType(Double) Then
            sngValue = CSng(value)
         Else
            sngValue = value
         End If
         Console.WriteLine("{0} ({1}) --> {2:R} ({3})",
                           value, value.GetType().Name,
                           sngValue, sngValue.GetType().Name)
      Next
   End Sub
End Module
' The example displays the following output:
'       0 (Byte) --> 0 (Single)
'       255 (Byte) --> 255 (Single)
'       -79228162514264337593543950335 (Decimal) --> -7.92281625E+28 (Single)
'       79228162514264337593543950335 (Decimal) --> 7.92281625E+28 (Single)
'       -1.79769313486232E+308 (Double) --> -Infinity (Single)
'       1.79769313486232E+308 (Double) --> Infinity (Single)
'       -32768 (Int16) --> -32768 (Single)
'       32767 (Int16) --> 32767 (Single)
'       -2147483648 (Int32) --> -2.14748365E+09 (Single)
'       2147483647 (Int32) --> 2.14748365E+09 (Single)
'       -9223372036854775808 (Int64) --> -9.223372E+18 (Single)
'       9223372036854775807 (Int64) --> 9.223372E+18 (Single)
'       -128 (SByte) --> -128 (Single)
'       127 (SByte) --> 127 (Single)
'       0 (UInt16) --> 0 (Single)
'       65535 (UInt16) --> 65535 (Single)
'       0 (UInt32) --> 0 (Single)
'       4294967295 (UInt32) --> 4.2949673E+09 (Single)
'       0 (UInt64) --> 0 (Single)
'       18446744073709551615 (UInt64) --> 1.84467441E+19 (Single)

또한 , 및 Double.PositiveInfinity값은 각각 , Single.PositiveInfinitySingle.NegativeInfinity로 변환Single.NaN됩니다.DoubleDouble.NaNDouble.NegativeInfinity

일부 숫자 형식의 값을 값으로 Single 변환하면 정밀도 손실이 포함될 수 있습니다. 예제에서 알 수 있듯이 , , Double, Int32UInt32Int64, 및 UInt64 값을 값으로 변환할 Decimal때 정밀도 손실이 발생할 수 Single 있습니다.

값을 로 Single 변환하는 Double 것은 확대 변환입니다. 형식에 값에 대한 정확한 표현이 없는 경우 Double 변환으로 인해 정밀도 손실이 Single 발생할 수 있습니다.

값을 이외의 기본 숫자 데이터 형식 Double 의 값으로 변환 Single 하는 것은 축소 변환이며 캐스트 연산자(C#) 또는 변환 메서드(Visual Basic의 경우)가 필요합니다. 대상 형식의 및 속성에 의해 정의된 대상 데이터 형식의 MinValue 범위를 벗어난 값은 다음 표와 MaxValue 같이 동작합니다.

대상 형식 결과
모든 정수 형식 OverflowException 선택한 컨텍스트에서 변환이 발생하는 경우 예외입니다.

확인되지 않은 컨텍스트(C#의 기본값)에서 변환이 발생하면 변환 작업이 성공하지만 값이 오버플로됩니다.
Decimal 예외,OverflowException

또한 Single.NaN, Single.PositiveInfinitySingle.NegativeInfinity 는 확인된 컨텍스트에서 정수로 변환하기 위해 를 throw OverflowException 하지만 이러한 값은 선택되지 않은 컨텍스트에서 정수로 변환될 때 오버플로됩니다. 로 변환하는 Decimal경우 항상 을 throw합니다 OverflowException. 로 변환하는 Double경우 각각 , Double.PositiveInfinityDouble.NegativeInfinity로 변환Double.NaN됩니다.

전체 자릿수가 손실되면 값을 다른 숫자 형식으로 Single 변환할 수 있습니다. 비정수 Single 값을 변환하는 경우 예제의 출력에서 알 수 있듯이 값이 반올림되거나(Visual Basic에서와 같이) 잘리거나(C# 및 F#에서와 같이) 소수점 구성 요소가 손실 Single 됩니다. 값으로 변환하는 Decimal 경우 값에 Single 대상 데이터 형식의 정확한 표현이 없을 수 있습니다.

다음 예제에서는 여러 Single 값을 다른 여러 숫자 형식으로 변환합니다. 변환은 Visual Basic(기본값), C#(확인된 키워드(keyword)) 및 F#(문으로 인해)의 open Checked 확인된 컨텍스트에서 발생합니다. 예제의 출력은 선택된 선택되지 않은 컨텍스트 모두에서 변환 결과를 보여 줍니다. 컴파일러 스위치를 /removeintchecks+ 사용하여 컴파일하고, C#에서 문을 주석으로 처리하고, 문을 주석으로 처리하여 checked F#에서 Visual Basic에서 확인되지 않은 컨텍스트에서 변환을 open Checked 수행할 수 있습니다.

using System;

public class Example
{
   public static void Main()
   {
      float[] values = { Single.MinValue, -67890.1234f, -12345.6789f,
                         12345.6789f, 67890.1234f, Single.MaxValue,
                         Single.NaN, Single.PositiveInfinity,
                         Single.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);
            }

            Double dblValue = value;
            Console.WriteLine("{0} ({1}) --> {2} ({3})",
                              value, value.GetType().Name,
                              dblValue, dblValue.GetType().Name);
            Console.WriteLine();
         }
      }
   }
}
// The example displays the following output for conversions performed
// in a checked context:
//       Unable to convert -3.402823E+38 to Int64.
//       Unable to convert -3.402823E+38 to UInt64.
//       Unable to convert -3.402823E+38 to Decimal.
//       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
//
//       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
//       Unable to convert -67890.13 to UInt64.
//       -67890.13 (Single) --> -67890.12 (Decimal)
//       -67890.13 (Single) --> -67890.125 (Double)
//
//       -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
//       Unable to convert -12345.68 to UInt64.
//       -12345.68 (Single) --> -12345.68 (Decimal)
//       -12345.68 (Single) --> -12345.6787109375 (Double)
//
//       12345.68 (Single) --> 12345 (0x0000000000003039) (Int64)
//       12345.68 (Single) --> 12345 (0x0000000000003039) (UInt64)
//       12345.68 (Single) --> 12345.68 (Decimal)
//       12345.68 (Single) --> 12345.6787109375 (Double)
//
//       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
//       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
//       67890.13 (Single) --> 67890.12 (Decimal)
//       67890.13 (Single) --> 67890.125 (Double)
//
//       Unable to convert 3.402823E+38 to Int64.
//       Unable to convert 3.402823E+38 to UInt64.
//       Unable to convert 3.402823E+38 to Decimal.
//       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
//
//       Unable to convert NaN to Int64.
//       Unable to convert NaN to UInt64.
//       Unable to convert NaN to Decimal.
//       NaN (Single) --> NaN (Double)
//
//       Unable to convert Infinity to Int64.
//       Unable to convert Infinity to UInt64.
//       Unable to convert Infinity to Decimal.
//       Infinity (Single) --> Infinity (Double)
//
//       Unable to convert -Infinity to Int64.
//       Unable to convert -Infinity to UInt64.
//       Unable to convert -Infinity to Decimal.
//       -Infinity (Single) --> -Infinity (Double)
// The example displays the following output for conversions performed
// in an unchecked context:
//       -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
//       Unable to convert -3.402823E+38 to Decimal.
//       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
//
//       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
//       -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
//       -67890.13 (Single) --> -67890.12 (Decimal)
//       -67890.13 (Single) --> -67890.125 (Double)
//
//       -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
//       -12345.68 (Single) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (UInt64)
//       -12345.68 (Single) --> -12345.68 (Decimal)
//       -12345.68 (Single) --> -12345.6787109375 (Double)
//
//       12345.68 (Single) --> 12345 (0x0000000000003039) (Int64)
//       12345.68 (Single) --> 12345 (0x0000000000003039) (UInt64)
//       12345.68 (Single) --> 12345.68 (Decimal)
//       12345.68 (Single) --> 12345.6787109375 (Double)
//
//       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
//       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
//       67890.13 (Single) --> 67890.12 (Decimal)
//       67890.13 (Single) --> 67890.125 (Double)
//
//       3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert 3.402823E+38 to Decimal.
//       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
//
//       NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       NaN (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert NaN to Decimal.
//       NaN (Single) --> NaN (Double)
//
//       Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert Infinity to Decimal.
//       Infinity (Single) --> Infinity (Double)
//
//       -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
//       Unable to convert -Infinity to Decimal.
//       -Infinity (Single) --> -Infinity (Double)
open System
open Checked

let values = 
    [ Single.MinValue; -67890.1234f; -12345.6789f
      12345.6789f; 67890.1234f; Single.MaxValue
      Single.NaN; Single.PositiveInfinity
      Single.NegativeInfinity ]

for value in values do
    try
        let lValue = int64 value
        printfn $"{value} ({value.GetType().Name}) --> {lValue} (0x{lValue:X16}) ({lValue.GetType().Name})"
    with :? OverflowException ->
        printfn $"Unable to convert {value} to Int64."
    try
        let ulValue = uint64 value
        printfn $"{value} ({value.GetType().Name}) --> {ulValue} (0x{ulValue:X16}) ({ulValue.GetType().Name})"
    with :? OverflowException ->
        printfn $"Unable to convert {value} to UInt64."
    try
        let dValue = decimal value
        printfn $"{value} ({value.GetType().Name}) --> {dValue} ({dValue.GetType().Name})"
    with :? OverflowException ->
        printfn $"Unable to convert {value} to Decimal."

    let dblValue = double value
    printfn $"{value} ({value.GetType().Name}) --> {dblValue} ({dblValue.GetType().Name})\n"
// The example displays the following output for conversions performed
// in a checked context:
//       Unable to convert -3.402823E+38 to Int64.
//       Unable to convert -3.402823E+38 to UInt64.
//       Unable to convert -3.402823E+38 to Decimal.
//       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
//
//       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
//       Unable to convert -67890.13 to UInt64.
//       -67890.13 (Single) --> -67890.12 (Decimal)
//       -67890.13 (Single) --> -67890.125 (Double)
//
//       -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
//       Unable to convert -12345.68 to UInt64.
//       -12345.68 (Single) --> -12345.68 (Decimal)
//       -12345.68 (Single) --> -12345.6787109375 (Double)
//
//       12345.68 (Single) --> 12345 (0x0000000000003039) (Int64)
//       12345.68 (Single) --> 12345 (0x0000000000003039) (UInt64)
//       12345.68 (Single) --> 12345.68 (Decimal)
//       12345.68 (Single) --> 12345.6787109375 (Double)
//
//       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
//       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
//       67890.13 (Single) --> 67890.12 (Decimal)
//       67890.13 (Single) --> 67890.125 (Double)
//
//       Unable to convert 3.402823E+38 to Int64.
//       Unable to convert 3.402823E+38 to UInt64.
//       Unable to convert 3.402823E+38 to Decimal.
//       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
//
//       Unable to convert NaN to Int64.
//       Unable to convert NaN to UInt64.
//       Unable to convert NaN to Decimal.
//       NaN (Single) --> NaN (Double)
//
//       Unable to convert Infinity to Int64.
//       Unable to convert Infinity to UInt64.
//       Unable to convert Infinity to Decimal.
//       Infinity (Single) --> Infinity (Double)
//
//       Unable to convert -Infinity to Int64.
//       Unable to convert -Infinity to UInt64.
//       Unable to convert -Infinity to Decimal.
//       -Infinity (Single) --> -Infinity (Double)
// The example displays the following output for conversions performed
// in an unchecked context:
//       -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
//       Unable to convert -3.402823E+38 to Decimal.
//       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
//
//       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
//       -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
//       -67890.13 (Single) --> -67890.12 (Decimal)
//       -67890.13 (Single) --> -67890.125 (Double)
//
//       -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
//       -12345.68 (Single) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (UInt64)
//       -12345.68 (Single) --> -12345.68 (Decimal)
//       -12345.68 (Single) --> -12345.6787109375 (Double)
//
//       12345.68 (Single) --> 12345 (0x0000000000003039) (Int64)
//       12345.68 (Single) --> 12345 (0x0000000000003039) (UInt64)
//       12345.68 (Single) --> 12345.68 (Decimal)
//       12345.68 (Single) --> 12345.6787109375 (Double)
//
//       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
//       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
//       67890.13 (Single) --> 67890.12 (Decimal)
//       67890.13 (Single) --> 67890.125 (Double)
//
//       3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert 3.402823E+38 to Decimal.
//       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
//
//       NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       NaN (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert NaN to Decimal.
//       NaN (Single) --> NaN (Double)
//
//       Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
//       Unable to convert Infinity to Decimal.
//       Infinity (Single) --> Infinity (Double)
//
//       -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
//       -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
//       Unable to convert -Infinity to Decimal.
//       -Infinity (Single) --> -Infinity (Double)
Module Example
   Public Sub Main()
      Dim values() As Single = { Single.MinValue, -67890.1234, -12345.6789,
                                 12345.6789, 67890.1234, Single.MaxValue,
                                 Single.NaN, Single.PositiveInfinity,
                                 Single.NegativeInfinity }
      For Each value In values
         Try
             Dim lValue As Long = 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

         Dim dblValue As Double = value
         Console.WriteLine("{0} ({1}) --> {2} ({3})",
                           value, value.GetType().Name,
                           dblValue, dblValue.GetType().Name)
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output for conversions performed
' in a checked context:
'       Unable to convert -3.402823E+38 to Int64.
'       Unable to convert -3.402823E+38 to UInt64.
'       Unable to convert -3.402823E+38 to Decimal.
'       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
'
'       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
'       Unable to convert -67890.13 to UInt64.
'       -67890.13 (Single) --> -67890.12 (Decimal)
'       -67890.13 (Single) --> -67890.125 (Double)
'
'       -12345.68 (Single) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
'       Unable to convert -12345.68 to UInt64.
'       -12345.68 (Single) --> -12345.68 (Decimal)
'       -12345.68 (Single) --> -12345.6787109375 (Double)
'
'       12345.68 (Single) --> 12346 (0x000000000000303A) (Int64)
'       12345.68 (Single) --> 12346 (0x000000000000303A) (UInt64)
'       12345.68 (Single) --> 12345.68 (Decimal)
'       12345.68 (Single) --> 12345.6787109375 (Double)
'
'       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
'       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
'       67890.13 (Single) --> 67890.12 (Decimal)
'       67890.13 (Single) --> 67890.125 (Double)
'
'       Unable to convert 3.402823E+38 to Int64.
'       Unable to convert 3.402823E+38 to UInt64.
'       Unable to convert 3.402823E+38 to Decimal.
'       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
'
'       Unable to convert NaN to Int64.
'       Unable to convert NaN to UInt64.
'       Unable to convert NaN to Decimal.
'       NaN (Single) --> NaN (Double)
'
'       Unable to convert Infinity to Int64.
'       Unable to convert Infinity to UInt64.
'       Unable to convert Infinity to Decimal.
'       Infinity (Single) --> Infinity (Double)
'
'       Unable to convert -Infinity to Int64.
'       Unable to convert -Infinity to UInt64.
'       Unable to convert -Infinity to Decimal.
'       -Infinity (Single) --> -Infinity (Double)
' The example displays the following output for conversions performed
' in an unchecked context:
'       -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
'       Unable to convert -3.402823E+38 to Decimal.
'       -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
'
'       -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
'       -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
'       -67890.13 (Single) --> -67890.12 (Decimal)
'       -67890.13 (Single) --> -67890.125 (Double)
'
'       -12345.68 (Single) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
'       -12345.68 (Single) --> 18446744073709539270 (0xFFFFFFFFFFFFCFC6) (UInt64)
'       -12345.68 (Single) --> -12345.68 (Decimal)
'       -12345.68 (Single) --> -12345.6787109375 (Double)
'
'       12345.68 (Single) --> 12346 (0x000000000000303A) (Int64)
'       12345.68 (Single) --> 12346 (0x000000000000303A) (UInt64)
'       12345.68 (Single) --> 12345.68 (Decimal)
'       12345.68 (Single) --> 12345.6787109375 (Double)
'
'       67890.13 (Single) --> 67890 (0x0000000000010932) (Int64)
'       67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64)
'       67890.13 (Single) --> 67890.12 (Decimal)
'       67890.13 (Single) --> 67890.125 (Double)
'
'       3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert 3.402823E+38 to Decimal.
'       3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
'
'       NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       NaN (Single) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert NaN to Decimal.
'       NaN (Single) --> NaN (Double)
'
'       Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert Infinity to Decimal.
'       Infinity (Single) --> Infinity (Double)
'
'       -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
'       Unable to convert -Infinity to Decimal.
'       -Infinity (Single) --> -Infinity (Double)

숫자 형식의 변환에 대한 자세한 내용은 .NET Framework 형식 변환형식 변환 테이블을 참조하세요.

부동 소수점 기능

구조체 및 관련 형식은 Single 다음과 같은 작업 범주를 수행하는 메서드를 제공합니다.

  • 값 비교. 메서드를 Equals 호출하여 두 값이 같은지 또는 메서드를 CompareTo 호출하여 두 Single 값 간의 관계를 확인할 수 있습니다.

    구조체는 Single 전체 비교 연산자 집합도 지원합니다. 예를 들어 같음 또는 같지 않음을 테스트하거나 한 값이 다른 값보다 크거나 같은지 확인할 수 있습니다. 피연산자 중 하나가 인 Double경우 비교를 Single 수행하기 전에 값이 로 Double 변환됩니다. 피연산자 중 하나가 정수 형식인 경우 비교를 Single 수행하기 전에 로 변환됩니다. 이러한 변환은 확대되지만 정밀도 손실이 발생할 수 있습니다.

    경고

    정밀도의 차이로 인해 같을 것으로 예상되는 두 Single 값이 같지 않은 것으로 판명되어 비교 결과에 영향을 줄 수 있습니다. 두 값을 비교하는 방법에 대한 자세한 내용은 같음 테스트 섹션을 참조하세요.Single

    , , IsInfinityIsPositiveInfinityIsNegativeInfinity 메서드를 IsNaN호출하여 이러한 특수 값을 테스트할 수도 있습니다.

  • 수학 연산. 더하기, 빼기, 곱하기 및 나누기와 같은 일반적인 산술 연산은 메서드가 아닌 언어 컴파일러 및 CIL(공용 중간 언어) 명령에 의해 Single 구현됩니다. 수학 연산 Double의 다른 피연산자는 인 Single 경우 연산을 수행하기 전에 가 로 Double 변환되고 연산의 결과도 값입니다 Double . 다른 피연산자는 정수 계열 형식인 경우 연산을 Single 수행하기 전에 으로 변환되며 작업의 결과도 값입니다 Single .

    클래스에서 (SharedVisual Basic의 경우) 메서드를 호출 static 하여 다른 수학 연산을 System.Math 수행할 수 있습니다. 여기에는 산술(예: , Math.Sign및 ), 기하 도형(예: Math.AbsMath.CosMath.Sin) 및 Math.Sqrt미적분(예: Math.Log)에 일반적으로 사용되는 추가 메서드가 포함됩니다. 모든 경우에 값은 Single 로 변환 Double됩니다.

    값의 개별 비트를 조작할 수도 있습니다 Single . 메서드는 BitConverter.GetBytes(Single) 비트 패턴을 바이트 배열로 반환합니다. 해당 바이트 배열을 메서드에 BitConverter.ToInt32 전달하면 값의 비트 패턴을 32비트 정수로 유지할 Single 수도 있습니다.

  • 반올림. 반올림은 부동 소수점 표현과 정밀도 문제로 인해 발생하는 값 간의 차이를 줄이는 기술로 자주 사용됩니다. 메서드를 Single 호출하여 값을 반올림할 Math.Round 수 있습니다. 그러나 메서드가 Single 호출되기 전에 값이 로 Double 변환되고 변환에 정밀도 손실이 포함될 수 있습니다.

  • 서식 지정. 메서드를 Single 호출 ToString 하거나 복합 서식 지정 기능을 사용하여 값을 문자열 표현으로 변환할 수 있습니다. 서식 문자열이 부동 소수점 값의 문자열 표현을 제어하는 방법에 대한 자세한 내용은 표준 숫자 형식 문자열사용자 지정 숫자 형식 문자열 topics 참조하세요.

  • 문자열 구문 분석. 또는 TryParse 메서드를 호출 Parse 하여 부동 소수점 값의 문자열 표현을 값으로 Single 변환할 수 있습니다. 구문 분석 작업이 실패하면 메서드는 Parse 예외를 throw하는 반면 메서드는 TryParse 를 반환합니다 false.

  • 형식 변환. 구조체는 Single 두 표준 .NET Framework 데이터 형식 간의 변환을 지원하는 인터페이스에 대한 IConvertible 명시적 인터페이스 구현을 제공합니다. 언어 컴파일러에서는 값으로의 변환을 제외한 다른 모든 표준 숫자 형식에 대한 값의 DoubleSingle 암시적 변환도 지원합니다. 이외의 표준 숫자 형식 DoubleSingle 의 값을 로 변환하는 것은 확대 변환이며 캐스팅 연산자 또는 변환 메서드를 사용할 필요가 없습니다.

    그러나 32비트 및 64비트 정수 값의 변환에는 정밀도 손실이 포함될 수 있습니다. 다음 표에서는 32비트, 64비트 및 형식의 전체 자릿수 차이를 나열합니다 Double .

    형식 최대 정밀도(10진수) 내부 전체 자릿수(10진수)
    Double 15 17
    Int32UInt32 10 10
    Int64UInt64 19 19
    Single 7 9

    정밀도 문제는 값으로 변환 Double 되는 값에 Single 가장 자주 영향을 줍니다. 다음 예제에서는 값 중 하나가 로 변환 Double되는 단정밀도 부동 소수점 값이므로 동일한 나누기 연산에서 생성된 두 값이 같지 않습니다.

    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
    
    let value1 = 1. / 3.
    let sValue2 = 1f / 3f
    let value2 = double sValue2
    printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
    // The example displays the following output:
    //        0.33333333333333331 = 0.3333333432674408: 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
    

필드

E

상수(e)로 지정된 자연 로그 베이스를 나타냅니다.

Epsilon

0보다 큰 양의 최소 Single 값을 나타냅니다. 이 필드는 상수입니다.

MaxValue

Single의 가능한 최대값을 나타냅니다. 이 필드는 상수입니다.

MinValue

Single의 가능한 최소값을 나타냅니다. 이 필드는 상수입니다.

NaN

Not-a-Number(NaN)를 나타냅니다. 이 필드는 상수입니다.

NegativeInfinity

음의 무한대를 나타냅니다. 이 필드는 상수입니다.

NegativeZero

숫자 음수 0(-0)을 나타냅니다.

Pi

상수(π)로 지정된 원주율을 나타냅니다.

PositiveInfinity

양의 무한대를 나타냅니다. 이 필드는 상수입니다.

Tau

상수 τ로 지정된 한 턴의 라디안 수를 나타냅니다.

메서드

Abs(Single)

값의 절대값을 계산합니다.

Acos(Single)

값의 아크 코사인을 계산합니다.

Acosh(Single)

값의 쌍곡선 아크 코사인을 계산합니다.

AcosPi(Single)

값의 아크 코사인을 계산하고 결과를 로 pi나눕니다.

Asin(Single)

값의 아크 사인을 계산합니다.

Asinh(Single)

값의 하이퍼볼릭 아크 사인을 계산합니다.

AsinPi(Single)

값의 아크 사인을 계산하고 결과를 로 pi나눕니다.

Atan(Single)

값의 아크 탄젠트를 계산합니다.

Atan2(Single, Single)

두 값의 몫의 아크 탄젠트를 계산합니다.

Atan2Pi(Single, Single)

두 값의 몫에 대한 호 탄젠트를 계산하고 결과를 로 pi나눕니다.

Atanh(Single)

값의 하이퍼볼릭 아크 탄젠트를 계산합니다.

AtanPi(Single)

값의 아크 탄젠트를 계산하고 결과를 pi로 나눕니다.

BitDecrement(Single)

값을 지정된 값보다 작게 비교하는 가장 작은 값으로 줄입니다.

BitIncrement(Single)

지정된 값보다 큰 값을 비교하는 가장 작은 값으로 값을 증분합니다.

Cbrt(Single)

값의 큐브 루트를 계산합니다.

Ceiling(Single)

값의 최대값을 계산합니다.

Clamp(Single, Single, Single)

값을 포괄 최소값 및 최대값으로 고정합니다.

CompareTo(Object)

이 인스턴스를 지정된 개체와 비교하고 이 인스턴스의 값이 지정된 개체의 값보다 작은지, 같은지 또는 큰지를 나타내는 정수를 반환합니다.

CompareTo(Single)

이 인스턴스를 지정된 단정밀도 부동 소수점 숫자와 비교하고 이 인스턴스의 값이 지정된 단정밀도 부동 소수점 숫자 값보다 작은지, 같은지 또는 큰지를 나타내는 정수를 반환합니다.

CopySign(Single, Single)

값의 기호를 다른 값의 기호에 복사합니다.

Cos(Single)

값의 코사인을 계산합니다.

Cosh(Single)

값의 쌍곡선 코사인을 계산합니다.

CosPi(Single)

에 의해 pi배수된 값의 코사인을 계산합니다.

CreateChecked<TOther>(TOther)

현재 형식의 표현 가능한 범위를 벗어나는 값에 대해 오버플로 예외를 throw하여 값에서 현재 형식의 instance 만듭니다.

CreateSaturating<TOther>(TOther)

값에서 현재 형식의 instance 만들어 현재 형식의 표현 가능한 범위를 벗어나는 값을 채도합니다.

CreateTruncating<TOther>(TOther)

값에서 현재 형식의 instance 만들어 현재 형식의 표현 가능한 범위를 벗어나는 값을 잘려냅니다.

DegreesToRadians(Single)

지정된 값을 도에서 라디안으로 변환합니다.

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

Equals(Single)

이 인스턴스의 값과 지정된 Single 개체의 값이 같은지를 나타내는 값을 반환합니다.

Exp(Single)

E 지정된 전원으로 발생하는 컴퓨팅입니다.

Exp10(Single)

10 지정된 전원으로 발생하는 컴퓨팅입니다.

Exp10M1(Single)

10 지정된 전원으로 발생된 컴퓨팅은 1을 뺍니다.

Exp2(Single)

2 지정된 전원으로 발생하는 컴퓨팅입니다.

Exp2M1(Single)

2 지정된 전원으로 발생된 컴퓨팅은 1을 뺍니다.

ExpM1(Single)

E 지정된 전원으로 발생된 컴퓨팅은 1을 뺍니다.

Floor(Single)

값의 바닥을 계산합니다.

FusedMultiplyAdd(Single, Single, Single)

융합된 곱하기 3개의 값을 계산합니다.

GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

GetTypeCode()

TypeCode 값 형식에 대한 Single를 반환합니다.

Hypot(Single, Single)

오른쪽 각진 삼각형에서 짧은 면의 길이를 나타내는 두 개의 값이 지정된 가설을 계산합니다.

Ieee754Remainder(Single, Single)

IEEE 754에서 지정한 대로 두 값의 나머지 부분을 계산합니다.

ILogB(Single)

값의 정수 로그를 계산합니다.

IsEvenInteger(Single)

값이 짝수 정수인지 여부를 결정합니다.

IsFinite(Single)

지정된 값이 유한(0, 비정상 또는 정상)한지 확인합니다.

IsInfinity(Single)

지정된 숫자가 음의 무한대로 계산되는지 양의 무한대로 계산되는지를 나타내는 값을 반환합니다.

IsInteger(Single)

값이 정수 값을 나타내는지 여부를 결정합니다.

IsNaN(Single)

지정된 값이 숫자가 아닌지(NaN) 여부를 나타내는 값을 반환합니다.

IsNegative(Single)

지정된 값이 음수인지 확인합니다.

IsNegativeInfinity(Single)

지정된 숫자가 음의 무한대로 계산되는지를 나타내는 값을 반환합니다.

IsNormal(Single)

지정된 값이 정상인지 확인합니다.

IsOddInteger(Single)

값이 홀수 정수인지 여부를 결정합니다.

IsPositive(Single)

값이 양수인지 확인합니다.

IsPositiveInfinity(Single)

지정된 숫자가 양의 무한대로 계산되는지를 나타내는 값을 반환합니다.

IsPow2(Single)

값이 2의 힘인지 확인합니다.

IsRealNumber(Single)

값이 실제 숫자를 나타내는지 여부를 결정합니다.

IsSubnormal(Single)

지정된 값이 비정상인지 확인합니다.

Lerp(Single, Single, Single)

지정된 가중치에 따라 두 값 간의 선형 보간을 수행합니다.

Log(Single)

자연(base-E 값의 로그)을 계산합니다.

Log(Single, Single)

지정된 베이스에 있는 값의 로그를 계산합니다.

Log10(Single)

값의 base-10 로그를 계산합니다.

Log10P1(Single)

값의 base-10 로그와 1을 계산합니다.

Log2(Single)

값의 log2를 계산합니다.

Log2P1(Single)

값의 base-2 로그와 1을 계산합니다.

LogP1(Single)

값에 1을 더한 자연(base-E) 로그를 계산합니다.

Max(Single, Single)

두 값을 더 큰 컴퓨팅과 비교합니다.

MaxMagnitude(Single, Single)

두 값을 더 큰 컴퓨팅과 비교합니다.

MaxMagnitudeNumber(Single, Single)

크기가 더 큰 컴퓨팅과 두 값을 비교하고 입력이 인 경우 다른 값을 반환합니다 NaN.

MaxNumber(Single, Single)

두 값을 더 큰 컴퓨팅과 비교하고 입력이 인 경우 다른 값을 반환합니다 NaN.

Min(Single, Single)

두 값을 더 작은 컴퓨팅과 비교합니다.

MinMagnitude(Single, Single)

두 값을 더 작은 컴퓨팅과 비교합니다.

MinMagnitudeNumber(Single, Single)

크기가 작은 컴퓨팅과 두 값을 비교하고 입력이 인 경우 다른 값을 반환합니다 NaN.

MinNumber(Single, Single)

두 값을 더 작은 컴퓨팅과 비교하고 입력이 인 경우 다른 값을 반환합니다 NaN.

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8자의 범위를 값으로 구문 분석합니다.

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8자의 범위를 값으로 구문 분석합니다.

Parse(ReadOnlySpan<Char>, IFormatProvider)

문자 범위를 값으로 구문 분석합니다.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을포함하는 문자 범위를 해당하는 단정밀도 부동 소수점 숫자로 변환합니다.

Parse(String)

숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다.

Parse(String, IFormatProvider)

지정된 문화권별 형식의 숫자에 대한 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다.

Parse(String, NumberStyles)

지정된 스타일로 된 숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다.

Parse(String, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다.

Pow(Single, Single)

지정된 전력으로 발생한 값을 계산합니다.

RadiansToDegrees(Single)

지정된 값을 라디안에서 도로 변환합니다.

ReciprocalEstimate(Single)

값의 상호 추정값을 계산합니다.

ReciprocalSqrtEstimate(Single)

값의 상호 제곱근 추정값을 계산합니다.

RootN(Single, Int32)

값의 n번째 루트를 계산합니다.

Round(Single)

기본 반올림 모드(ToEven)를 사용하여 값을 가장 가까운 정수로 반올림합니다.

Round(Single, Int32)

기본 반올림 모드(ToEven)를 사용하여 값을 지정된 수의 소수 자릿수로 반올림합니다.

Round(Single, Int32, MidpointRounding)

기본 반올림 모드(ToEven)를 사용하여 값을 지정된 수의 소수 자릿수로 반올림합니다.

Round(Single, MidpointRounding)

지정된 반올림 모드를 사용하여 값을 가장 가까운 정수로 반올림합니다.

ScaleB(Single, Int32)

값의 곱과 지정된 전력으로 발생한 기본 반지름을 계산합니다.

Sign(Single)

값의 기호를 계산합니다.

Sin(Single)

값의 사인을 계산합니다.

SinCos(Single)

값의 사인 및 코사인을 계산합니다.

SinCosPi(Single)

값의 사인 및 코사인을 계산합니다.

Sinh(Single)

값의 쌍곡선 사인을 계산합니다.

SinPi(Single)

을 곱한 값의 사인을 pi계산합니다.

Sqrt(Single)

값의 제곱근을 계산합니다.

Tan(Single)

값의 탄젠트를 계산합니다.

Tanh(Single)

값의 쌍곡선 탄젠트를 계산합니다.

TanPi(Single)

에 의해 pi배수된 값의 탄젠트를 계산합니다.

ToString()

이 인스턴스의 숫자 값을 해당하는 문자열 표현으로 변환합니다.

ToString(IFormatProvider)

지정된 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

ToString(String)

지정된 형식을 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

ToString(String, IFormatProvider)

지정된 형식 및 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

Truncate(Single)

값을 자립니다.

TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

현재 instance 값의 형식을 제공된 바이트 범위로 UTF-8로 지정하려고 시도합니다.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

현재의 부동 숫자 인스턴스 값을 제공된 문자 범위의 형식으로 지정하도록 시도합니다.

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Single)

UTF-8 문자의 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Single)

UTF-8 문자의 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Byte>, Single)

숫자의 문자열 표현을 포함하는 UTF-8 문자 범위를 해당하는 단정밀도 부동 소수점 숫자로 변환하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, IFormatProvider, Single)

문자 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Single)

지정된 스타일 및 문화권별 형식으로 된 숫자의 범위 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(ReadOnlySpan<Char>, Single)

문자 범위로 된 숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, IFormatProvider, Single)

문자열을 값으로 구문 분석하려고 시도합니다.

TryParse(String, NumberStyles, IFormatProvider, Single)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, Single)

숫자의 문자열 표현을 해당하는 단정밀도 부동 소수점 숫자로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

연산자

Equality(Single, Single)

지정된 두 Single 값이 같은지 여부를 나타내는 값을 반환합니다.

GreaterThan(Single, Single)

지정된 Single 값이 지정된 다른 Single 값보다 큰지 여부를 나타내는 값을 반환합니다.

GreaterThanOrEqual(Single, Single)

지정된 Single 값이 지정된 다른 Single 값보다 크거나 같은지 여부를 나타내는 값을 반환합니다.

Inequality(Single, Single)

지정된 두 Single 값이 같지 않은지 여부를 나타내는 값을 반환합니다.

LessThan(Single, Single)

지정된 Single 값이 지정된 다른 Single 값보다 작은지 여부를 나타내는 값을 반환합니다.

LessThanOrEqual(Single, Single)

지정된 Single 값이 지정된 다른 Single 값보다 작거나 같은지 여부를 나타내는 값을 반환합니다.

명시적 인터페이스 구현

IAdditionOperators<Single,Single,Single>.Addition(Single, Single)

두 값을 함께 추가하여 합계를 계산합니다.

IAdditiveIdentity<Single,Single>.AdditiveIdentity

현재 형식의 추가 ID를 가져옵니다.

IBinaryNumber<Single>.AllBitsSet

모든 비트가 설정된 이진 형식의 instance 가져옵니다.

IBitwiseOperators<Single,Single,Single>.BitwiseAnd(Single, Single)

두 값의 비트 및 를 계산합니다.

IBitwiseOperators<Single,Single,Single>.BitwiseOr(Single, Single)

두 값의 비트 또는 를 계산합니다.

IBitwiseOperators<Single,Single,Single>.ExclusiveOr(Single, Single)

배타적 또는 두 값의 계산.

IBitwiseOperators<Single,Single,Single>.OnesComplement(Single)

지정된 값의 보수 표현을 계산합니다.

IComparable.CompareTo(Object)

현재 인스턴스와 동일한 형식의 다른 개체를 비교하고 정렬 순서에서 현재 인스턴스의 위치가 다른 개체보다 앞인지, 뒤인지 또는 동일한지를 나타내는 정수를 반환합니다.

IConvertible.GetTypeCode()

이 인스턴스에 대한 TypeCode를 반환합니다.

IConvertible.ToBoolean(IFormatProvider)

이 멤버에 대한 설명은 ToBoolean(IFormatProvider)를 참조하세요.

IConvertible.ToByte(IFormatProvider)

이 멤버에 대한 설명은 ToByte(IFormatProvider)를 참조하세요.

IConvertible.ToChar(IFormatProvider)

이 변환은 지원되지 않습니다. 이 메서드를 사용하려고 하면 InvalidCastException이 throw됩니다.

IConvertible.ToDateTime(IFormatProvider)

이 변환은 지원되지 않습니다. 이 메서드를 사용하려고 하면 InvalidCastException이 throw됩니다.

IConvertible.ToDecimal(IFormatProvider)

이 멤버에 대한 설명은 ToDecimal(IFormatProvider)를 참조하세요.

IConvertible.ToDouble(IFormatProvider)

이 멤버에 대한 설명은 ToDouble(IFormatProvider)를 참조하세요.

IConvertible.ToInt16(IFormatProvider)

이 멤버에 대한 설명은 ToInt16(IFormatProvider)를 참조하세요.

IConvertible.ToInt32(IFormatProvider)

이 멤버에 대한 설명은 ToInt32(IFormatProvider)를 참조하세요.

IConvertible.ToInt64(IFormatProvider)

이 멤버에 대한 설명은 ToInt64(IFormatProvider)를 참조하세요.

IConvertible.ToSByte(IFormatProvider)

이 멤버에 대한 설명은 ToSByte(IFormatProvider)를 참조하세요.

IConvertible.ToSingle(IFormatProvider)

이 멤버에 대한 설명은 ToSingle(IFormatProvider)를 참조하세요.

IConvertible.ToType(Type, IFormatProvider)

이 멤버에 대한 설명은 ToType(Type, IFormatProvider)를 참조하세요.

IConvertible.ToUInt16(IFormatProvider)

이 멤버에 대한 설명은 ToUInt16(IFormatProvider)를 참조하세요.

IConvertible.ToUInt32(IFormatProvider)

이 멤버에 대한 설명은 ToUInt32(IFormatProvider)를 참조하세요.

IConvertible.ToUInt64(IFormatProvider)

이 멤버에 대한 설명은 ToUInt64(IFormatProvider)를 참조하세요.

IDecrementOperators<Single>.Decrement(Single)

값을 감소합니다.

IDivisionOperators<Single,Single,Single>.Division(Single, Single)

한 값을 다른 값으로 나누어 몫을 계산합니다.

IFloatingPoint<Single>.GetExponentByteCount()

의 일부로 TryWriteExponentLittleEndian(Span<Byte>, Int32)작성될 바이트 수를 가져옵니다.

IFloatingPoint<Single>.GetExponentShortestBitLength()

현재 지수의 가장 짧은 두 개의 보수 표현의 길이(비트)를 가져옵니다.

IFloatingPoint<Single>.GetSignificandBitLength()

현재 중요도의 길이(비트)를 가져옵니다.

IFloatingPoint<Single>.GetSignificandByteCount()

의 일부로 TryWriteSignificandLittleEndian(Span<Byte>, Int32)작성될 바이트 수를 가져옵니다.

IFloatingPoint<Single>.TryWriteExponentBigEndian(Span<Byte>, Int32)

현재 지수를 big-endian 형식으로 지정된 범위에 쓰려고 시도합니다.

IFloatingPoint<Single>.TryWriteExponentLittleEndian(Span<Byte>, Int32)

현재 지수를 little-endian 형식으로 지정된 범위에 쓰려고 시도합니다.

IFloatingPoint<Single>.TryWriteSignificandBigEndian(Span<Byte>, Int32)

현재 중요를 big-endian 형식으로 지정된 범위에 쓰려고 시도합니다.

IFloatingPoint<Single>.TryWriteSignificandLittleEndian(Span<Byte>, Int32)

현재 의미 있는 를 little-endian 형식으로 지정된 범위에 쓰려고 시도합니다.

IFloatingPointConstants<Single>.E

수학 상수를 e가져옵니다.

IFloatingPointConstants<Single>.Pi

수학 상수를 pi가져옵니다.

IFloatingPointConstants<Single>.Tau

수학 상수를 tau가져옵니다.

IFloatingPointIeee754<Single>.Epsilon

가 발생하지 않는 에 0 추가할 수 있는 가장 작은 값을 가져옵니다 0.

IFloatingPointIeee754<Single>.NaN

를 나타내는 값을 가져옵니다 NaN.

IFloatingPointIeee754<Single>.NegativeInfinity

infinity수 를 나타내는 값을 가져옵니다.

IFloatingPointIeee754<Single>.NegativeZero

zero수 를 나타내는 값을 가져옵니다.

IFloatingPointIeee754<Single>.PositiveInfinity

infinity수 를 나타내는 값을 가져옵니다.

IIncrementOperators<Single>.Increment(Single)

값을 증분합니다.

IMinMaxValue<Single>.MaxValue

현재 형식의 최대값을 가져옵니다.

IMinMaxValue<Single>.MinValue

현재 형식의 최소값을 가져옵니다.

IModulusOperators<Single,Single,Single>.Modulus(Single, Single)

두 값을 함께 나누어 모듈러스 또는 나머지를 계산합니다.

IMultiplicativeIdentity<Single,Single>.MultiplicativeIdentity

현재 형식의 곱하기 ID를 가져옵니다.

IMultiplyOperators<Single,Single,Single>.Multiply(Single, Single)

두 값을 함께 곱하여 제품을 계산합니다.

INumberBase<Single>.IsCanonical(Single)

값이 정식 표현에 있는지 확인합니다.

INumberBase<Single>.IsComplexNumber(Single)

값이 복소수를 나타내는지 여부를 결정합니다.

INumberBase<Single>.IsImaginaryNumber(Single)

값이 순수 허수의 숫자를 나타내는지 여부를 결정합니다.

INumberBase<Single>.IsZero(Single)

값이 0인지 확인합니다.

INumberBase<Single>.One

형식의 값을 1 가져옵니다.

INumberBase<Single>.Radix

형식의 radix 또는 base를 가져옵니다.

INumberBase<Single>.TryConvertFromChecked<TOther>(TOther, Single)

단정밀도 부동 소수점 숫자를 나타냅니다.

INumberBase<Single>.TryConvertFromSaturating<TOther>(TOther, Single)

단정밀도 부동 소수점 숫자를 나타냅니다.

INumberBase<Single>.TryConvertFromTruncating<TOther>(TOther, Single)

단정밀도 부동 소수점 숫자를 나타냅니다.

INumberBase<Single>.TryConvertToChecked<TOther>(Single, TOther)

현재 형식의 instance 다른 형식으로 변환하여 현재 형식의 표시 가능한 범위를 벗어나는 값에 대해 오버플로 예외를 throw합니다.

INumberBase<Single>.TryConvertToSaturating<TOther>(Single, TOther)

현재 형식의 instance 다른 형식으로 변환하여 현재 형식의 표현 가능한 범위를 벗어나는 값을 채도합니다.

INumberBase<Single>.TryConvertToTruncating<TOther>(Single, TOther)

현재 형식의 instance 다른 형식으로 변환하여 현재 형식의 표현 가능한 범위를 벗어나는 값을 잘리려고 시도합니다.

INumberBase<Single>.Zero

형식의 값을 0 가져옵니다.

ISignedNumber<Single>.NegativeOne

형식의 값을 -1 가져옵니다.

ISubtractionOperators<Single,Single,Single>.Subtraction(Single, Single)

두 값을 빼서 차이를 계산합니다.

IUnaryNegationOperators<Single,Single>.UnaryNegation(Single)

값의 단항 부정을 계산합니다.

IUnaryPlusOperators<Single,Single>.UnaryPlus(Single)

값의 단항 더하기 를 계산합니다.

적용 대상

스레드 보안

이 형식의 모든 멤버는 스레드로부터 안전합니다. instance 상태를 수정하는 것처럼 보이는 멤버는 실제로 새 값으로 초기화된 새 instance 반환합니다. 다른 형식과 마찬가지로 이 형식의 instance 포함하는 공유 변수에 대한 읽기 및 쓰기는 스레드 안전을 보장하기 위해 잠금으로 보호되어야 합니다.

추가 정보