swift-arithmetics

main

Swift package extending numeric protocols of the Swift programming language.
alexandrehsaad/swift-arithmetics

swift-arithmetics

Arithmetics is a package containing extensions to the numeric protocols and the implementation of the five basic arithmetics protocols including exponentiation for the Swift programming language.

Contents

The package currently provides the following implementations:

Extensions

BinaryInteger

  • isEven: A boolean value indicating whether this value is even.
  • isOdd: A boolean value indicating whether this value is odd.

CGFloat

  • Conforms to Addable, Clampable, Divisible, Multipliable, Raisable, Subtractable.

CGPoint

  • Conforms to Addable, AdditiveArithmetic, Subtractable.

Collection

  • areEqual: Returns a boolean value indicating whether the elements of this sequence are equal.

Comparable

  • isLess(than:): Returns a boolean value indicating whether this value is less than the specified value.
  • isLessThanOrEqual(to:): Returns a boolean value indicating whether this value is less than or equal to the specified value.
  • isGreater(than:): Returns a boolean value indicating whether this value is greater than the specified value.
  • isGreaterThanOrEqual(to:): Returns a boolean value indicating whether this value is greater than or equal to the specified value.

Equatable

  • isEqual(to:): Returns a boolean value indicating whether this value is equal to the specified value.
  • isUnequal(to:): Returns a boolean value indicating whether this value is unequal to the specified value.

Float32, Float64

  • Conforms to Addable, Clampable, Divisible, Multipliable, Raisable, Subtractable.

Int, Int8, Int16, Int32, Int64

  • Conforms to Addable, Clampable, Divisible, Multipliable, Raisable, Subtractable.

Numeric

  • isNegative: A boolean value indicating whether this value is negative.
  • isPositive: A boolean value indicating whether this value is positive.

UInt, UInt8, UInt16, UInt32, UInt64

  • Conforms to Addable, Clampable, Divisible, Multipliable, Raisable, Subtractable.

Property Wrappers

Clamped: A property wrapper that keeps a value clamped to a specified range.

Protocols

Addable: Representing values that can be added.

  • adding(_:): Returns the result of adding this value to the specified value, computed without intermediate rounding.
  • add(_:): Adds this value to the specified value, computed without intermediate rounding.

Clampable: Representing values that can be clamped.

  • clamping(from:): Returns a value clamped from a specified value.
  • clamp(from:): Clamps this value from a specified value.
  • clamping(from:through:): Returns a value clamped within two specified values.
  • clamp(from:through:): Clamps this value within two specified values.
  • clamping(through:): Returns a value clamped to a maximum specified value.
  • clamp(through:): Clamps this value to a maximum specified value.

Divisible: Representing values that can be divided.

  • dividing(by:): Returns the result of dividing this value to the specified value, computed without intermediate rounding.
  • divide(by:): Divides this value by the specified value, computed without intermediate rounding.
  • halved(): Returns this value halved, rounded to a representable value.
  • halve(): Halves this value, rounded to a representable value.

Multipliable: Representing values that can be multiplied.

  • multiplying(by:): Returns the result of multiplying this value by the specified value, computed without intermediate rounding.
  • multiply(by:): Multiplies this value by the specified value, computed without intermediate rounding.
  • doubled(): Returns this value doubled, rounded to a representable value.
  • double(): Doubles this value, rounded to a representable value.

Subtractable: Representing values that can be subtracted.

  • subtracting(_:): Returns the result of subtracting this value by the specified value, computed without intermediate rounding.
  • subtract(_:): Subtracts this value by the specified value, computed without intermediate rounding.

Raisable: Representing values that can be raised to the power.

  • raising(to:): Returns the result of raising this value to the specified value, computed without intermediate rounding.
  • raise(to:): Raises this value to the specified value, computed without intermediate rounding.
  • raisedReportingOverflow(to:): Returns the power of this value and the specified value, along with a boolean value indicating whether overflow occurred in the operation.
  • squared(): Returns the result of raising this value to its square, computed without intermediate rounding.
  • square(): Raises this value to its square, computed without intermediate rounding.
  • cubed(): Returns the result of raising this value to its cube, computed without intermediate rounding.
  • cube(): Raises this value to its cube, computed without intermediate rounding.
  • isPowerOfTwo: A boolean value indicating whether this value is a power of two.
  • isPowerOfTen: A boolean value indicating whether this value is a power of ten.

Installation

To use this package in a SwiftPM project:

  1. Add it to the dependencies in your Package.swift file:
let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/alexandrehsaad/swift-arithmetics.git", branch: "main")
    ],
    ...
)
  1. Add it as a dependency for your target in your Package.swift file:
let package = Package(
    ...
    targets: [
        .target(name: "MyTarget", dependencies: [
            .product(name: "Arithmetics", package: "swift-arithmetics")
        ]),
    ],
    ...
)
  1. Import the package in your source code.
import Arithmetics

Contribution

Reporting a bug

If you find a bug, please open a bug report.

Contacting the maintainers

The current code owner of this package is Alexandre H. Saad (@alexandrehsaad). You can contact him by writing an email to alexandresaad at icloud dot com.

Supporting

If you like our work, show your support by staring this repository.

Feedback

We would love to hear your thoughts or feedback on how we can improve Swift Arithmetics!

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Nov 17 2021 08:56:09 GMT-0500 (GMT-05:00)