From 0a96cd370ecf894b1061a32c864f7347d39fcd75 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Thu, 10 Sep 2026 10:30:39 -0400 Subject: [PATCH] Merge pull request #351 from stephentyrone/recip-documentation Relax documented behavior of Complex.reciprocal --- 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..25ce2e6 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 + /// 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`. + /// + /// 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