A lightweight Swift framework providing complex number support with clean syntax, stable math functions, and a Swift-friendly API. Designed for numerical work, graphics, and fractal math on iOS, iPadOS, and macOS.
Complextype with full arithmetic support- Stable magnitude computation using
hypot - Human-readable formatting (
2.00 - 0.50𝒊,𝒊,-𝒊) - Mixed
Double+Complexarithmetic - Immutable and consistent complex rectangles (
ComplexRect) - Fully
@inlinablefor performance-critical code Sendable,Equatable, andHashablesupport
Add MDSComplexNumbers.framework to your Xcode project binaries, then import the module where needed:
import MDSComplexNumbersvar z = Complex() // 0.00
var w = Complex(2.5, -4.5) // 2.50 - 4.50𝒊
z = Complex(1.1, 0.9) // 1.10 + 0.90𝒊
var u = Complex(0, -1) // -𝒊
u = Complex(0, 1) // 𝒊let sum = z + w // 3.60 - 3.60𝒊
let product = z * w // 6.80 - 2.70𝒊
let squared = sqr(z) // 0.40 + 1.98𝒊
print(z - w) // -1.40 + 5.40𝒊
let quotient = z / w // 0.05 + 0.27𝒊
let areEqual = (z == w) // false
let notEqual = (z != w) // truelet m1 = modulus(z) // 1.42126704035519
let m2 = z.magnitude // same as modulus(z)
let m3 = z.modulusSquared // avoids sqrtMagnitude uses hypot(real, imaginary) for improved numerical stability.
let aDouble = Double.pi
print(aDouble * w) // 7.85 - 14.14𝒊
print(aDouble + z) // 4.24 + 0.90𝒊
print(aDouble - w) // 0.64 + 4.50𝒊ComplexRect represents a rectangular region in the complex plane.
Corners are always normalized and internally consistent.
let r = ComplexRect(
Complex(-2.0, 1.0),
Complex(1.0, -1.0)
)
r.topLeft // -2.00 + 1.00𝒊
r.bottomRight // 1.00 - 1.00𝒊
r.bottomLeft // -2.00 - 1.00𝒊
r.topRight // 1.00 + 1.00𝒊
r.width // 3.0
r.height // 2.0An optional MutableComplexRect is also included if mutation is required.
- Division by
0 + 0𝒊triggers a runtime precondition failure. - Formatting is intended for debugging and display, not serialization.
- The API favors correctness, clarity, and performance over cleverness.
© 2018-2026 Michael Stebel Consulting, LLC. All rights reserved.