Skip to content

Commit 20a1781

Browse files
Minor improvement for the documentation of ulp and ulpOfOne. (#23211)
1. Move discussion of `DBL_EPSILON` etc. onto `ulpOfOne` instead of `ulp`. 2. Add text explaining that `ulpOfOne` is a poor value to use for approximate comparison.
1 parent 6cb9a69 commit 20a1781

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

stdlib/public/core/FloatingPoint.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,25 @@ public protocol FloatingPoint : SignedNumeric, Strideable, Hashable
366366
/// - `greatestFiniteMagnitude.ulp` is a finite number, even though the next
367367
/// greater representable value is `infinity`.
368368
///
369-
/// This quantity, or a related quantity, is sometimes called *epsilon* or
370-
/// *machine epsilon.* Avoid that name because it has different meanings in
371-
/// different languages, which can lead to confusion, and because it
372-
/// suggests that it is a good tolerance to use for comparisons, which it
373-
/// almost never is.
369+
/// See also the `ulpOfOne` static property.
374370
var ulp: Self { get }
375371

376372
/// The unit in the last place of 1.0.
377373
///
378374
/// The positive difference between 1.0 and the next greater representable
379-
/// number. The `ulpOfOne` constant corresponds to the C macros
380-
/// `FLT_EPSILON`, `DBL_EPSILON`, and others with a similar purpose.
375+
/// number. `ulpOfOne` corresponds to the value represented by the C macros
376+
/// `FLT_EPSILON`, `DBL_EPSILON`, etc, and is sometimes called *epsilon* or
377+
/// *machine epsilon*. Swift deliberately avoids using the term "epsilon"
378+
/// because:
379+
///
380+
/// - Historically "epsilon" has been used to refer to several different
381+
/// concepts in different languages, leading to confusion and bugs.
382+
///
383+
/// - The name "epsilon" suggests that this quantity is a good tolerance to
384+
/// choose for approximate comparisons, but it is almost always unsuitable
385+
/// for that purpose.
386+
///
387+
/// See also the `ulp` member property.
381388
static var ulpOfOne: Self { get }
382389

383390
/// The least positive normal number.

0 commit comments

Comments
 (0)