C#의 Single.IsNan() 메서드는 지정된 값이 숫자(NaN)가 아닌지 여부를 나타내는 값을 반환하는 데 사용됩니다.
구문
구문은 다음과 같습니다 -
public static bool IsNaN (float f);
위에서 매개변수 val은 단정밀도 부동 소수점 숫자입니다.
예
이제 예를 살펴보겠습니다 -
using System; public class Demo { public static void Main() { float f1 = 5.0f/0.0f; float f2 = 45.5f; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); } }
출력
이것은 다음과 같은 출력을 생성합니다 -
Value1 = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Value2 = 45.5 Hashcode for Value2 = 1110835200 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = False
예
이제 다른 예를 살펴보겠습니다 -
using System; public class Demo { public static void Main() { float f1 = 5.0f/0.0f; float f2 = 0.0f / 0.0f; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); } }
출력
이것은 다음과 같은 출력을 생성합니다 -
Value1 = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Value2 = NaN Hashcode for Value2 = -4194304 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = True