[#1016] | project: compiler | priority: low | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Iulian | _ | fixed | 2007-03-23 19:02:11.0 | |
subject | [contrib #394] scala.BigInt ArrayIndexOutOfBoundsException | |||
code |
object pidigits { def main(args: Array[String]): unit = { val N: int = Integer.parseInt(args(0)); var i: int = 10 while (i <= N) { System.out.println(pi_digits(10) + "\t:" + i) i = i + 10 } i = i - 10 if (i < N) { System.out.println(pi_digits(N - i) + "\t:" + N) } } def compose(a: Array[BigInt], b: Array[BigInt]): Array[BigInt] = { return Array(a(0) * b(0), a(0) * b(1) + a(1) * b(3), a(2) * b(0) + a(3) * b(2), a(2) * b(1) + a(3) * b(3)) } def extract(a: Array[BigInt], j: int): BigInt = { return (a(0) * j + a(1)) / (a(2) * j + a(3)) } def pi_digits(c: int): String = { val r: StringBuffer = new StringBuffer(); var i: int = 0 while (i < c) { var y: BigInt = extract(Z, 3) while (y != extract(Z, 4)) { K = K + 1; Z = compose(Z, Array(K, 4 * K + 2, 0, 2 * K + 1)) y = extract(Z, 3) } Z = compose(Array(10, y * -10, 0, 1), Z) r.append(y); i = i + 1; } return r.toString() } var K: int = 0 var Z: Array[BigInt] = Array(1, 0, 0, 1) } |
|||
what happened | JAVACMD="/opt/sun-jdk-1.6.0/bin/java $JDKFLAGS -server" /opt/scala-2.4.0/bin/scala -classpath pidigits.scala_ru\ n pidigits %A java.lang.ArrayIndexOutOfBoundsException: -10 at scala.BigInt$.apply(BigInt.scala:34) at scala.BigInt$.int2bigInt(BigInt.scala:98) at pidigits$.pi_digits(pidigits.scala:55) at pidigits$.main(pidigits.scala:16) at pidigits.main(pidigits.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:76) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:106) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) |
|||
what expected | http://shootout.alioth.debian.org/debian/benchmark.php?test=pidigits&lang=scala&id=0#log | |||
[back to overview] |
Iulian edited on 2007-03-23 19:02:23.0 |