@@ -56,6 +56,10 @@ extension Augmented {
56
56
57
57
/// The sum `a + b` represented as an implicit sum `head + tail`.
58
58
///
59
+ /// - Parameters:
60
+ /// - a: The summand with larger magnitude.
61
+ /// - b: The summand with smaller magnitude.
62
+ ///
59
63
/// `head` is the correctly rounded value of `a + b`. `tail` is the
60
64
/// error from that computation rounded to the closest representable
61
65
/// value.
@@ -65,15 +69,13 @@ extension Augmented {
65
69
///
66
70
/// This operation is sometimes called ["fastTwoSum"].
67
71
///
68
- /// - Parameters:
69
- /// - a: The summand with larger magnitude.
70
- /// - b: The summand with smaller magnitude.
71
- ///
72
- /// Preconditions:
73
- ///
74
- /// - `large.magnitude` must not be smaller than `small.magnitude`.
75
- /// They may be equal, or one or both may be `NaN`.
76
- /// This precondition is only enforced in debug builds.
72
+ /// > Note:
73
+ /// > `tail` is guaranteed to be the best approximation to the error of
74
+ /// the sum only if `large.magnitude` >= `small.magnitude`. If this is
75
+ /// not the case, then `head` is the correctly rounded sum, but `tail`
76
+ /// is not guaranteed to be the exact error. If you do not know a priori
77
+ /// how the magnitudes of `a` and `b` compare, you likely want to use
78
+ /// ``sum(_:_:)`` instead.
77
79
///
78
80
/// Edge Cases:
79
81
///
@@ -89,29 +91,23 @@ extension Augmented {
89
91
/// ["fastTwoSum"]: https://en.wikipedia.org/wiki/2Sum
90
92
@_transparent
91
93
public static func sum< T: Real > ( large a: T , small b: T ) -> ( head: T , tail: T ) {
92
- assert ( !( b. magnitude > a. magnitude) )
93
94
let head = a + b
94
95
let tail = a - head + b
95
96
return ( head, tail)
96
97
}
97
-
98
+
98
99
/// The sum `a + b` represented as an implicit sum `head + tail`.
99
100
///
100
101
/// `head` is the correctly rounded value of `a + b`. `tail` is the
101
102
/// error from that computation rounded to the closest representable
102
103
/// value.
103
104
///
104
- /// Unlike `Augmented.sum(large: a, small: b)`, the magnitude of the summands
105
- /// does not matter and `a.magnitude` might as well be strictly less than
106
- /// `b.magnitude`. However, it is recommended to only use this function over
107
- /// `Augmented.sum(large: a, small: b)` in cases where the ordering of the
108
- /// summands magnitude is unknown at compile time. In cases where either of
109
- /// the summands magnitude is guaranteed to be greater than or equal the
110
- /// magnitude of the other summand, use `Augmented.sum(large: a, small: b)`
111
- /// over this function; as it faster to calculate.
105
+ /// Unlike ``sum(large:small:)``, the magnitude of the summands does not
106
+ /// matter. If you know statically that `a.magnitude >= b.magnitude`, you
107
+ /// should use ``sum(large:small:)``. If you do not have such a static
108
+ /// bound, you should use this function instead.
112
109
///
113
- /// Unlike `Augmented.product(a, b)`, the rounding error of a sum can
114
- /// never underflow.
110
+ /// Unlike ``product(_:_:)``, the rounding error of a sum never underflows.
115
111
///
116
112
/// This operation is sometimes called ["twoSum"].
117
113
///
@@ -126,7 +122,7 @@ extension Augmented {
126
122
/// interpreted as having any meaning (it may be `NaN` or `infinity`).
127
123
///
128
124
/// Postconditions:
129
- ///
125
+ ///
130
126
/// - If `head` is normal, then `abs(tail) < head.ulp`.
131
127
/// Assuming IEEE 754 default rounding, `abs(tail) <= head.ulp/2`.
132
128
///
0 commit comments