Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#의 Double.IsNaN() 메서드


C#의 Double.IsNaN() 메서드는 지정된 값이 숫자(NaN)가 아닌지 여부를 나타내는 값을 반환하는 데 사용됩니다.

구문

구문은 다음과 같습니다 -

public static bool IsNaN (double val);

위의 val은 배정도 부동 소수점 숫자입니다.

이제 예를 살펴보겠습니다 -

using System;
public class Demo {
   public static void Main(){
      double d = 1.0/0.0;
      Console.WriteLine("Double Value = "+d);
      Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());
      TypeCode type = d.GetTypeCode();
      Console.WriteLine("TypeCode of Double Value = "+type);
      Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d));
      Console.WriteLine("Check whether the specified value is NaN? = "+Double.IsNaN(d));
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Double Value = ∞
HashCode of Double Value = 2146435072
TypeCode of Double Value = Double
Positive Infinity? = True
Check whether the specified value is NaN? = False

이제 다른 예를 살펴보겠습니다 -

using System;
public class Demo {
   public static void Main(){
      double d = 0.0/0;
      Console.WriteLine("Double Value = "+d);
      Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());
      TypeCode type = d.GetTypeCode();
      Console.WriteLine("TypeCode of Double Value = "+type);
      Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d));
      Console.WriteLine("Check whether the specified value is NaN? = "+Double.IsNaN(d));
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Double Value = NaN
HashCode of Double Value = -524288
TypeCode of Double Value = Double
Positive Infinity? = False
Check whether the specified value is NaN? = True