Swiftpack.co - Package - SomeRandomiOSDev/Complex


License MIT CocoaPods Compatible Carthage Compatible Platform Linux Build Swift Code Coverage Codacy

Complex is a lightweight framework designed for representing and working with complex numbers for iOS, macOS, tvOS, and watchOS.


Complex is available through CocoaPods, Carthage and the Swift Package Manager.

To install via CocoaPods, simply add the following line to your Podfile:

pod 'Complex'

To install via Carthage, simply add the following line to your Cartfile:

github "SomeRandomiOSDev/Complex"

To install via the Swift Package Manager add the following line to your Package.swift file's dependencies:

.package(url: "https://github.com/SomeRandomiOSDev/Complex.git", from: "1.0.0")


First import Complex at the top of your Swift file:

import Complex

After importing, use of complex numbers is as simple as can be:

let input = Complex<Double>(real: 4.31, imaginary: 2.0)
let scale = Complex<Double>(real: 1.5, imaginary: 2.718)

let output = input * scale


The Complex type also has builtin functionality specific to complex numbers, such as conjugates and modulus/angle (for converting to polar coordinates):

let complex = Complex<Double>(real: 7.0, imaginary: -4.1)

// Equal to 7.0 + 4.1i
let conjugate = ~complex // or complex.conjugate()

let (modulus, angle) = (complex.modulus, complex.angle)



If you have need for a specific feature or you encounter a bug, please open an issue. If you extend the functionality of Complex yourself or you feel like fixing a bug yourself, please submit a pull request.


Joseph Newton, somerandomiosdev@gmail.com


Complex is available under the MIT license. See the LICENSE file for more info.


Stars: 12


Used By

Total: 0


1.0.0 - 2020-02-24 14:21:54

Initial release

1.1.1 - 2020-02-24 14:21:40

  • Hotfix for a build error due to unavailability of Float80 type

1.1.0 - 2020-02-24 14:21:01

  • Reduced scalar type requirements on Complex from BinaryFloatingPoint to Numeric
  • Added additional primitive mathematical functions for Complex numbers (sin, cos, etc.)
  • Added component-wise arithmetic operators
  • Added arithmetic operators for ignoring overflow when working with FixedWidthInteger types
  • Added functions for multiplication and division that report their result using additional bit width and also those that report overflow.