Skip to content

Commit a118de9

Browse files
committed
Polish README.md
1 parent 58f4e72 commit a118de9

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Sources/IntegerUtilities/README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@ The following API are defined for signed integer types:
3737
- The `rotated(right:)` and `rotated(left:)` methods implement _bitwise rotation_ for signed and unsigned integer types.
3838
The count parameter may be any `BinaryInteger` type.
3939

40-
### Saturating Arithmetic
40+
### [Saturating Arithmetic][saturating]
4141

42-
The following saturating operations are defined as methods on
43-
`FixedWidthInteger` types:
42+
The following saturating operations are defined as methods on `FixedWidthInteger`:
4443

4544
- `addingWithSaturation(_:)`
4645
- `subtractingWithSaturation(_:)`
4746
- `negatedWithSaturation(_:)`
4847
- `multipliedWithSaturation(by:)`
48+
- `shiftedWithSaturation(leftBy:rounding:)`
4949

50-
These implement _saturating arithmetic_. These are an alternative to the
51-
usual `+`, `-`, and `*` operators, which trap if the result cannot be
52-
represented in the argument type, and `&+`, `&-`, and `&*` which wrap
53-
out-of-range results modulo 2ⁿ for some n. Instead these methods clamp
54-
the result to the representable range of the type:
50+
These implement _saturating arithmetic_.
51+
They are an alternative to the usual `+`, `-`, and `*` operators, which trap if the result cannot be represented in the argument type, and `&+`, `&-`, `&*`, and `<<`, which wrap out-of-range results modulo 2ⁿ for some n.
52+
Instead these methods clamp the result to the representable range of the type:
5553
```
5654
let x: Int8 = 84
5755
let y: Int8 = 100
@@ -60,15 +58,11 @@ let b = x &+ y // wraps to -72
6058
let c = x.addingWithSaturation(y) // saturates to 127
6159
```
6260

63-
There is one other method, `shiftedWithSaturation(leftBy:rounding:)`,
64-
which performs a bitwise shift with rounding and saturation.
65-
66-
If you are using saturating arithmetic, you may also want to perform
67-
saturating conversions between integer types; this functionality is provided
68-
by the standard library via the [`init(clamping:)` API][clamping]
61+
If you are using saturating arithmetic, you may also want to perform saturating conversions between integer types; this functionality is provided by the standard library via the [`init(clamping:)` API][clamping].
6962

7063
## Types
7164

7265
The `RoundingRule` enum is used with shift, division, and round operations to specify how to round their results to a representable value.
7366

67+
[saturating]: https://en.wikipedia.org/wiki/Saturation_arithmetic
7468
[clamping]: https://developer.apple.com/documentation/swift/binaryinteger/init(clamping:)

0 commit comments

Comments
 (0)