mirror of
https://github.com/apple/swift-numerics
synced 2026-11-22 04:30:45 +00:00
Correct rounding documentation examples
This commit is contained in:
1 parent
899af71c02
commit
aa5684820a
2 files changed
+5
-7
No files matched your search
@@ -163,7 +163,7 @@ public enum RoundingRule {
|
||||
/// - `(-4).divided(by: 3, rounding: .toNearestOrZero)`
|
||||
/// is `-1`, because –4/3 = –1.3̅ is closer to –1 than it is to –2.
|
||||
///
|
||||
/// - `5.shifted(rightBy: 1, rounding: .toNearestOrZero)` is `3`,
|
||||
/// - `5.shifted(rightBy: 1, rounding: .toNearestOrZero)` is `2`,
|
||||
/// because 5/2 = 2.5 is equally close to 2 and 3, and 2 is closer to zero.
|
||||
case toNearestOrZero
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ extension BinaryInteger {
|
||||
/// // is odd.
|
||||
/// 3.shifted(rightBy: 1, rounding: .toOdd)
|
||||
///
|
||||
/// // 7/4 = 1.75, so the result is 1 with probability 1/4, or 2
|
||||
/// // with probability 3/4.
|
||||
/// 7.shifted(rightBy: 2, rounding: .stochastically)
|
||||
/// // 6/4 = 1.5, so the tie is broken in favor of the even value 2.
|
||||
/// 6.shifted(rightBy: 2, rounding: .toNearestOrEven)
|
||||
///
|
||||
/// // 4/4 is exactly 1, so this does not trap.
|
||||
/// 4.shifted(rightBy: 2, rounding: .requireExact)
|
||||
@@ -153,9 +152,8 @@ extension BinaryInteger {
|
||||
/// // is odd.
|
||||
/// 3.shifted(rightBy: 1, rounding: .toOdd)
|
||||
///
|
||||
/// // 7/4 = 1.75, so the result is 1 with probability 1/4, or 2
|
||||
/// // with probability 3/4.
|
||||
/// 7.shifted(rightBy: 2, rounding: .stochastically)
|
||||
/// // 6/4 = 1.5, so the tie is broken in favor of the even value 2.
|
||||
/// 6.shifted(rightBy: 2, rounding: .toNearestOrEven)
|
||||
///
|
||||
/// // 4/4 is exactly 1, so this does not trap.
|
||||
/// 4.shifted(rightBy: 2, rounding: .requireExact)
|
||||
|
||||
Reference in new issue
Block a user