From bfd905c9e4571fd8d8be096387652ededde46d08 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Wed, 3 Nov 2021 13:51:59 -0400 Subject: [PATCH] Minor cleanups in integer utilities. --- Sources/IntegerUtilities/CMakeLists.txt | 2 +- .../IntegerUtilities/DivideWithRounding.swift | 2 +- Sources/IntegerUtilities/README.md | 38 +++++++------------ .../{Rounding.swift => RoundingRule.swift} | 2 +- .../IntegerUtilities/ShiftWithRounding.swift | 2 +- 5 files changed, 18 insertions(+), 28 deletions(-) rename Sources/IntegerUtilities/{Rounding.swift => RoundingRule.swift} (97%) diff --git a/Sources/IntegerUtilities/CMakeLists.txt b/Sources/IntegerUtilities/CMakeLists.txt index d738647..cd141a4 100644 --- a/Sources/IntegerUtilities/CMakeLists.txt +++ b/Sources/IntegerUtilities/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(IntegerUtilities DivideWithRounding.swift GCD.swift Rotate.swift - Rounding.swift + RoundingRule.swift ShiftWithRounding.swift) set_target_properties(IntegerUtilities PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/Sources/IntegerUtilities/DivideWithRounding.swift b/Sources/IntegerUtilities/DivideWithRounding.swift index 5a50aac..87fabaa 100644 --- a/Sources/IntegerUtilities/DivideWithRounding.swift +++ b/Sources/IntegerUtilities/DivideWithRounding.swift @@ -1,4 +1,4 @@ -//===--- Divide.swift -----------------------------------------*- swift -*-===// +//===--- DivideWithRounding.swift -----------------------------*- swift -*-===// // // This source file is part of the Swift Numerics open source project // diff --git a/Sources/IntegerUtilities/README.md b/Sources/IntegerUtilities/README.md index 2651799..ee7318c 100644 --- a/Sources/IntegerUtilities/README.md +++ b/Sources/IntegerUtilities/README.md @@ -6,47 +6,37 @@ _Note: This module is only present on `main`, and has not yet been stabilized an The following API are defined for all integer types conforming to `BinaryInteger`: -- The `gcd(_:_:)` free function implements the _Greatest Common Divisor_ - operation. +- The `gcd(_:_:)` free function implements the _Greatest Common Divisor_ operation. -- The `shifted(rightBy:rounding:)` method implements _bitwise shift with - rounding_. +- The `shifted(rightBy:rounding:)` method implements _bitwise shift with rounding_. -- The `divided(by:rounding:)` method implements division with specified - rounding. (See also `SignedInteger.divided(by:rounding:)`, - `remainder(dividingBy:rounding:)`, and `euclideanDivision(_:_:)` below). +- The `divided(by:rounding:)` method implements division with specified rounding. + (See also `SignedInteger.divided(by:rounding:)`, `remainder(dividingBy:rounding:)`, and `euclideanDivision(_:_:)` below). ## Utilities defined for `SignedInteger` The following API are defined for signed integer types: -- The `divided(by:rounding:)` method implementing division with specified - rounding, returning both quotient and remainder. This requires a signed - type because the remainder is not generally representable for unsigned - types. This is a disfavored overload; by default, you will get only the - quotient as the result: +- The `divided(by:rounding:)` method implementing division with specified rounding, returning both quotient and remainder. + This requires a signed type because the remainder is not generally representable for unsigned types. + This is a disfavored overload; by default, you will get only the quotient as the result: ``` let p = 5.divided(by: 3, rounding: .up) // p = 2 let (q, r) = 5.divided(by: 3, rounding: .up) // q = 2, r = -1 ``` -- The `remainder(dividingBy:rounding:)` method implementing the remainder - operation; the `rounding` argument describes how to round the _quotient_, - which is not returned. (The remainder is always exact, and hence is not - rounded). +- The `remainder(dividingBy:rounding:)` method implementing the remainder operation; the `rounding` argument describes how to round the _quotient_, which is not returned. + (The remainder is always exact, and hence is not rounded). - The `euclideanDivision(_:_:)` free function implements _Euclidean division_. - In this operation, the remainder is chosen to always be non-negative. This - does not correspond to any rounding rule on the quotient, which is why it - uses a distinct API. + In this operation, the remainder is chosen to always be non-negative. + This does not correspond to any rounding rule on the quotient, which is why it uses a distinct API. ## Utilities defined for `FixedWidthInteger` -- The `rotated(right:)` and `rotated(left:)` methods implement _bitwise - rotation_ for signed and unsigned integer types. The count parameter may - be any `BinaryInteger` type. +- The `rotated(right:)` and `rotated(left:)` methods implement _bitwise rotation_ for signed and unsigned integer types. + The count parameter may be any `BinaryInteger` type. ## Types -The `RoundingRule` enum is used with shift, division, and round operations -to specify how to round their results to a representable value. +The `RoundingRule` enum is used with shift, division, and round operations to specify how to round their results to a representable value. diff --git a/Sources/IntegerUtilities/Rounding.swift b/Sources/IntegerUtilities/RoundingRule.swift similarity index 97% rename from Sources/IntegerUtilities/Rounding.swift rename to Sources/IntegerUtilities/RoundingRule.swift index 63a7a92..47d13c9 100644 --- a/Sources/IntegerUtilities/Rounding.swift +++ b/Sources/IntegerUtilities/RoundingRule.swift @@ -1,4 +1,4 @@ -//===--- Rounding.swift ---------------------------------------*- swift -*-===// +//===--- RoundingRule.swift -----------------------------------*- swift -*-===// // // This source file is part of the Swift Numerics open source project // diff --git a/Sources/IntegerUtilities/ShiftWithRounding.swift b/Sources/IntegerUtilities/ShiftWithRounding.swift index 32fbb24..baaa8f4 100644 --- a/Sources/IntegerUtilities/ShiftWithRounding.swift +++ b/Sources/IntegerUtilities/ShiftWithRounding.swift @@ -1,4 +1,4 @@ -//===--- Shift.swift ------------------------------------------*- swift -*-===// +//===--- ShiftWithRounding.swift ------------------------------*- swift -*-===// // // This source file is part of the Swift Numerics open source project //