ClampedInteger
An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.
Examples
let big = ClampedInteger.max // 9223372036854775807
big + 10 == .max // true
big * 2 == .max // true
big * -1 == .min + 1 // true, because -.max > .min
big * -2 == .min // true
let negative = ClampedInteger.min // -9223372036854775808
negative - 10 == .min // true
negative * 2 == .min // true
negative * -1 == .max // true
ClampedInteger is generic over FixedWidthIntegers and can be used with any fixed with integer type:
let big = ClampedInteger<UInt16>.max
big + 10 == .max // true
Install
Package.swift
Edit the Package.swift file. Add the GamCenterUI as a dependency:
let package = Package(
name: " ... ",
products: [ ... ],
dependencies: [
.package(url: "https://github.com/berikv/ClampedInteger.git", from: "0.0.0") // here
],
targets: [
.target(
name: " ... ",
dependencies: [
"ClampedInteger" // and here
]),
]
)
For .xcodeproj projects
- Open menu File > Add Packages...
- Search for "https://github.com/berikv/ClampedInteger.git" and click Add Package.
- Open your project file, select your target in "Targets".
- Open Dependencies
- Click the + sign
- Add ClampedInteger