diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9d00e..f22a88f 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/NumberKit.xcodeproj/project.pbxproj b/NumberKit.xcodeproj/project.pbxproj index 1bcb516..aed48a3 100644 --- a/NumberKit.xcodeproj/project.pbxproj +++ b/NumberKit.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/README.md b/README.md index ea00224..9ab8ae2 100644 --- a/README.md +++ b/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 @@ -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 () -Copyright © 2016-2020 Matthias Zenger. All rights reserved. +Copyright © 2016-2021 Matthias Zenger. All rights reserved. diff --git a/Sources/NumberKit iOS/Info.plist b/Sources/NumberKit iOS/Info.plist index f04303e..270ecc6 100644 --- a/Sources/NumberKit iOS/Info.plist +++ b/Sources/NumberKit iOS/Info.plist @@ -19,6 +19,6 @@ CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright - Copyright © 2015–2020 Matthias Zenger. All rights reserved. + Copyright © 2015–2021 Matthias Zenger. All rights reserved. diff --git a/Sources/NumberKit/Complex.swift b/Sources/NumberKit/Complex.swift index 9b602c9..17bba30 100644 --- a/Sources/NumberKit/Complex.swift +++ b/Sources/NumberKit/Complex.swift @@ -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 } @@ -126,7 +133,7 @@ public struct Complex: ComplexNumber, ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral, CustomStringConvertible { - + /// The real part of thix complex number. public let re: T @@ -203,11 +210,26 @@ public struct Complex: 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 { @@ -569,6 +591,30 @@ public func atanh(_ 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` codable if `T` is codable. extension Complex: Codable where T: Codable { diff --git a/Sources/NumberKit/Info.plist b/Sources/NumberKit/Info.plist index f04303e..270ecc6 100644 --- a/Sources/NumberKit/Info.plist +++ b/Sources/NumberKit/Info.plist @@ -19,6 +19,6 @@ CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright - Copyright © 2015–2020 Matthias Zenger. All rights reserved. + Copyright © 2015–2021 Matthias Zenger. All rights reserved. diff --git a/Tests/NumberKitTests/Info.plist b/Tests/NumberKitTests/Info.plist index f04303e..270ecc6 100644 --- a/Tests/NumberKitTests/Info.plist +++ b/Tests/NumberKitTests/Info.plist @@ -19,6 +19,6 @@ CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright - Copyright © 2015–2020 Matthias Zenger. All rights reserved. + Copyright © 2015–2021 Matthias Zenger. All rights reserved.