Double.Nan值

此常數的值是零被零除所得到的結果。  
      當運算結果未定義時返回此常數。  
      使用   IsNaN   確定值是否爲非數字。不可能通過將某個值與另一個等於   NaN   的值進行比較來確定該值是否不是數字。   
    
下面的代碼示例演示如何使用   NaN:    
   
  Visual   Basic  
  Dim   zero   As   Double   =   0  
   
  '   This   condition   will   return   false.  
  If   (0   /   zero)   =   Double.NaN   Then  
          Console.WriteLine("0   /   0   can   be   tested   with   Double.NaN.")  
  Else  
          Console.WriteLine("0   /   0   cannot   be   tested   with   Double.NaN;   use   Double.IsNan()   instead.")  
  End   If  
   
     
  C#    
  Double   zero   =   0;  
   
  //   This   condition   will   return   false.  
  if   ((0   /   zero)   ==   Double.NaN)    
  {  
          Console.WriteLine("0   /   0   can   be   tested   with   Double.NaN.");  
  }    
  else    
  {  
          Console.WriteLine("0   /   0   cannot   be   tested   with   Double.NaN;   use   Double.IsNan()   instead.");  
  }  
   
     
  C++  
  Double   zero   =   0;  
   
  //   This   condition   will   return   false.  
  if   (   (0   /   zero)   ==   Double::NaN   )  
  {  
        Console::WriteLine(   "0   /   0   can   be   tested   with   Double::NaN."   );  
  }  
  else  
  {  
        Console::WriteLine(   "0   /   0   cannot   be   tested   with   Double::NaN;   use   Double::IsNan()   instead."   );  
  }  
   
     
  J#  
  Double   zero   =   new   Double(0);  
   
  //   This   condition   will   return   false.  
  if   (0   /   zero.doubleValue()   ==   Double.NaN)   {  
          Console.WriteLine("0   /   0   can   be   tested   with   Double.NaN.");  
  }  
  else   {  
          Console.WriteLine(  
                  "0   /   0   cannot   be   tested   with   Double.NaN;   "    
                  +   "use   Double.IsNan()   instead.");  
  }  
   
     
  以上都會輸出  
  0   /   0   cannot   be   tested   with   Double.NaN;   use   Double.IsNan()   instead. 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章