Swiftpack.co -  apple/swift-se0288-is-power as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Preview package for Swift Evolution proposal SE-0288
.package(url: "https://github.com/apple/swift-se0288-is-power.git", from: "1.0.0")


SE0288_IsPower is a standalone library that implements the Swift Evolution proposal SE-0288: Adding isPower(of:) to BinaryInteger. You can use this package independently, or as part of the standard library preview package.


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.

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


You can add this library as a dependency to any Swift package. Add this line to the dependencies parameter in your Package.swift file:

    url: "https://github.com/apple/swift-se0288-is-power",
    from: "1.0.0"),

Next, add the module as a dependency for your targets that will use the library:

.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.


Contributions to this package and the standard library preview package are welcomed and encouraged!


Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Initial release of isPower(of:)
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics