Instance Property

ulp

The unit in the last place of this value.

Declaration

var ulp: Double { get }

Discussion

This is the unit of the least significant digit in this value’s significand. For most numbers x, this is the difference between x and the next greater (in magnitude) representable number. There are some edge cases to be aware of:

  • If x is not a finite number, then x.ulp is NaN.

  • If x is very small in magnitude, then x.ulp may be a subnormal number. If a type does not support subnormals, x.ulp may be rounded to zero.

  • greatestFiniteMagnitude.ulp is a finite number, even though the next greater representable value is infinity.

This quantity, or a related quantity, is sometimes called epsilon or machine epsilon. Avoid that name because it has different meanings in different languages, which can lead to confusion, and because it suggests that it is a good tolerance to use for comparisons, which it almost never is.

Relationships

From Protocol

See Also

Querying a Double

var significand: Double

The significand of the floating-point value.

var exponent: Int

The exponent of the floating-point value.

var nextUp: Double

The least representable value that compares greater than this value.

var nextDown: Double

The greatest representable value that compares less than this value.

var binade: Double

The floating-point value with the same sign and exponent as this value, but with a significand of 1.0.