Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.math/Ordering/Double

Double

scala.math.Ordering.Double
objectDouble

Orderings forDoubles.

The behavior of the comparison operations provided by the default (implicit) ordering onDouble changed in 2.10.0 and 2.13.0. Prior to Scala 2.10.0, theOrdering instance used semantics consistent withjava.lang.Double.compare.

Scala 2.10.0 changed the implementation oflt,equiv,min, etc., to be IEEE 754 compliant, while keeping thecompare method NOT compliant, creating an internally inconsistent instance. IEEE 754 specifies that0.0 == -0.0. In addition, it requires all comparisons withDouble.NaN returnfalse thus0.0 < Double.NaN,0.0 > Double.NaN, andDouble.NaN == Double.NaN all yieldfalse, analogousNone inflatMap.

Recognizing the limitation of the IEEE 754 semantics in terms of ordering, Scala 2.13.0 created two instances:Ordering.Double.IeeeOrdering, which retains the IEEE 754 semantics from Scala 2.12.x, andOrdering.Double.TotalOrdering, which brings back thejava.lang.Double.compare semantics for all operations. The default extendsTotalOrdering.

List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).sorted      // List(-Infinity, 0.0, 1.0, NaN)List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).min         // -Infinityimplicitly[Ordering[Double]].lt(0.0, 0.0 / 0.0)   // true{  import Ordering.Double.IeeeOrdering  List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).sorted    // List(-Infinity, 0.0, 1.0, NaN)  List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).min       // NaN  implicitly[Ordering[Double]].lt(0.0, 0.0 / 0.0) // false}

Attributes

Source
Ordering.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Self type
Double.type

Members list

Type members

Classlikes

Attributes

Companion
trait
Source
Ordering.scala
Supertypes
traitEquiv[Double]
classObject
traitMatchable
classAny
Show all
Self type

An ordering forDoubles which is consistent with IEEE specifications whenever possible.

An ordering forDoubles which is consistent with IEEE specifications whenever possible.

  • lt,lteq,equiv,gteq andgt are consistent with primitive comparison operations forDoubles, and returnfalse when called withNaN.

  • min andmax are consistent withmath.min andmath.max, and returnNaN when called withNaN as either argument.

  • compare behaves the same asjava.lang.Double.compare.

Because the behavior ofDoubles specified by IEEE is not consistent with a total ordering when dealing withNaN, there are two orderings defined forDouble:TotalOrdering, which is consistent with a total ordering, andIeeeOrdering, which is consistent as much as possible with IEEE spec and floating point operations defined inscala.math.

This ordering may be preferable for numeric contexts.

Attributes

See also
Companion
object
Source
Ordering.scala
Supertypes
traitEquiv[Double]
classObject
traitMatchable
classAny
Show all
Known subtypes

Attributes

Companion
trait
Source
Ordering.scala
Supertypes
traitEquiv[Double]
classObject
traitMatchable
classAny
Show all
Self type

An ordering forDoubles which is a fully consistent total ordering, and treatsNaN as larger than all otherDouble values; it behaves the same asjava.lang.Double.compare.

An ordering forDoubles which is a fully consistent total ordering, and treatsNaN as larger than all otherDouble values; it behaves the same asjava.lang.Double.compare.

Because the behavior ofDoubles specified by IEEE is not consistent with a total ordering when dealing withNaN, there are two orderings defined forDouble:TotalOrdering, which is consistent with a total ordering, andIeeeOrdering, which is consistent as much as possible with IEEE spec and floating point operations defined inscala.math.

This ordering may be preferable for sorting collections.

Attributes

See also
Companion
object
Source
Ordering.scala
Supertypes
traitEquiv[Double]
classObject
traitMatchable
classAny
Show all
Known subtypes
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp