Skip to content

Commit

Permalink
Merge pull request #1 from dwijnand/wip/migrate-ordering
Browse files Browse the repository at this point in the history
Reword
  • Loading branch information
eed3si9n committed Feb 18, 2020
2 parents acf7044 + efbbad1 commit ee86732
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
52 changes: 27 additions & 25 deletions src/library/scala/math/Ordering.scala
Expand Up @@ -370,17 +370,17 @@ object Ordering extends LowPriorityOrderingImplicits {

/** `Ordering`s for `Float`s.
*
* The behavior of the comparison operations provided by default (implicit)
* ordering on `Float` has changed in 2.10.0 and 2.13.0.
* Prior to Scala 2.10.0, the `Ordering` instance used the semantics
* The behavior of the comparison operations provided by the default (implicit)
* ordering on `Float` changed in 2.10.0 and 2.13.0.
* Prior to Scala 2.10.0, the `Ordering` instance used semantics
* consistent with `java.lang.Float.compare`.
*
* Scala 2.10.0 changed the implementation of `lt`, `equiv`, `min` etc to be
* IEEE 754 compliant, while keeping `compare` method NOT compliant,
* creating an internally inconsistent instance. IEEE 754 specified that
* `0.0F == -0.0F`. In addition, all comparisons with `Float.NaN` must return
* Scala 2.10.0 changed the implementation of `lt`, `equiv`, `min`, etc., to be
* IEEE 754 compliant, while keeping the `compare` method NOT compliant,
* creating an internally inconsistent instance. IEEE 754 specifies that
* `0.0F == -0.0F`. In addition, it requires all comparisons with `Float.NaN` return
* `false` thus `0.0F < Float.NaN`, `0.0F > Float.NaN`, and
* `Float.NaN == Float.NaN` all yield `false`, analogous to `None`.
* `Float.NaN == Float.NaN` all yield `false`, analogous `None` in `flatMap`.
*
* Recognizing the limitation of the IEEE 754 semantics in terms of ordering,
* Scala 2.13.0 created two instances: `Ordering.Float.IeeeOrdering`, which retains
Expand Down Expand Up @@ -454,26 +454,27 @@ object Ordering extends LowPriorityOrderingImplicits {
implicit object IeeeOrdering extends IeeeOrdering
}
@migration(
" The new ordering does not affect the sorting, placing NaN at the end.\n" +
" However, methods such as `lt`, `min`, and `equiv` now match `compare`\n" +
" instead of having IEEE 754 behavior for -0.0F and NaN.\n" +
" Import Ordering.Float.IeeeOrdering to retain the previous behavior.\n" +
" See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html", "2.13.0")
" The default implicit ordering for floats now maintains consistency\n" +
" between its `compare` method and its `lt`, `min`, `equiv`, etc., methods,\n" +
" which means nonconforming to IEEE 754's behavior for -0.0F and NaN.\n" +
" The sort order of floats remains the same, however, with NaN at the end.\n" +
" Import Ordering.Float.IeeeOrdering to recover the previous behavior.\n" +
" See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html.", "2.13.0")
implicit object DeprecatedFloatOrdering extends Float.TotalOrdering

/** `Ordering`s for `Double`s.
*
* The behavior of the comparison operations provided by default (implicit)
* ordering on `Double` has changed in 2.10.0 and 2.13.0.
* Prior to Scala 2.10.0, the `Ordering` instance used the semantics
* The behavior of the comparison operations provided by the default (implicit)
* ordering on `Double` changed in 2.10.0 and 2.13.0.
* Prior to Scala 2.10.0, the `Ordering` instance used semantics
* consistent with `java.lang.Double.compare`.
*
* Scala 2.10.0 changed the implementation of `lt`, `equiv`, `min` etc to be
* IEEE 754 compliant, while keeping `compare` method NOT compliant,
* creating an internally inconsistent instance. IEEE 754 specified that
* `0.0 == -0.0`. In addition, all comparisons with `Double.NaN` must return
* Scala 2.10.0 changed the implementation of `lt`, `equiv`, `min`, etc., to be
* IEEE 754 compliant, while keeping the `compare` method NOT compliant,
* creating an internally inconsistent instance. IEEE 754 specifies that
* `0.0 == -0.0`. In addition, it requires all comparisons with `Double.NaN` return
* `false` thus `0.0 < Double.NaN`, `0.0 > Double.NaN`, and
* `Double.NaN == Double.NaN` all yield `false`, analogous to `None`.
* `Double.NaN == Double.NaN` all yield `false`, analogous `None` in `flatMap`.
*
* Recognizing the limitation of the IEEE 754 semantics in terms of ordering,
* Scala 2.13.0 created two instances: `Ordering.Double.IeeeOrdering`, which retains
Expand Down Expand Up @@ -547,10 +548,11 @@ object Ordering extends LowPriorityOrderingImplicits {
implicit object IeeeOrdering extends IeeeOrdering
}
@migration(
" The new ordering does not affect the sorting, placing NaN at the end.\n" +
" However, methods such as `lt`, `min`, and `equiv` now match `compare`\n" +
" instead of having IEEE 754 behavior for -0.0 and NaN.\n" +
" Import Ordering.Double.IeeeOrdering to retain the previous behavior.\n" +
" The default implicit ordering for doubles now maintains consistency\n" +
" between its `compare` method and its `lt`, `min`, `equiv`, etc., methods,\n" +
" which means nonconforming to IEEE 754's behavior for -0.0 and NaN.\n" +
" The sort order of doubles remains the same, however, with NaN at the end.\n" +
" Import Ordering.Double.IeeeOrdering to recover the previous behavior.\n" +
" See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Double$.html.", "2.13.0")
implicit object DeprecatedDoubleOrdering extends Double.TotalOrdering

Expand Down
29 changes: 16 additions & 13 deletions test/files/neg/ordering-migration.check
@@ -1,24 +1,27 @@
ordering-migration.scala:3: warning: object DeprecatedFloatOrdering in object Ordering has changed semantics in version 2.13.0:
The new ordering does not affect the sorting, placing NaN at the end.
However, methods such as `lt`, `min`, and `equiv` now match `compare`
instead of having IEEE 754 behavior for -0.0F and NaN.
Import Ordering.Float.IeeeOrdering to retain the previous behavior.
See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html
The default implicit ordering for floats now maintains consistency
between its `compare` method and its `lt`, `min`, `equiv`, etc., methods,
which means nonconforming to IEEE 754's behavior for -0.0F and NaN.
The sort order of floats remains the same, however, with NaN at the end.
Import Ordering.Float.IeeeOrdering to recover the previous behavior.
See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html.
val f = Ordering[Float]
^
ordering-migration.scala:4: warning: object DeprecatedDoubleOrdering in object Ordering has changed semantics in version 2.13.0:
The new ordering does not affect the sorting, placing NaN at the end.
However, methods such as `lt`, `min`, and `equiv` now match `compare`
instead of having IEEE 754 behavior for -0.0 and NaN.
Import Ordering.Double.IeeeOrdering to retain the previous behavior.
The default implicit ordering for doubles now maintains consistency
between its `compare` method and its `lt`, `min`, `equiv`, etc., methods,
which means nonconforming to IEEE 754's behavior for -0.0 and NaN.
The sort order of doubles remains the same, however, with NaN at the end.
Import Ordering.Double.IeeeOrdering to recover the previous behavior.
See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Double$.html.
val d = Ordering[Double]
^
ordering-migration.scala:7: warning: object DeprecatedDoubleOrdering in object Ordering has changed semantics in version 2.13.0:
The new ordering does not affect the sorting, placing NaN at the end.
However, methods such as `lt`, `min`, and `equiv` now match `compare`
instead of having IEEE 754 behavior for -0.0 and NaN.
Import Ordering.Double.IeeeOrdering to retain the previous behavior.
The default implicit ordering for doubles now maintains consistency
between its `compare` method and its `lt`, `min`, `equiv`, etc., methods,
which means nonconforming to IEEE 754's behavior for -0.0 and NaN.
The sort order of doubles remains the same, however, with NaN at the end.
Import Ordering.Double.IeeeOrdering to recover the previous behavior.
See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Double$.html.
list.sorted
^
Expand Down

0 comments on commit ee86732

Please sign in to comment.