Skip to content

Commit

Permalink
Support random number generation for Complex. Migrate project to Swif…
Browse files Browse the repository at this point in the history
…t 5.7 and Xcode 14.
  • Loading branch information
objecthub committed Jan 1, 2023
1 parent 09602a1 commit 0f9c918
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.4.2 (2023-01-01)
- Support random number generation for Complex
- Migrated project to Swift 5.7 and Xcode 14

## 2.4.1 (2022-01-04)
- Support random number generation for BigInt
- Migrated project to Swift 5.5 and Xcode 13.2
Expand Down
12 changes: 9 additions & 3 deletions NumberKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 1200;
LastUpgradeCheck = 1420;
ORGANIZATIONNAME = ObjectHub;
TargetAttributes = {
CC99F54E1B7AA6E200355E1E = {
Expand Down Expand Up @@ -389,6 +389,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -407,7 +408,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -451,6 +452,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -463,7 +465,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -482,6 +484,7 @@
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down Expand Up @@ -509,6 +512,7 @@
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -533,6 +537,7 @@
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
INFOPLIST_FILE = Tests/NumberKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -550,6 +555,7 @@
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
INFOPLIST_FILE = Tests/NumberKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// NumberKit
//
// Created by Matthias Zenger on 01/05/2017.
// Copyright © 2015-2020 Matthias Zenger. All rights reserved.
// Copyright © 2015-2023 Matthias Zenger. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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.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)
[![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)

## Overview

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

## Copyright

Author: Matthias Zenger (<[email protected]>)
Copyright © 2016-2021 Matthias Zenger. All rights reserved.
Copyright © 2016-2023 Matthias Zenger. All rights reserved.
2 changes: 1 addition & 1 deletion Sources/NumberKit iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>
17 changes: 9 additions & 8 deletions Sources/NumberKit/BigInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ public struct BigInt: Hashable,
self.init(digits: temp, negative: negative, base: base)
}

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

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

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

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

/// Returns a random `BigInt` below the given upper bound `bound` using the system random
/// number generator.
/// Returns a random non-negative `BigInt` below the given upper bound `bound` using
/// the system random number generator.
public static func random(below bound: BigInt) -> BigInt {
var generator = SystemRandomNumberGenerator()
return BigInt.random(below: bound, using: &generator)
Expand Down
8 changes: 8 additions & 0 deletions Sources/NumberKit/Complex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ public struct Complex<T: FloatingPointNumber>: ComplexNumber,
public func divided(by rhs: T) -> Complex<T> {
return Complex(self.re / rhs, self.im / rhs);
}

/// Returns a random complex number given a real and imaginary range.
public static func random<R>(realRange: Range<T>,
imaginaryRange: Range<T>,
using generator: inout R) -> Self where R: RandomNumberGenerator {
return Complex(T.random(in: realRange, using: &generator),
T.random(in: imaginaryRange, using: &generator))
}
}

// Implement equality
Expand Down
2 changes: 2 additions & 0 deletions Sources/NumberKit/FloatingPointNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public protocol FloatingPointNumber: FloatingPoint, _ExpressibleByBuiltinFloatLi
func pow(_ ex: Self) -> Self
func hypot(_ y: Self) -> Self
func atan2(_ y: Self) -> Self
static func random<T: RandomNumberGenerator>(in range: Range<Self>,
using generator: inout T) -> Self
}

/// Make `Float` implement protocol `FloatingPointNumber`.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NumberKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Tests/NumberKitTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015–2021 Matthias Zenger. All rights reserved.</string>
<string>Copyright © 2015–2023 Matthias Zenger. All rights reserved.</string>
</dict>
</plist>

0 comments on commit 0f9c918

Please sign in to comment.