Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save plokhotnyuk/c63e841bbab0ba9bd89c24d5f2bda479 to your computer and use it in GitHub Desktop.
Save plokhotnyuk/c63e841bbab0ba9bd89c24d5f2bda479 to your computer and use it in GitHub Desktop.
andriy@notebook:~$ /opt/scala-2.13.0-RC1/bin/scala
Welcome to Scala 2.13.0-RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_212).
Type in expressions for evaluation. Or try :help.
scala> def timed[A](f: => A): A = { val t = System.currentTimeMillis; val r = f; println(s"Elapsed time (ms): ${System.currentTimeMillis - t}"); r }
timed: [A](f: => A)A
scala> timed(BigDecimal("1e-1000000000") + 1)
Elapsed time (ms): 1
res0: scala.math.BigDecimal = 1.000000000000000000000000000000000
scala> timed(BigDecimal("1e-1000000000", java.math.MathContext.UNLIMITED) + 1)
java.lang.ArithmeticException: BigInteger would overflow supported range
at java.math.BigInteger.reportOverflow(BigInteger.java:1084)
at java.math.BigInteger.pow(BigInteger.java:2391)
at java.math.BigDecimal.bigTenToThe(BigDecimal.java:3574)
at java.math.BigDecimal.bigMultiplyPowerTen(BigDecimal.java:4539)
at java.math.BigDecimal.add(BigDecimal.java:4485)
at java.math.BigDecimal.add(BigDecimal.java:1292)
at java.math.BigDecimal.add(BigDecimal.java:1321)
at scala.math.BigDecimal.$plus(BigDecimal.scala:487)
at .$anonfun$res1$1(<console>:1)
at .timed(<console>:1)
... 28 elided
scala> timed(BigDecimal("1e-100000000", java.math.MathContext.UNLIMITED) + 1)
Elapsed time (ms): 84467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment