2016-04-27 69 views
2

我想檢查給出的結果是否等於無窮大。如何正確檢查它?如何檢查無窮大時除法爲0

<input type="text" name="answer" id="t" onkeyup="withoutLat(this);withoutCyr(this);checkInfinity(this);" placeholder="Enter data" autofocus> 

     function checkInfinity(value) 
    { 

     var value = calculator.answer.value; 

     if (value == Number.POSITIVE_INFINITY || value == Number.NEGATIVE_INFINITY) 
     { 
      alert("Помилка ділення на нуль") 
     } 
    } 
+0

不,它不需要。只有'0/0'產生'NaN',因爲它比「其他數字除以零」更「不確定」。當x!= 0時,'x/0'將導致'sgn(x)* Infinity',即'5/0'爲'Number.POSITIVE_INFINITY','(-5)/ 0'爲'Number.NEGATIVE_INFINITY'。 – CherryDT

回答

3
isFinite(12) //true 
isFinite(12/0) //false