Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5779

Wrong warning message (comparing values of types Float/Double and Number using `==' will always yield false)

    Details

      Description

      In the following example, a Float and a Double is compared with a Number. They are all equal, and == returns true.
      However, the compiler gives the warning "comparing values of types Double and Number using `==' will always yield false" and this is not true!

      scala> val d = (BigInt(1) << 64).toDouble
      d: Double = 1.8446744073709552E19
       
      scala> val f: Float = d.toFloat
      f: Float = 1.8446744E19
       
      scala> val n: java.lang.Number = d
      n: Number = 1.8446744073709552E19
       
      scala> d == f
      res37: Boolean = true
       
      scala> d == n
      <console>:10: warning: comparing values of types Double and Number using `==' will always yield false
                    d == n
                      ^
      res38: Boolean = true
       
      scala> f == n
      <console>:11: warning: comparing values of types Float and Number using `==' will always yield false
                    f == n
                      ^
      res39: Boolean = true
      

        Attachments

          Activity

          Hide
          apm A. P. Marki added a comment -

          Probably this bug won't exist in some future version of Scala.

          https://github.com/scala/scala/pull/599

          Show
          apm A. P. Marki added a comment - Probably this bug won't exist in some future version of Scala. https://github.com/scala/scala/pull/599
          Hide
          apm A. P. Marki added a comment -

          adriaanm merged commit 2e7daa1

          Show
          apm A. P. Marki added a comment - adriaanm merged commit 2e7daa1

            People

            • Assignee:
              apm A. P. Marki
              Reporter:
              dgruntz Dominik Gruntz
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: