From 221387985aea3fb0d02fdd1c6f5f0aa907122e32 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Tue, 12 Aug 2025 15:04:11 -0400 Subject: [PATCH] Further review edits from Nate. --- .../Complex+AdditiveArithmetic.swift | 4 ++-- .../Complex+AlgebraicField.swift | 4 +++- Sources/ComplexModule/Complex+Codable.swift | 2 +- .../Complex+ElementaryFunctions.swift | 2 +- Sources/ComplexModule/Complex+Hashable.swift | 2 +- .../Complex+IntegerLiteral.swift | 2 +- Sources/ComplexModule/Complex+Numeric.swift | 8 +++---- .../Complex+StringConvertible.swift | 2 +- Sources/ComplexModule/Complex.swift | 21 ++++++++---------- Sources/ComplexModule/Polar.swift | 22 +++++++++---------- Sources/ComplexModule/Scale.swift | 5 ++--- 11 files changed, 34 insertions(+), 40 deletions(-) diff --git a/Sources/ComplexModule/Complex+AdditiveArithmetic.swift b/Sources/ComplexModule/Complex+AdditiveArithmetic.swift index 58f59fe..0806fb4 100644 --- a/Sources/ComplexModule/Complex+AdditiveArithmetic.swift +++ b/Sources/ComplexModule/Complex+AdditiveArithmetic.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019-2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -14,7 +14,7 @@ import RealModule extension Complex: AdditiveArithmetic { /// The additive identity, with real and imaginary parts both zero. /// - /// See also: `one`, `i`, `infinity` + /// See also: ``one``, ``i``, ``infinity`` @_transparent public static var zero: Complex { Complex(0, 0) diff --git a/Sources/ComplexModule/Complex+AlgebraicField.swift b/Sources/ComplexModule/Complex+AlgebraicField.swift index 42e847a..c6f4cb8 100644 --- a/Sources/ComplexModule/Complex+AlgebraicField.swift +++ b/Sources/ComplexModule/Complex+AlgebraicField.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019-2024 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -13,6 +13,8 @@ import RealModule extension Complex: AlgebraicField { /// The multiplicative identity `1 + 0i`. + /// + /// See also: ``zero``, ``i``, ``infinity`` @_transparent public static var one: Complex { Complex(1, 0) diff --git a/Sources/ComplexModule/Complex+Codable.swift b/Sources/ComplexModule/Complex+Codable.swift index 9be3e7d..f7f094f 100644 --- a/Sources/ComplexModule/Complex+Codable.swift +++ b/Sources/ComplexModule/Complex+Codable.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information diff --git a/Sources/ComplexModule/Complex+ElementaryFunctions.swift b/Sources/ComplexModule/Complex+ElementaryFunctions.swift index 049dad0..38c8cdc 100644 --- a/Sources/ComplexModule/Complex+ElementaryFunctions.swift +++ b/Sources/ComplexModule/Complex+ElementaryFunctions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019-2020 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information diff --git a/Sources/ComplexModule/Complex+Hashable.swift b/Sources/ComplexModule/Complex+Hashable.swift index f2daf56..91e4361 100644 --- a/Sources/ComplexModule/Complex+Hashable.swift +++ b/Sources/ComplexModule/Complex+Hashable.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information diff --git a/Sources/ComplexModule/Complex+IntegerLiteral.swift b/Sources/ComplexModule/Complex+IntegerLiteral.swift index fadb8fc..07126fc 100644 --- a/Sources/ComplexModule/Complex+IntegerLiteral.swift +++ b/Sources/ComplexModule/Complex+IntegerLiteral.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information diff --git a/Sources/ComplexModule/Complex+Numeric.swift b/Sources/ComplexModule/Complex+Numeric.swift index 874742f..5a5d9fb 100644 --- a/Sources/ComplexModule/Complex+Numeric.swift +++ b/Sources/ComplexModule/Complex+Numeric.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -43,16 +43,14 @@ extension Complex: Numeric { /// Equal to `max(abs(real), abs(imaginary))`. /// /// If you need to work with the Euclidean norm (a.k.a. 2-norm) instead, - /// use the `length` or `lengthSquared` properties. If you just need to - /// know "how big" a number is, use this property. + /// use the ``length`` or ``lengthSquared`` properties. If you just need + /// to know "how big" a number is, use this property. /// /// **Edge cases:** /// /// - If `z` is not finite, `z.magnitude` is infinity. /// - If `z` is zero, `z.magnitude` is zero. /// - Otherwise, `z.magnitude` is finite and non-zero. - /// - /// See also `.length` and `.lengthSquared`. @_transparent public var magnitude: RealType { guard isFinite else { return .infinity } diff --git a/Sources/ComplexModule/Complex+StringConvertible.swift b/Sources/ComplexModule/Complex+StringConvertible.swift index d1a26f0..85e7f78 100644 --- a/Sources/ComplexModule/Complex+StringConvertible.swift +++ b/Sources/ComplexModule/Complex+StringConvertible.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information diff --git a/Sources/ComplexModule/Complex.swift b/Sources/ComplexModule/Complex.swift index ad9ed2b..5929a7e 100644 --- a/Sources/ComplexModule/Complex.swift +++ b/Sources/ComplexModule/Complex.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -11,11 +11,8 @@ import RealModule -/// A [complex number](https://en.wikipedia.org/wiki/Complex_number). -/// -/// `Complex` is an `AlgebraicField`, so it has all the normal arithmetic -/// operators. It conforms to `ElementaryFunctions`, so it has all the usual -/// math functions. +// A [complex number](https://en.wikipedia.org/wiki/Complex_number). +// See Documentation.docc/Complex.md for more details. @frozen public struct Complex where RealType: Real { // A note on the `x` and `y` properties @@ -92,7 +89,7 @@ extension Complex { extension Complex { /// The imaginary unit. /// - /// See also `.zero`, `.one` and `.infinity`. + /// See also ``zero``, ``one`` and ``infinity``. @_transparent public static var i: Complex { Complex(0, 1) @@ -100,7 +97,7 @@ extension Complex { /// The point at infinity. /// - /// See also `.zero`, `.one` and `.i`. + /// See also ``zero``, ``one`` and ``i``. @_transparent public static var infinity: Complex { Complex(.infinity, 0) @@ -110,7 +107,7 @@ extension Complex { /// /// A complex value is finite if neither component is an infinity or nan. /// - /// See also `.isNormal`, `.isSubnormal` and `.isZero`. + /// See also ``isNormal``, ``isSubnormal`` and ``isZero``. @_transparent public var isFinite: Bool { x.isFinite && y.isFinite @@ -123,7 +120,7 @@ extension Complex { /// one of the components is normal if its exponent allows a full-precision /// representation. /// - /// See also `.isFinite`, `.isSubnormal` and `.isZero`. + /// See also ``isFinite``, ``isSubnormal`` and ``isZero``. @_transparent public var isNormal: Bool { isFinite && (x.isNormal || y.isNormal) @@ -135,7 +132,7 @@ extension Complex { /// When the result of a computation is subnormal, underflow has occurred and /// the result generally does not have full precision. /// - /// See also `.isFinite`, `.isNormal` and `.isZero`. + /// See also ``isFinite``, ``isNormal`` and ``isZero``. @_transparent public var isSubnormal: Bool { isFinite && !isNormal && !isZero @@ -146,7 +143,7 @@ extension Complex { /// A complex number is zero if *both* the real and imaginary components /// are zero. /// - /// See also `.isFinite`, `.isNormal` and `isSubnormal`. + /// See also ``isFinite``, ``isNormal`` and ``isSubnormal``. @_transparent public var isZero: Bool { x == 0 && y == 0 diff --git a/Sources/ComplexModule/Polar.swift b/Sources/ComplexModule/Polar.swift index 3a7587a..e5dabaa 100644 --- a/Sources/ComplexModule/Polar.swift +++ b/Sources/ComplexModule/Polar.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -26,15 +26,15 @@ extension Complex { /// because the length can be as much as sqrt(2) times larger than /// either component, and thus may not be representable in the real type. /// - /// For most use cases, you can use the cheaper `.magnitude` + /// For most use cases, you can use the cheaper ``magnitude`` /// property (which computes the ∞-norm) instead, which always produces /// a representable result. See for more details. /// /// Edge cases: - /// - If a complex value is not finite, its `.length` is `infinity`. + /// - If a complex value is not finite, its `length` is `infinity`. /// - /// See also `.magnitude`, `.lengthSquared`, `.phase`, `.polar` - /// and `init(r:θ:)`. + /// See also ``lengthSquared``, ``phase``, ``polar`` + /// and ``init(length:phase:)``. @_transparent public var length: RealType { let naive = lengthSquared @@ -42,7 +42,7 @@ extension Complex { return .sqrt(naive) } - // Internal implementation detail of `length`, moving slow path off + // Internal implementation detail of ``length``, moving slow path off // of the inline function. Note that even `carefulLength` can overflow // for finite inputs, but only when the result is outside the range // of representable values. @@ -54,21 +54,19 @@ extension Complex { /// The squared length `(real*real + imaginary*imaginary)`. /// - /// This property is more efficient to compute than `length`, but is + /// This property is more efficient to compute than ``length``, but is /// highly prone to overflow or underflow; for finite values that are /// not well-scaled, `lengthSquared` is often either zero or /// infinity, even when `length` is a finite number. Use this property /// only when you are certain that this value is well-scaled. /// - /// For many cases, `.magnitude` can be used instead, which is similarly + /// For many cases, ``magnitude`` can be used instead, which is similarly /// cheap to compute and always returns a representable value. /// /// Note that because of how `lengthSquared` is used, it is a primary /// design goal that it be as fast as possible. Therefore, it does not /// normalize infinities, and may return either `.infinity` or `.nan` /// for non-finite values. - /// - /// See also ``length`` and ``magnitude``. @_transparent public var lengthSquared: RealType { x*x + y*y @@ -93,7 +91,7 @@ extension Complex { /// - If the complex value is zero or non-finite, phase is `.nan`. /// - If the complex value is non-finite, length is `.infinity`. /// - /// See also: `.length`, `.phase` and `init(r:θ:)`. + /// See also: ``length``, ``phase`` and ``init(length:phase:)``. public var polar: (length: RealType, phase: RealType) { (length, phase) } @@ -116,7 +114,7 @@ extension Complex { /// ``` /// - Otherwise, `θ` must be finite, or a precondition failure occurs. /// - /// See also `.length`, `.phase` and `.polar`. + /// See also ``length``, ``phase`` and ``polar``. @inlinable public init(length: RealType, phase: RealType) { if phase.isFinite { diff --git a/Sources/ComplexModule/Scale.swift b/Sources/ComplexModule/Scale.swift index b7ac778..df50d57 100644 --- a/Sources/ComplexModule/Scale.swift +++ b/Sources/ComplexModule/Scale.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Numerics open source project // -// Copyright (c) 2019-2021 Apple Inc. and the Swift Numerics project authors +// Copyright (c) 2019-2025 Apple Inc. and the Swift Numerics project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -33,10 +33,9 @@ extension Complex { /// `self` divided by the real value `a`. /// /// More efficient than `self / Complex(a)`. May not produce exactly the - /// same result, but will always be more accurate when they differ. + /// same result, but will always be more accurate if they differ. @inlinable @inline(__always) public func divided(by a: RealType) -> Complex { - // See implementation notes for `multiplied` above. Complex(x/a, y/a) } }