From bb7b69501f158582c6c02c856c12750c983b1f9e Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Thu, 10 Sep 2026 10:07:01 -0400 Subject: [PATCH 1/2] Relax documented behavior of Complex.reciprocal In cases of underflow, multiplication by reciprocal may not be the same as division. Document this, rather than tightening the behavior, because it's still about as good as multiplication by reciprocal would be for a Real type. --- Sources/ComplexModule/Complex+AlgebraicField.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/ComplexModule/Complex+AlgebraicField.swift b/Sources/ComplexModule/Complex+AlgebraicField.swift index c6f4cb8..88c9604 100644 --- a/Sources/ComplexModule/Complex+AlgebraicField.swift +++ b/Sources/ComplexModule/Complex+AlgebraicField.swift @@ -155,9 +155,17 @@ extension Complex: AlgebraicField { /// /// Error Bounds: /// - /// Unlike real types, when working with complex types, multiplying by the - /// reciprocal instead of dividing cannot change the result. If the - /// reciprocal is non-nil, the two computations are always equivalent. + /// Unlike real types, with Complex types, _if no underflow occurs in + /// computing the reciprocal_, replacing division with multiplication by + /// does not perturb the result. Note that this condition is not the + /// same as `reciprocal` returning a non-nil value. If the `real` and + /// `imaginary` components are poorly scaled with respect to eachother, + /// one component of `reciprocal` may underflow while the other component + /// is normal, resulting in a non-nil `reciprocal`. + /// + /// We return a non-nil reciprocal in this case because it still + /// satisfies the accuracy expectations of `reciprocal` in any Complex + /// norm (but not componentwise). @inlinable public var reciprocal: Complex? { let recip = 1/self From 3b272b08af9a19f0a396af08ec6f90dcbc4241d1 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Thu, 10 Sep 2026 10:09:49 -0400 Subject: [PATCH 2/2] a word. --- Sources/ComplexModule/Complex+AlgebraicField.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ComplexModule/Complex+AlgebraicField.swift b/Sources/ComplexModule/Complex+AlgebraicField.swift index 88c9604..25ce2e6 100644 --- a/Sources/ComplexModule/Complex+AlgebraicField.swift +++ b/Sources/ComplexModule/Complex+AlgebraicField.swift @@ -157,9 +157,9 @@ extension Complex: AlgebraicField { /// /// Unlike real types, with Complex types, _if no underflow occurs in /// computing the reciprocal_, replacing division with multiplication by - /// does not perturb the result. Note that this condition is not the - /// same as `reciprocal` returning a non-nil value. If the `real` and - /// `imaginary` components are poorly scaled with respect to eachother, + /// this value does not perturb the result. Note that this condition is + /// not the same as `reciprocal` returning a non-nil value. If the `real` + /// and `imaginary` components are poorly scaled with respect to each other, /// one component of `reciprocal` may underflow while the other component /// is normal, resulting in a non-nil `reciprocal`. ///