Update Readme
An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.
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>(21) big * 21 == 255 // true
The clamping behavior may lead to surprising results. In this example the literal -10 is clamped to the minimum value of UInt (which is 0).
-10
0
ClampedInteger<UInt>(-10) == 0 // true
Edit the Package.swift file. Add the ClampedInteger 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 ]), ] )
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
ClampedInteger
An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.
Examples
ClampedInteger is generic over FixedWidthIntegers and can be used with any fixed with integer type:
The clamping behavior may lead to surprising results. In this example the literal
-10
is clamped to the minimum value of UInt (which is0
).Install
Package.swift
Edit the Package.swift file. Add the ClampedInteger as a dependency:
For .xcodeproj projects