Skip to content

Commit

Permalink
Several enhancements of the Complex type. Migrated project to Swift…
Browse files Browse the repository at this point in the history
… 5.4 and Xcode 12.5
  • Loading branch information
objecthub committed May 12, 2021
1 parent ab1de90 commit 9411a28
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 2.4.0 (2021-05-12)
- Several enhancements of the `Complex` type
- Migrated project to Swift 5.4 and Xcode 12.5

## 2.3.9 (2020-10-04)
- Port to Swift 5.3
- Migrated project to Xcode 12.0
Expand Down
16 changes: 8 additions & 8 deletions NumberKit.xcodeproj/project.pbxproj
Expand Up @@ -481,7 +481,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -494,7 +494,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.3.9;
MARKETING_VERSION = 2.4.0;
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -508,7 +508,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -521,7 +521,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.3.9;
MARKETING_VERSION = 2.4.0;
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -573,7 +573,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = C72Z63N8M5;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -588,7 +588,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.3.9;
MARKETING_VERSION = 2.4.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
Expand All @@ -612,7 +612,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = C72Z63N8M5;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -627,7 +627,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.3.9;
MARKETING_VERSION = 2.4.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
PRODUCT_NAME = NumberKit;
Expand Down
12 changes: 6 additions & 6 deletions README.md
@@ -1,11 +1,11 @@
# Swift NumberKit

[![Platforms: macOS, iOS, Linux](https://img.shields.io/badge/Platforms-macOS,%20iOS,%20Linux-blue.svg?style=flat)](https://developer.apple.com/osx/) [![Language: Swift 5.3](https://img.shields.io/badge/Language-Swift%205.3-green.svg?style=flat)](https://developer.apple.com/swift/) [![IDE: Xcode 12.0](https://img.shields.io/badge/IDE-Xcode%2012.0-orange.svg?style=flat)](https://developer.apple.com/xcode/) [![Package managers: SwiftPM, Carthage](https://img.shields.io/badge/Package%20managers-SwiftPM,%20Carthage-8E64B0.svg?style=flat)](https://github.com/Carthage/Carthage) [![License: Apache](http://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat)](https://raw.githubusercontent.com/objecthub/swift-numberkit/master/LICENSE)
[![Platforms: macOS, iOS, Linux](https://img.shields.io/badge/Platforms-macOS,%20iOS,%20Linux-blue.svg?style=flat)](https://developer.apple.com/osx/) [![Language: Swift 5.4](https://img.shields.io/badge/Language-Swift%205.4-green.svg?style=flat)](https://developer.apple.com/swift/) [![IDE: Xcode 12.5](https://img.shields.io/badge/IDE-Xcode%2012.5-orange.svg?style=flat)](https://developer.apple.com/xcode/) [![Package managers: SwiftPM, Carthage](https://img.shields.io/badge/Package%20managers-SwiftPM,%20Carthage-8E64B0.svg?style=flat)](https://github.com/Carthage/Carthage) [![License: Apache](http://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat)](https://raw.githubusercontent.com/objecthub/swift-numberkit/master/LICENSE)

## Overview

This is a framework implementing advanced numeric data types for the Swift programming
language on macOS and iOS. Currently, the framework provides three new numeric types,
language on macOS, iOS and Linux. Currently, the framework provides three new numeric types,
each represented as a struct:

1. `BigInt`: arbitrary-precision signed integers
Expand Down Expand Up @@ -47,12 +47,12 @@ where _i_ is the _imaginary unit_.

The following technologies are needed to build the components of the _Swift NumberKit_ framework:

- [Xcode 12.0](https://developer.apple.com/xcode/)
- [Swift 5.3](https://developer.apple.com/swift/)
- [Xcode 12.5](https://developer.apple.com/xcode/)
- [Swift 5.4](https://developer.apple.com/swift/)
- [Swift Package Manager](https://swift.org/package-manager/)
- macOS or Linux
- macOS, iOS or Linux

## Copyright

Author: Matthias Zenger (<matthias@objecthub.net>)
Copyright © 2016-2020 Matthias Zenger. All rights reserved.
Copyright © 2016-2021 Matthias Zenger. All rights reserved.
2 changes: 1 addition & 1 deletion Sources/NumberKit iOS/Info.plist
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>
54 changes: 50 additions & 4 deletions Sources/NumberKit/Complex.swift
Expand Up @@ -56,10 +56,17 @@ public protocol ComplexNumber: Equatable {

/// Returns true if either real or imaginary parts are not a number.
var isNaN: Bool { get }


/// Returns true if both real and imaginary parts are finite.
var isFinite: Bool { get }

/// Returns true if either real or imaginary parts are infinite.
var isInfinite: Bool { get }


/// Returns the ∞-norm of this complex number. Use `norm` if the Euclidean norm
/// is needed.
var magnitude: Float { get }

/// Returns the absolute value of this complex number.
var abs: Float { get }

Expand Down Expand Up @@ -126,7 +133,7 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
ExpressibleByIntegerLiteral,
ExpressibleByFloatLiteral,
CustomStringConvertible {

/// The real part of thix complex number.
public let re: T

Expand Down Expand Up @@ -203,11 +210,26 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
public var isNaN: Bool {
return re.isNaN || im.isNaN
}


/// Returns true if both real and imaginary parts are finite.
public var isFinite: Bool {
return re.isFinite && im.isFinite
}

/// Returns true if either real or imaginary parts are infinite.
public var isInfinite: Bool {
return re.isInfinite || im.isInfinite
}

/// Returns the ∞-norm of this complex number. Use `norm` if the Euclidean norm
/// is needed.
public var magnitude: T {
if self.isFinite {
return max(self.re.abs, self.im.abs)
} else {
return .infinity
}
}

/// Returns the absolute value of this complex number.
public var abs: T {
Expand Down Expand Up @@ -569,6 +591,30 @@ public func atanh<C: ComplexNumber>(_ z: C) -> C {
return log(x.divided(by: y)).divided(by: C.Float(2))
}

/// This extensions provides access to a few complex constants.
extension Complex {

/// The additive identity for complex numbers.
public static var zero: Complex {
Complex(0, 0)
}

/// The multiplicative identity for complex numbers.
public static var one: Complex {
Complex(1, 0)
}

/// The imaginary unit.
public static var i: Complex {
Complex(0, 1)
}

/// One representation of infinity.
public static var infinity: Complex {
Complex(.infinity, 0)
}
}

/// This extension implements the logic to make `Complex<T>` codable if `T` is codable.
extension Complex: Codable where T: Codable {

Expand Down
2 changes: 1 addition & 1 deletion Sources/NumberKit/Info.plist
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Tests/NumberKitTests/Info.plist
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>

0 comments on commit 9411a28

Please sign in to comment.