https://github.com/swiftlang/swift-se0288-is-power
Preview package for Swift Evolution proposal SE-0288
https://github.com/swiftlang/swift-se0288-is-power
Last synced: 12 days ago
JSON representation
Preview package for Swift Evolution proposal SE-0288
- Host: GitHub
- URL: https://github.com/swiftlang/swift-se0288-is-power
- Owner: swiftlang
- License: apache-2.0
- Created: 2021-09-08T16:23:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T21:24:04.000Z (over 1 year ago)
- Last Synced: 2025-10-18T16:26:11.117Z (2 months ago)
- Language: Swift
- Size: 26.4 KB
- Stars: 9
- Watchers: 124
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SE0288_IsPower
**SE0288_IsPower** is a standalone library that implements the Swift Evolution proposal
[SE-0288: Adding `isPower(of:)` to BinaryInteger][proposal].
You can use this package independently,
or as part of the [standard library preview package][stdlib-preview].
* Proposal: [SE-0288][proposal]
* Author: [Ding Ye](https://github.com/dingobye)
## Introduction
This package adds a public API `isPower(of:)`, as an extension method,
to the `BinaryInteger` protocol.
It checks if an integer is a power of another.
That is, `a.isPower(of: b)` checks whether there exists any integer `n` such that `a == pow(b, n)` is true.
```swift
import SE0288_IsPower
let x: Int = Int.random(in: 0000..<0288)
1.isPower(of: x) // 'true' since x^0 == 1
let y: UInt = 1000
y.isPower(of: 10) // 'true' since 10^3 == 1000
(-1).isPower(of: 1) // 'false'
(-32).isPower(of: -2) // 'true' since (-2)^5 == -32
```
## Usage
You can add this library as a dependency to any Swift package.
Add this line to the `dependencies` parameter in your `Package.swift` file:
```swift
.package(url: "https://github.com/apple/swift-se0288-is-power", from: "2.0.0"),
```
Next, add the module as a dependency for your targets that will use the library:
```swift
.product(name: "SE0288_IsPower", package: "swift-se0288-is-power"),
```
You can now use `import SE0288_IsPower` to make the library available in any Swift file.
## Contributing
We are no longer taking contributions to this repo. Please see the
[guide for Contributing to Swift][contributing] for other opportunities within the Swift
project. Thanks to all past contributors!
[proposal]: https://github.com/apple/swift-evolution/blob/master/proposals/0288-binaryinteger-ispower.md
[stdlib-preview]: https://github.com/apple/swift-standard-library-preview
[user-forums]: https://forums.swift.org/c/swift-users/
[bugs]: https://bugs.swift.org
[evolution-process]: https://github.com/apple/swift-evolution/blob/master/process.md
[contributing]: https://swift.org/contributing