Skip to content

Commit 5827f9a

Browse files
committed
80-column formatting for source doc comments
Tidying, plus a few small edits. This commit should not include any code changes.
1 parent 3cad9b6 commit 5827f9a

File tree

7 files changed

+125
-85
lines changed

7 files changed

+125
-85
lines changed

Sources/ComplexModule/Arithmetic.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ extension Complex: AlgebraicField {
126126

127127
/// A normalized complex number with the same phase as this value.
128128
///
129-
/// If such a value cannot be produced (because the phase of zero and infinity is undefined),
130-
/// `nil` is returned.
129+
/// If such a value cannot be produced (because the phase of zero and
130+
/// infinity is undefined), `nil` is returned.
131131
@inlinable
132132
public var normalized: Complex? {
133133
if length.isNormal {
@@ -139,10 +139,12 @@ extension Complex: AlgebraicField {
139139
return self.divided(by: magnitude).normalized
140140
}
141141

142-
/// The reciprocal of this value, if it can be computed without undue overflow or underflow.
142+
/// The reciprocal of this value, if it can be computed without undue
143+
/// overflow or underflow.
143144
///
144-
/// If z.reciprocal is non-nil, you can safely replace division by z with multiplication by this value. It is
145-
/// not advantageous to do this for an isolated division, but if you are dividing many values by a single
145+
/// If z.reciprocal is non-nil, you can safely replace division by z with
146+
/// multiplication by this value. It is not advantageous to do this for an
147+
/// isolated division, but if you are dividing many values by a single
146148
/// denominator, this will often be a significant performance win.
147149
///
148150
/// Typical use looks like this:

Sources/ComplexModule/Complex.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ extension Complex {
163163

164164
/// True if this value is normal.
165165
///
166-
/// A complex number is normal if it is finite and *either* the real or imaginary component is normal.
167-
/// A floating-point number representing one of the components is normal if its exponent allows a full-
168-
/// precision representation.
166+
/// A complex number is normal if it is finite and *either* the real or
167+
/// imaginary component is normal. A floating-point number representing
168+
/// one of the components is normal if its exponent allows a full-precision
169+
/// representation.
169170
///
170171
/// See also:
171172
/// -
@@ -179,9 +180,10 @@ extension Complex {
179180

180181
/// True if this value is subnormal.
181182
///
182-
/// A complex number is subnormal if it is finite, not normal, and not zero. When the result of a
183-
/// computation is subnormal, underflow has occurred and the result generally does not have full
184-
/// precision.
183+
/// A complex number is subnormal if it is finite, not normal, and not zero.
184+
/// When the result of a computation is subnormal, underflow has occurred and
185+
/// the result generally does not have full precision.
186+
///
185187
/// See also:
186188
/// -
187189
/// - `.isFinite`
@@ -194,7 +196,8 @@ extension Complex {
194196

195197
/// True if this value is zero.
196198
///
197-
/// A complex number is zero if *both* the real and imaginary components are zero.
199+
/// A complex number is zero if *both* the real and imaginary components
200+
/// are zero.
198201
///
199202
/// See also:
200203
/// -
@@ -208,8 +211,8 @@ extension Complex {
208211

209212
/// The ∞-norm of the value (`max(abs(real), abs(imaginary))`).
210213
///
211-
/// If you need the Euclidean norm (a.k.a. 2-norm) use the `length` or `lengthSquared`
212-
/// properties instead.
214+
/// If you need the Euclidean norm (a.k.a. 2-norm) use the `length` or
215+
/// `lengthSquared` properties instead.
213216
///
214217
/// Edge cases:
215218
/// -
@@ -240,8 +243,8 @@ extension Complex {
240243
/// This is mainly useful for interoperation with other languages, where
241244
/// you may want to reduce each equivalence class to a single representative
242245
/// before passing across language boundaries, but it may also be useful
243-
/// for some serialization tasks. It's also a useful implementation detail for
244-
/// some primitive operations.
246+
/// for some serialization tasks. It's also a useful implementation detail
247+
/// for some primitive operations.
245248
@_transparent
246249
public var canonicalized: Self {
247250
if isZero { return .zero }
@@ -491,7 +494,8 @@ extension Complex {
491494
///
492495
/// Edge cases:
493496
/// -
494-
/// - Negative lengths are interpreted as reflecting the point through the origin, i.e.:
497+
/// - Negative lengths are interpreted as reflecting the point through the
498+
/// origin, i.e.:
495499
/// ```
496500
/// Complex(length: -r, phase: θ) == -Complex(length: r, phase: θ)
497501
/// ```

Sources/ComplexModule/ElementaryFunctions.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ extension Complex: ElementaryFunctions {
3939

4040
// MARK: - exp-like functions
4141

42-
/// The complex exponential function e^z whose base `e` is the base of the natural logarithm.
42+
/// The complex exponential function e^z whose base `e` is the base of the
43+
/// natural logarithm.
4344
///
44-
/// Mathematically, this operation can be expanded in terms of the `Real` operations `exp`,
45-
/// `cos` and `sin` as follows:
45+
/// Mathematically, this operation can be expanded in terms of the `Real`
46+
/// operations `exp`, `cos` and `sin` as follows:
4647
/// ```
4748
/// exp(x + iy) = exp(x) exp(iy)
4849
/// = exp(x) cos(y) + i exp(x) sin(y)
4950
/// ```
50-
/// Note that naive evaluation of this expression in floating-point would be prone to premature
51-
/// overflow, since `cos` and `sin` both have magnitude less than 1 for most inputs (i.e.
52-
/// `exp(x)` may be infinity when `exp(x) cos(y)` would not be.
51+
/// Note that naive evaluation of this expression in floating-point would be
52+
/// prone to premature overflow, since `cos` and `sin` both have magnitude
53+
/// less than 1 for most inputs (i.e. `exp(x)` may be infinity when
54+
/// `exp(x) cos(y)` would not be).
5355
@inlinable
5456
public static func exp(_ z: Complex) -> Complex {
5557
guard z.isFinite else { return z }

Sources/RealModule/ApproximateEquality.swift

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ extension Numeric where Magnitude: FloatingPoint {
2222
/// ```
2323
///
2424
/// The default value of `relativeTolerance` is `.ulpOfOne.squareRoot()`,
25-
/// which corresponds to expecting "about half the digits" in the computed results to be good.
26-
/// This is the usual guidance in numerical analysis, if you don't know anything about the
27-
/// computation being performed, but is not suitable for all use cases.
25+
/// which corresponds to expecting "about half the digits" in the computed
26+
/// results to be good. This is the usual guidance in numerical analysis,
27+
/// if you don't know anything about the computation being performed, but
28+
/// is not suitable for all use cases.
2829
///
2930
/// Mathematical Properties:
3031
/// ------------------------
@@ -34,16 +35,21 @@ extension Numeric where Magnitude: FloatingPoint {
3435
///
3536
/// - `isApproximatelyEqual(to:relativeTolerance:norm:)` is _symmetric_.
3637
///
37-
/// - `isApproximatelyEqual(to:relativeTolerance:norm:)` is __not__ _transitive_.
38-
/// Because of this, approximately equality is __not an equivalence relation__,
39-
/// even when restricted to non-exceptional values.
38+
/// - `isApproximatelyEqual(to:relativeTolerance:norm:)` is __not__
39+
/// _transitive_. Because of this, approximately equality is __not an
40+
/// equivalence relation__, even when restricted to non-exceptional values.
4041
///
41-
/// - For any point `a`, the set of values that compare approximately equal to `a` is _convex_.
42-
/// (Under the assumption that the `.magnitude` property implements a valid norm.)
42+
/// This means that you must not use approximate equality to implement
43+
/// a conformance to Equatable, as it will violate the invariants of
44+
/// code written against that protocol.
45+
///
46+
/// - For any point `a`, the set of values that compare approximately equal
47+
/// to `a` is _convex_. (Under the assumption that the `.magnitude`
48+
/// property implements a valid norm.)
4349
///
4450
/// - `isApproximatelyEqual(to:relativeTolerance:norm:)` is _scale invariant_,
45-
/// so long as no underflow or overflow has occured, and no exceptional value is produced
46-
/// by the scaling.
51+
/// so long as no underflow or overflow has occured, and no exceptional
52+
/// value is produced by the scaling.
4753
///
4854
/// See Also:
4955
/// -------
@@ -57,8 +63,9 @@ extension Numeric where Magnitude: FloatingPoint {
5763
/// Defaults to `.ulpOfOne.squareRoot()`.
5864
///
5965
/// This value should be non-negative and less than or equal to 1.
60-
/// This constraint on is only checked in debug builds, because a mathematically
61-
/// well-defined result exists for any tolerance, even one out of range.
66+
/// This constraint on is only checked in debug builds, because a
67+
/// mathematically well-defined result exists for any tolerance,
68+
/// even one out of range.
6269
///
6370
/// - norm: The [norm] to use for the comparison.
6471
/// Defaults to `\.magnitude`.
@@ -99,13 +106,17 @@ extension Numeric where Magnitude: FloatingPoint {
99106
/// - `isApproximatelyEqual(to:absoluteTolerance:relativeTolerance:)`
100107
/// is _symmetric_.
101108
///
102-
/// - `isApproximatelyEqual(to:absoluteTolerance:relativeTolerance:)`
103-
/// is __not__ _transitive_. Because of this, approximately equality is
104-
/// __not an equivalence relation__, even when restricted to non-exceptional values.
109+
/// - `isApproximatelyEqual(to:relativeTolerance:norm:)` is __not__
110+
/// _transitive_. Because of this, approximately equality is __not an
111+
/// equivalence relation__, even when restricted to non-exceptional values.
105112
///
106-
/// - For any point `a`, the set of values that compare approximately equal to `a` is _convex_.
107-
/// (Under the assumption that `norm` implements a valid norm, which cannot be checked
108-
/// by this function.)
113+
/// This means that you must not use approximate equality to implement
114+
/// a conformance to Equatable, as it will violate the invariants of
115+
/// code written against that protocol.
116+
///
117+
/// - For any point `a`, the set of values that compare approximately equal
118+
/// to `a` is _convex_. (Under the assumption that `norm` implements a
119+
/// valid norm, which cannot be checked by this function.)
109120
///
110121
/// See Also:
111122
/// -------
@@ -118,15 +129,17 @@ extension Numeric where Magnitude: FloatingPoint {
118129
/// - absoluteTolerance: The absolute tolerance to use in the comparison.
119130
///
120131
/// This value should be non-negative and finite.
121-
/// This constraint on is only checked in debug builds, because a mathematically
122-
/// well-defined result exists for any tolerance, even one out of range.
132+
/// This constraint on is only checked in debug builds, because a
133+
/// mathematically well-defined result exists for any tolerance,
134+
/// even one out of range.
123135
///
124136
/// - relativeTolerance: The relative tolerance to use in the comparison.
125137
/// Defaults to zero.
126138
///
127139
/// This value should be non-negative and less than or equal to 1.
128-
/// This constraint on is only checked in debug builds, because a mathematically
129-
/// well-defined result exists for any tolerance, even one out of range.
140+
/// This constraint on is only checked in debug builds, because a
141+
/// mathematically well-defined result exists for any tolerance,
142+
/// even one out of range.
130143
@inlinable @inline(__always)
131144
public func isApproximatelyEqual(
132145
to other: Self,
@@ -143,7 +156,8 @@ extension Numeric where Magnitude: FloatingPoint {
143156
}
144157

145158
extension AdditiveArithmetic {
146-
/// Test if `self` and `other` are approximately equal with specified tolerances and norm.
159+
/// Test if `self` and `other` are approximately equal with specified
160+
/// tolerances and norm.
147161
///
148162
/// `true` if `self` and `other` are equal, or if they are finite and either
149163
/// ```
@@ -166,11 +180,16 @@ extension AdditiveArithmetic {
166180
///
167181
/// - `isApproximatelyEqual(to:absoluteTolerance:relativeTolerance:norm:)`
168182
/// is __not__ _transitive_. Because of this, approximately equality is
169-
/// __not an equivalence relation__, even when restricted to non-exceptional values.
183+
/// __not an equivalence relation__, even when restricted to
184+
/// non-exceptional values.
185+
///
186+
/// This means that you must not use approximate equality to implement
187+
/// a conformance to Equatable, as it will violate the invariants of
188+
/// code written against that protocol.
170189
///
171-
/// - For any point `a`, the set of values that compare approximately equal to `a` is _convex_.
172-
/// (Under the assumption that `norm` implements a valid norm, which cannot be checked
173-
/// by this function.)
190+
/// - For any point `a`, the set of values that compare approximately equal
191+
/// to `a` is _convex_ (under the assumption that `norm` implements a
192+
/// valid norm, which cannot be checked by this function or a protocol).
174193
///
175194
/// See Also:
176195
/// -------
@@ -184,30 +203,32 @@ extension AdditiveArithmetic {
184203
/// - absoluteTolerance: The absolute tolerance to use in the comparison.
185204
///
186205
/// This value should be non-negative and finite.
187-
/// This constraint on is only checked in debug builds, because a mathematically
188-
/// well-defined result exists for any tolerance, even one out of range.
206+
/// This constraint on is only checked in debug builds, because a
207+
/// mathematically well-defined result exists for any tolerance, even
208+
/// one out of range.
189209
///
190210
/// - relativeTolerance: The relative tolerance to use in the comparison.
191211
/// Defaults to zero.
192212
///
193213
/// This value should be non-negative and less than or equal to 1.
194-
/// This constraint on is only checked in debug builds, because a mathematically
195-
/// well-defined result exists for any tolerance, even one out of range.
214+
/// This constraint on is only checked in debug builds, because a
215+
/// mathematically well-defined result exists for any tolerance,
216+
/// even one out of range.
196217
///
197218
/// - norm: The norm to use for the comparison.
198219
/// Defaults to `\.magnitude`.
199220
///
200-
/// For example, if we wanted to test if a complex value was inside a circle of
201-
/// radius 0.001 centered at (1 + 0i), we could use:
221+
/// For example, if we wanted to test if a complex value was inside a
222+
/// circle of radius 0.001 centered at (1 + 0i), we could use:
202223
/// ```
203224
/// z.isApproximatelyEqual(
204225
/// to: 1,
205226
/// absoluteTolerance: 0.001,
206227
/// norm: \.length
207228
/// )
208229
/// ```
209-
/// (if we used the default, we would be testing if `z` were inside a square region
210-
/// instead.)
230+
/// (if we used the default norm, `.magnitude`, we would be testing if
231+
/// `z` were inside a square region instead.)
211232
@inlinable
212233
public func isApproximatelyEqual<Magnitude>(
213234
to other: Self,

Sources/RealModule/ElementaryFunctions.swift

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@
2424
/// let y = Float.sin(x) // 0.84147096
2525
/// ```
2626
///
27-
/// There are three broad families of functions defined by `ElementaryFunctions`:
27+
/// There are three broad families of functions defined by
28+
/// `ElementaryFunctions`:
2829
/// - Exponential, trigonometric, and hyperbolic functions:
2930
/// `exp`, `expMinusOne`, `cos`, `sin`, `tan`, `cosh`, `sinh`, and `tanh`.
3031
/// - Logarithmic, inverse trigonometric, and inverse hyperbolic functions:
31-
/// `log`, `log(onePlus:)`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and `atanh`.
32+
/// `log`, `log(onePlus:)`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and
33+
/// `atanh`.
3234
/// - Power and root functions:
3335
/// `pow`, `sqrt`, and `root`.
3436
///
3537
/// `ElementaryFunctions` conformance implies `AdditiveArithmetic`, so addition
3638
/// and subtraction and the `.zero` property are also available.
3739
///
38-
/// There are two other protocols that you are more likely to want to use directly:
40+
/// There are two other protocols that you are more likely to want to use
41+
/// directly:
3942
///
4043
/// `RealFunctions` refines `ElementaryFunctions` and includes
4144
/// additional functions specific to real number types.
@@ -50,7 +53,8 @@
5053
///
5154
/// [elfn]: http://en.wikipedia.org/wiki/Elementary_function
5255
public protocol ElementaryFunctions: AdditiveArithmetic {
53-
/// The [exponential function][wiki] e^x whose base `e` is the base of the natural logarithm.
56+
/// The [exponential function][wiki] e^x whose base `e` is the base of the
57+
/// natural logarithm.
5458
///
5559
/// See also:
5660
/// -
@@ -63,19 +67,20 @@ public protocol ElementaryFunctions: AdditiveArithmetic {
6367

6468
/// exp(x) - 1, computed in such a way as to maintain accuracy for small x.
6569
///
66-
/// When `x` is close to zero, the expression `.exp(x) - 1` suffers from catastrophic
67-
/// cancellation and the result will not have full accuracy. The `.expMinusOne(x)` function gives
68-
/// you a means to address this problem.
70+
/// When `x` is close to zero, the expression `.exp(x) - 1` suffers from
71+
/// catastrophic cancellation and the result will not have full accuracy.
72+
/// The `.expMinusOne(x)` function gives you a means to address this problem.
6973
///
70-
/// As an example, consider the expression `(x + 1)*exp(x) - 1`. When `x` is smaller
71-
/// than `.ulpOfOne`, this expression evaluates to `0.0`, when it should actually round to
72-
/// `2*x`. We can get a full-accuracy result by using the following instead:
74+
/// As an example, consider the expression `(x + 1)*exp(x) - 1`. When `x`
75+
/// is smaller than `.ulpOfOne`, this expression evaluates to `0.0`, when it
76+
/// should actually round to `2*x`. We can get a full-accuracy result by
77+
/// using the following instead:
7378
/// ```
7479
/// let t = .expMinusOne(x)
7580
/// return x*(t+1) + t // x*exp(x) + (exp(x)-1) = (x+1)*exp(x) - 1
7681
/// ```
77-
/// This re-written expression delivers an accurate result for all values of `x`, not just for
78-
/// small values.
82+
/// This re-written expression delivers an accurate result for all values
83+
/// of `x`, not just for small values.
7984
///
8085
/// See also:
8186
/// -
@@ -238,7 +243,8 @@ public protocol ElementaryFunctions: AdditiveArithmetic {
238243

239244
/// The [arccosine][wiki] (inverse cosine) of `x`.
240245
///
241-
/// For real types, the result may be interpreted as an angle measured in radians.
246+
/// For real types, the result may be interpreted as an angle measured in
247+
/// radians.
242248
/// ```
243249
/// cos(acos(x)) ≅ x
244250
/// ```
@@ -253,7 +259,8 @@ public protocol ElementaryFunctions: AdditiveArithmetic {
253259

254260
/// The [arcsine][wiki] (inverse sine) of `x`.
255261
///
256-
/// For real types, the result may be interpreted as an angle measured in radians.
262+
/// For real types, the result may be interpreted as an angle measured in
263+
/// radians.
257264
/// ```
258265
/// sin(asin(x)) ≅ x
259266
/// ```
@@ -268,7 +275,8 @@ public protocol ElementaryFunctions: AdditiveArithmetic {
268275

269276
/// The [arctangent][wiki] (inverse tangent) of `x`.
270277
///
271-
/// For real types, the result may be interpreted as an angle measured in radians.
278+
/// For real types, the result may be interpreted as an angle measured in
279+
/// radians.
272280
/// ```
273281
/// tan(atan(x)) ≅ x
274282
/// ```

0 commit comments

Comments
 (0)