Scala 範例 - 巨大整數 (bigint)

原始程式:bigint.scala

/** Bigint's can be used seamlessly */
object bigint extends Application {
  def factorial(n: BigInt): BigInt =
    if (n == 0) 1 else n * factorial(n-1)

  val f50 = factorial(50); val f49 = factorial(49)
  println("50! = " + f50)
  println("49! = " + f49)
  println("50!/49! = " + (f50 / f49))
}

執行結果:

D:\Scala\code>scalac bigint.scala

D:\Scala\code>scala bigint
50! = 30414093201713378043612608166064768844377641568960512000000000000
49! = 608281864034267560872252163321295376887552831379210240000000000
50!/49! = 50
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License