title: Scala factorial on large numbers sometimes crashes and sometimes doesn't
body: <p>The following program, was compiled and tested, it sometimes return the result, and sometimes fills the screen with</p>
  
  <pre><code>java.lang.StackOverflowError
  at scala.BigInt$.apply(BigInt.scala:47)
  at scala.BigInt.equals(BigInt.scala:129)
  at scala.runtime.BoxesRunTime.equals(Unknown Source)
  at bigint$.factorial(fact2.scala:3)
  at bigint$.factorial(fact2.scala:3)
  ...
  </code></pre>
  
  <p>The program: </p>
  
  <pre><code>object bigint extends Application {
    def factorial(n: BigInt): BigInt = if (n == 0) 1 else n * factorial(n-1)
    println("4391! = "+factorial(4391))
  }
  </code></pre>
  
  <p>My questions:</p>
  
  <ul>
  <li>Is it because there is a stack overflow on the JVM, which sometimes happens and sometimes doesn't?</li>
  <li>Is this nondeterministic behavior considered a bug?</li>
  <li>I assume Scala did not tail-recursed this? how can I make it tail-recurse this?</li>
  </ul>
  
  <p>Details:</p>
  
  <blockquote>
    <p>Scala compiler version 2.7.5.final --
    Copyright 2002-2009, LAMP/EPFL Scala
    code runner version 2.7.5.final --
    Copyright 2002-2009, LAMP/EPFL</p>
    
    <p>java version "1.6.0_0" OpenJDK 
    Runtime Environment (build
    1.6.0_0-b11) OpenJDK Client VM (build 1.6.0_0-b11, mixed mode, sharing)</p>
    
    <p>Ubuntu 2.6.24-24-generic</p>
  </blockquote>