Dotty: Inconsistent Behavior of Double#NaN

Created on 4 Dec 2019  路  2Comments  路  Source: lampepfl/dotty

We noticed some inconsistent behavior involving Double.NaN when enabling one the ZIO test suites on Dotty. The following snippet will print true and false on Dotty 0.20.0-RC1 whereas it will print false and false on Scala 2.13.1. I saw that there was another issue reported regarding Double.NaN in #6710 but it looks like that was resolved back in June so this appears to be different, though potentially related.

Please let me know if there is anything else I can do to help!

object Example extends App {
  val a: Double = Double.NaN
  val eval = (a <= 0) || (10L <= 0)
  println(s"when Double.NaN is extracted to val, expression is evaluated to: $eval")
  val eval2 = (Double.NaN <= 0) || (10L <= 0)
  println(s"when Double.NaN is used directly, expression is evaluated to: $eval2")
}
backend bug

Most helpful comment

I tracked this down to what looks like a bug in the backend. Dotty issues a dcmpl instruction where scalac issues a dcmpg. The eval2 case yields false in both compilers since it is constant folded.

I am not able to fix this right now. The plan is anyway to use the scalac backend in Dotty, which will hopefully fix this problem. /cc @lrytz

All 2 comments

I tracked this down to what looks like a bug in the backend. Dotty issues a dcmpl instruction where scalac issues a dcmpg. The eval2 case yields false in both compilers since it is constant folded.

I am not able to fix this right now. The plan is anyway to use the scalac backend in Dotty, which will hopefully fix this problem. /cc @lrytz

You are on fire!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

odersky picture odersky  路  27Comments

odersky picture odersky  路  66Comments

odersky picture odersky  路  114Comments

odersky picture odersky  路  71Comments

lihaoyi picture lihaoyi  路  30Comments