Scala division by zero yields different results : <p>I am confused with how Scala handles division by zero. Here is a REPL code snippet. </p>

<pre><code>scala&gt; 1/0
java.lang.ArithmeticException: / by zero
  ... 33 elided

scala&gt; 1.toDouble/0.toDouble
res1: Double = Infinity

scala&gt; 0.0/0.0
res2: Double = NaN

scala&gt; 0/0
java.lang.ArithmeticException: / by zero
  ... 33 elided

scala&gt; 1.toInt/0.toInt
java.lang.ArithmeticException: / by zero
  ... 33 elided
</code></pre>

<p>As you can see in the above example, depending on how you divide by zero, you get one of the following: </p>

<ul>
<li>"java.lang.ArithmeticException: / by zero" </li>
<li>"Double = NaN" </li>
<li>"Double = Infinity"</li>
</ul>

<p>This makes debugging quite challenging especially when dealing with data of unknown characteristics. What is the reasoning behind this approach, or even a better question, how to handle division by zero in a unified manner in Scala?</p>
