4

In earlier versions of Scala, I used to be able to do something like this to get the minimum value:

val minValue = Seq[Float](0.3f, 0.5f, 0.1f, 0.8f).min

That seemed simple and easy to understand. In Scala 2.13.1, I get this error:

object DeprecatedFloatOrdering in object Ordering is deprecated (since 2.13.0): There are multiple ways to order Floats (Ordering.Float.TotalOrdering, Ordering.Float.IeeeOrdering). Specify one by using a local import, assigning an implicit val, or passing it explicitly. See their documentation for details.

I read about TotalOrdering and IeeeOrdering in the Scala doc and looked unsuccessfully for examples of how to use them, but I don't get it. Given my simple example, what is the new way to find the min and why can't it just default to earlier behavior if not specified?

user1933178
  • 340
  • 3
  • 12
  • 3
    Just `import scala.math.Ordering.Float.TotalOrdering` before calling `min` as stated on the [**documentation**](https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html). – Luis Miguel Mejía Suárez Oct 07 '19 at 00:24
  • Thanks. That worked. I would still prefer that there just be a default, but OK. – user1933178 Oct 07 '19 at 01:49
  • 4
    The reason why there can't be a default ordering for floats is that there is more than one possible ordering for floats. – Jörg W Mittag Oct 07 '19 at 02:13
  • 2
    Just because there is more than one possible ordering doesn't mean that there cannot be a default. As I understand it, the orderings are nearly identical except for some edge cases involving NaN. I don't understand why it can't just use the old ordering (or Java's ordering) as the default. – user1933178 Oct 08 '19 at 02:45

0 Answers0