Skip to content

A package for checking the parity of any Integers.

Notifications You must be signed in to change notification settings

McNight/Swift-Parity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Parity

Allow easy checking of the parity of numbers (integers in particular).

Overview

By importing this package, you'll benefit on two new APIs for easily checking if an number is either even or odd.

let a = 5
if a.isOdd {
    print(a, "is odd")
}
let b: UInt8 = .min
if b.isEven {
    print(b, "is even")
}

You can even benefit from an alternative implementation that I suspect to be faster but I need to measure properly to check if it really is.

let n = Int64.random(in: .min ... .max)
if n.probablyEvenFasterIsEven {
    print(a, "is even")
} else {
    assert(n.probablyEvenFasterIsOdd)
}

Installation

You can add Swift Parity to an Xcode project by adding it as a package dependency.

https://github.com/McNight/swift-parity

To use it in a SwiftPM project, just add it to a dependencies clause in your Package.swift:

dependencies: [
    .package(url: "https://github.com/McNight/swift-parity", from: "0.0.1")
]

About

A package for checking the parity of any Integers.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages