Created
April 18, 2019 19:10
-
-
Save plokhotnyuk/c63e841bbab0ba9bd89c24d5f2bda479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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