Class/Object

org.hammerlab.math.tolerance

Geometric

Related Docs: object Geometric | package tolerance

Permalink

final class Geometric extends AnyVal

Consider Doubles to be "equal" if they are within a factor of ε of one another:

import hammerlab.math.syntax._
implicit val ε: E = 1e-6
2.0 === 2.000002      //  true
2.0 !== 2.0000020001  // false
2.0 <<< 2.0000020001  //  true
2.0 <<= 2.0000020001  //  true
2.02.0000020001  //  true

Construction is done by assigning an "epsilon" value, as demonstrated above, which is then incremented by 1 to obtain the value that is actually used for comparing ratios. Doubles have 15 decimal-digits'-worth of precision, so an ε of 1e-16 or lower will effectively result in strict equality:

implicit val ε: E = 1e-15
// ε: hammerlab.math.tolerance.E = ±1.000000000000001

implicit val ε: E = 1e-16
// ε: hammerlab.math.tolerance.E = ±1.0

Note that equality (and by extension, ≤ and ≥) are not transitive! Don't try to use this as an Ordering!

implicit val ε: E = 1e-2
2.0  === 2.02  //  true
2.02 === 2.04  //  true
2.0  === 2.04  // false!

Note also that 0 can only === 0; whether a Double shoould be considered fuzzily-equal to 0 is a complicated question (likely requiring tracking of floating-point-arithmetic error) that this simple implementation of fuzzy-equality doesn't attempt to address.

Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Geometric
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. def !==(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  3. final def ##(): Int

    Permalink
    Definition Classes
    Any
  4. def <(l: D, r: D): Boolean

    Permalink
  5. def <=(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  6. def <>(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  7. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  8. def ===(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  9. def >(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  10. def >=(l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def toString(): String

    Permalink
    Definition Classes
    Geometric → Any
  15. val ε: Double

    Permalink
  16. def (l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()
  17. def (l: D, r: D): Boolean

    Permalink
    Annotations
    @inline()

Inherited from AnyVal

Inherited from Any

Ungrouped