Skip to content

Commit 0f9c918

Browse files
committed
Support random number generation for Complex. Migrate project to Swift 5.7 and Xcode 14.
1 parent 09602a1 commit 0f9c918

File tree

12 files changed

+42
-21
lines changed

12 files changed

+42
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.4.2 (2023-01-01)
4+
- Support random number generation for Complex
5+
- Migrated project to Swift 5.7 and Xcode 14
6+
37
## 2.4.1 (2022-01-04)
48
- Support random number generation for BigInt
59
- Migrated project to Swift 5.5 and Xcode 13.2

NumberKit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
isa = PBXProject;
247247
attributes = {
248248
LastSwiftUpdateCheck = 0700;
249-
LastUpgradeCheck = 1200;
249+
LastUpgradeCheck = 1420;
250250
ORGANIZATIONNAME = ObjectHub;
251251
TargetAttributes = {
252252
CC99F54E1B7AA6E200355E1E = {
@@ -389,6 +389,7 @@
389389
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
390390
COPY_PHASE_STRIP = NO;
391391
CURRENT_PROJECT_VERSION = 1;
392+
DEAD_CODE_STRIPPING = YES;
392393
DEBUG_INFORMATION_FORMAT = dwarf;
393394
ENABLE_STRICT_OBJC_MSGSEND = YES;
394395
ENABLE_TESTABILITY = YES;
@@ -407,7 +408,7 @@
407408
GCC_WARN_UNUSED_FUNCTION = YES;
408409
GCC_WARN_UNUSED_VARIABLE = YES;
409410
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
410-
MACOSX_DEPLOYMENT_TARGET = 10.12;
411+
MACOSX_DEPLOYMENT_TARGET = 11.0;
411412
MTL_ENABLE_DEBUG_INFO = YES;
412413
ONLY_ACTIVE_ARCH = YES;
413414
SDKROOT = macosx;
@@ -451,6 +452,7 @@
451452
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
452453
COPY_PHASE_STRIP = NO;
453454
CURRENT_PROJECT_VERSION = 1;
455+
DEAD_CODE_STRIPPING = YES;
454456
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
455457
ENABLE_NS_ASSERTIONS = NO;
456458
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -463,7 +465,7 @@
463465
GCC_WARN_UNUSED_FUNCTION = YES;
464466
GCC_WARN_UNUSED_VARIABLE = YES;
465467
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
466-
MACOSX_DEPLOYMENT_TARGET = 10.12;
468+
MACOSX_DEPLOYMENT_TARGET = 11.0;
467469
MTL_ENABLE_DEBUG_INFO = NO;
468470
SDKROOT = macosx;
469471
SWIFT_COMPILATION_MODE = wholemodule;
@@ -482,6 +484,7 @@
482484
CLANG_ENABLE_MODULES = YES;
483485
COMBINE_HIDPI_IMAGES = YES;
484486
CURRENT_PROJECT_VERSION = 3;
487+
DEAD_CODE_STRIPPING = YES;
485488
DEFINES_MODULE = YES;
486489
DYLIB_COMPATIBILITY_VERSION = 1;
487490
DYLIB_CURRENT_VERSION = 1;
@@ -509,6 +512,7 @@
509512
CLANG_ENABLE_MODULES = YES;
510513
COMBINE_HIDPI_IMAGES = YES;
511514
CURRENT_PROJECT_VERSION = 3;
515+
DEAD_CODE_STRIPPING = YES;
512516
DEFINES_MODULE = YES;
513517
DYLIB_COMPATIBILITY_VERSION = 1;
514518
DYLIB_CURRENT_VERSION = 1;
@@ -533,6 +537,7 @@
533537
isa = XCBuildConfiguration;
534538
buildSettings = {
535539
COMBINE_HIDPI_IMAGES = YES;
540+
DEAD_CODE_STRIPPING = YES;
536541
INFOPLIST_FILE = Tests/NumberKitTests/Info.plist;
537542
LD_RUNPATH_SEARCH_PATHS = (
538543
"$(inherited)",
@@ -550,6 +555,7 @@
550555
isa = XCBuildConfiguration;
551556
buildSettings = {
552557
COMBINE_HIDPI_IMAGES = YES;
558+
DEAD_CODE_STRIPPING = YES;
553559
INFOPLIST_FILE = Tests/NumberKitTests/Info.plist;
554560
LD_RUNPATH_SEARCH_PATHS = (
555561
"$(inherited)",

NumberKit.xcodeproj/xcshareddata/xcschemes/NumberKit iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1200"
3+
LastUpgradeVersion = "1420"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

NumberKit.xcodeproj/xcshareddata/xcschemes/NumberKit.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1200"
3+
LastUpgradeVersion = "1420"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// NumberKit
55
//
66
// Created by Matthias Zenger on 01/05/2017.
7-
// Copyright © 2015-2020 Matthias Zenger. All rights reserved.
7+
// Copyright © 2015-2023 Matthias Zenger. All rights reserved.
88
//
99
// Licensed under the Apache License, Version 2.0 (the "License");
1010
// you may not use this file except in compliance with the License.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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.5](https://img.shields.io/badge/Language-Swift%205.5-green.svg?style=flat)](https://developer.apple.com/swift/) [![IDE: Xcode 13](https://img.shields.io/badge/IDE-Xcode%2013-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.7](https://img.shields.io/badge/Language-Swift%205.7-green.svg?style=flat)](https://developer.apple.com/swift/) [![IDE: Xcode 14](https://img.shields.io/badge/IDE-Xcode%2014-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

@@ -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.5](https://developer.apple.com/xcode/)
51-
- [Swift 5.4](https://developer.apple.com/swift/)
50+
- [Xcode 14](https://developer.apple.com/xcode/)
51+
- [Swift 5.7](https://developer.apple.com/swift/)
5252
- [Swift Package Manager](https://swift.org/package-manager/)
5353
- macOS, iOS or Linux
5454

5555
## Copyright
5656

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

Sources/NumberKit iOS/Info.plist

Lines changed: 1 addition & 1 deletion
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–2021 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

Sources/NumberKit/BigInt.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ public struct BigInt: Hashable,
254254
self.init(digits: temp, negative: negative, base: base)
255255
}
256256

257-
/// Initializes a `BigInt` randomly with a given number of bits
257+
/// Initializes a non-negative `BigInt` randomly with a given number of bits using the
258+
/// provided random number generator.
258259
public init<R: RandomNumberGenerator>(randomWithMaxBits bitWidth: Int,
259260
using generator: inout R) {
260261
var words = ContiguousArray<UInt32>()
@@ -951,22 +952,22 @@ public struct BigInt: Hashable,
951952
return BigInt.fromTwoComplement(&words)
952953
}
953954

954-
/// Returns a random `BigInt` with up to `bitWidth` bits using the random number
955+
/// Returns a random non-negative `BigInt` with up to `bitWidth` bits using the random number
955956
/// generator `generator`.
956957
public static func random<R: RandomNumberGenerator>(withMaxBits bitWidth: Int,
957958
using generator: inout R) -> BigInt {
958959
return BigInt(randomWithMaxBits: bitWidth, using: &generator)
959960
}
960961

961-
/// Returns a random `BigInt` with up to `bitWidth` bits using the system random number
962-
/// generator.
962+
/// Returns a random non-negative `BigInt` with up to `bitWidth` bits using the system
963+
/// random number generator.
963964
public static func random(withMaxBits bitWidth: Int) -> BigInt {
964965
var generator = SystemRandomNumberGenerator()
965966
return BigInt(randomWithMaxBits: bitWidth, using: &generator)
966967
}
967968

968-
/// Returns a random `BigInt` below the given upper bound `bound` using the random number
969-
/// generator `generator`.
969+
/// Returns a random non-negative `BigInt` below the given upper bound `bound` using the
970+
/// random number generator `generator`.
970971
public static func random<R: RandomNumberGenerator>(below bound: BigInt,
971972
using generator: inout R) -> BigInt {
972973
let bitWidth = bound.bitSize
@@ -977,8 +978,8 @@ public struct BigInt: Hashable,
977978
return res
978979
}
979980

980-
/// Returns a random `BigInt` below the given upper bound `bound` using the system random
981-
/// number generator.
981+
/// Returns a random non-negative `BigInt` below the given upper bound `bound` using
982+
/// the system random number generator.
982983
public static func random(below bound: BigInt) -> BigInt {
983984
var generator = SystemRandomNumberGenerator()
984985
return BigInt.random(below: bound, using: &generator)

Sources/NumberKit/Complex.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
345345
public func divided(by rhs: T) -> Complex<T> {
346346
return Complex(self.re / rhs, self.im / rhs);
347347
}
348+
349+
/// Returns a random complex number given a real and imaginary range.
350+
public static func random<R>(realRange: Range<T>,
351+
imaginaryRange: Range<T>,
352+
using generator: inout R) -> Self where R: RandomNumberGenerator {
353+
return Complex(T.random(in: realRange, using: &generator),
354+
T.random(in: imaginaryRange, using: &generator))
355+
}
348356
}
349357

350358
// Implement equality

Sources/NumberKit/FloatingPointNumber.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public protocol FloatingPointNumber: FloatingPoint, _ExpressibleByBuiltinFloatLi
4040
func pow(_ ex: Self) -> Self
4141
func hypot(_ y: Self) -> Self
4242
func atan2(_ y: Self) -> Self
43+
static func random<T: RandomNumberGenerator>(in range: Range<Self>,
44+
using generator: inout T) -> Self
4345
}
4446

4547
/// Make `Float` implement protocol `FloatingPointNumber`.

Sources/NumberKit/Info.plist

Lines changed: 1 addition & 1 deletion
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–2021 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

Tests/NumberKitTests/Info.plist

Lines changed: 1 addition & 1 deletion
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–2021 Matthias Zenger. All rights reserved.</string>
22+
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
2323
</dict>
2424
</plist>

0 commit comments

Comments
 (0)