You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/IntegerUtilities/README.md
+8-14Lines changed: 8 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,21 +37,19 @@ The following API are defined for signed integer types:
37
37
- The `rotated(right:)` and `rotated(left:)` methods implement _bitwise rotation_ for signed and unsigned integer types.
38
38
The count parameter may be any `BinaryInteger` type.
39
39
40
-
### Saturating Arithmetic
40
+
### [Saturating Arithmetic][saturating]
41
41
42
-
The following saturating operations are defined as methods on
43
-
`FixedWidthInteger` types:
42
+
The following saturating operations are defined as methods on `FixedWidthInteger`:
44
43
45
44
-`addingWithSaturation(_:)`
46
45
-`subtractingWithSaturation(_:)`
47
46
-`negatedWithSaturation(_:)`
48
47
-`multipliedWithSaturation(by:)`
48
+
-`shiftedWithSaturation(leftBy:rounding:)`
49
49
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:
55
53
```
56
54
let x: Int8 = 84
57
55
let y: Int8 = 100
@@ -60,15 +58,11 @@ let b = x &+ y // wraps to -72
60
58
let c = x.addingWithSaturation(y) // saturates to 127
61
59
```
62
60
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].
69
62
70
63
## Types
71
64
72
65
The `RoundingRule` enum is used with shift, division, and round operations to specify how to round their results to a representable value.
0 commit comments