Skip to content

Commit 9411a28

Browse files
committed
Several enhancements of the Complex type. Migrated project to Swift 5.4 and Xcode 12.5
1 parent ab1de90 commit 9411a28

File tree

7 files changed

+71
-21
lines changed

7 files changed

+71
-21
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.4.0 (2021-05-12)
4+
- Several enhancements of the `Complex` type
5+
- Migrated project to Swift 5.4 and Xcode 12.5
6+
37
## 2.3.9 (2020-10-04)
48
- Port to Swift 5.3
59
- Migrated project to Xcode 12.0

NumberKit.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@
481481
buildSettings = {
482482
CLANG_ENABLE_MODULES = YES;
483483
COMBINE_HIDPI_IMAGES = YES;
484-
CURRENT_PROJECT_VERSION = 2;
484+
CURRENT_PROJECT_VERSION = 3;
485485
DEFINES_MODULE = YES;
486486
DYLIB_COMPATIBILITY_VERSION = 1;
487487
DYLIB_CURRENT_VERSION = 1;
@@ -494,7 +494,7 @@
494494
"@executable_path/../Frameworks",
495495
"@loader_path/Frameworks",
496496
);
497-
MARKETING_VERSION = 2.3.9;
497+
MARKETING_VERSION = 2.4.0;
498498
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
499499
PRODUCT_NAME = "$(TARGET_NAME)";
500500
SKIP_INSTALL = YES;
@@ -508,7 +508,7 @@
508508
buildSettings = {
509509
CLANG_ENABLE_MODULES = YES;
510510
COMBINE_HIDPI_IMAGES = YES;
511-
CURRENT_PROJECT_VERSION = 2;
511+
CURRENT_PROJECT_VERSION = 3;
512512
DEFINES_MODULE = YES;
513513
DYLIB_COMPATIBILITY_VERSION = 1;
514514
DYLIB_CURRENT_VERSION = 1;
@@ -521,7 +521,7 @@
521521
"@executable_path/../Frameworks",
522522
"@loader_path/Frameworks",
523523
);
524-
MARKETING_VERSION = 2.3.9;
524+
MARKETING_VERSION = 2.4.0;
525525
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
526526
PRODUCT_NAME = "$(TARGET_NAME)";
527527
SKIP_INSTALL = YES;
@@ -573,7 +573,7 @@
573573
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
574574
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
575575
CODE_SIGN_STYLE = Automatic;
576-
CURRENT_PROJECT_VERSION = 2;
576+
CURRENT_PROJECT_VERSION = 3;
577577
DEFINES_MODULE = YES;
578578
DEVELOPMENT_TEAM = C72Z63N8M5;
579579
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -588,7 +588,7 @@
588588
"@executable_path/Frameworks",
589589
"@loader_path/Frameworks",
590590
);
591-
MARKETING_VERSION = 2.3.9;
591+
MARKETING_VERSION = 2.4.0;
592592
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
593593
MTL_FAST_MATH = YES;
594594
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
@@ -612,7 +612,7 @@
612612
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
613613
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
614614
CODE_SIGN_STYLE = Automatic;
615-
CURRENT_PROJECT_VERSION = 2;
615+
CURRENT_PROJECT_VERSION = 3;
616616
DEFINES_MODULE = YES;
617617
DEVELOPMENT_TEAM = C72Z63N8M5;
618618
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -627,7 +627,7 @@
627627
"@executable_path/Frameworks",
628628
"@loader_path/Frameworks",
629629
);
630-
MARKETING_VERSION = 2.3.9;
630+
MARKETING_VERSION = 2.4.0;
631631
MTL_FAST_MATH = YES;
632632
PRODUCT_BUNDLE_IDENTIFIER = net.objecthub.NumberKit;
633633
PRODUCT_NAME = NumberKit;

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Swift NumberKit
22

3-
[![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)
3+
[![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)
44

55
## Overview
66

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

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

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

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

5555
## Copyright
5656

5757
Author: Matthias Zenger (<[email protected]>)
58-
Copyright © 2016-2020 Matthias Zenger. All rights reserved.
58+
Copyright © 2016-2021 Matthias Zenger. All rights reserved.

Sources/NumberKit iOS/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

Sources/NumberKit/Complex.swift

+50-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,17 @@ public protocol ComplexNumber: Equatable {
5656

5757
/// Returns true if either real or imaginary parts are not a number.
5858
var isNaN: Bool { get }
59-
59+
60+
/// Returns true if both real and imaginary parts are finite.
61+
var isFinite: Bool { get }
62+
6063
/// Returns true if either real or imaginary parts are infinite.
6164
var isInfinite: Bool { get }
62-
65+
66+
/// Returns the ∞-norm of this complex number. Use `norm` if the Euclidean norm
67+
/// is needed.
68+
var magnitude: Float { get }
69+
6370
/// Returns the absolute value of this complex number.
6471
var abs: Float { get }
6572

@@ -126,7 +133,7 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
126133
ExpressibleByIntegerLiteral,
127134
ExpressibleByFloatLiteral,
128135
CustomStringConvertible {
129-
136+
130137
/// The real part of thix complex number.
131138
public let re: T
132139

@@ -203,11 +210,26 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
203210
public var isNaN: Bool {
204211
return re.isNaN || im.isNaN
205212
}
206-
213+
214+
/// Returns true if both real and imaginary parts are finite.
215+
public var isFinite: Bool {
216+
return re.isFinite && im.isFinite
217+
}
218+
207219
/// Returns true if either real or imaginary parts are infinite.
208220
public var isInfinite: Bool {
209221
return re.isInfinite || im.isInfinite
210222
}
223+
224+
/// Returns the ∞-norm of this complex number. Use `norm` if the Euclidean norm
225+
/// is needed.
226+
public var magnitude: T {
227+
if self.isFinite {
228+
return max(self.re.abs, self.im.abs)
229+
} else {
230+
return .infinity
231+
}
232+
}
211233

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

594+
/// This extensions provides access to a few complex constants.
595+
extension Complex {
596+
597+
/// The additive identity for complex numbers.
598+
public static var zero: Complex {
599+
Complex(0, 0)
600+
}
601+
602+
/// The multiplicative identity for complex numbers.
603+
public static var one: Complex {
604+
Complex(1, 0)
605+
}
606+
607+
/// The imaginary unit.
608+
public static var i: Complex {
609+
Complex(0, 1)
610+
}
611+
612+
/// One representation of infinity.
613+
public static var infinity: Complex {
614+
Complex(.infinity, 0)
615+
}
616+
}
617+
572618
/// This extension implements the logic to make `Complex<T>` codable if `T` is codable.
573619
extension Complex: Codable where T: Codable {
574620

Sources/NumberKit/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

Tests/NumberKitTests/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2015–2020 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

0 commit comments

Comments
 (0)