Skip to content

Commit faf1377

Browse files
committed
Add some documentation for AlgebraicField ops, minor fix for Augmented.
1 parent 17f5b59 commit faf1377

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Sources/RealModule/AlgebraicField.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
/// [field]: https://en.wikipedia.org/wiki/Field_(mathematics)
4848
public protocol AlgebraicField: SignedNumeric {
4949

50+
/// Replaces a with the (approximate) quotient `a/b`.
5051
static func /=(a: inout Self, b: Self)
5152

53+
/// The (approximate) quotient `a/b`.
5254
static func /(a: Self, b: Self) -> Self
5355

5456
/// The (approximate) reciprocal (multiplicative inverse) of this number,
@@ -59,11 +61,14 @@ public protocol AlgebraicField: SignedNumeric {
5961
/// (for finite fields) or approximately the same result up to a typical
6062
/// rounding error (for floating-point formats).
6163
///
62-
/// If self is zero, or if a reciprocal would overflow or underflow such
63-
/// that it cannot be accurately represented, the result is nil. Note that
64-
/// `.zero.reciprocal`, somewhat surprisingly, is *not* nil for `Real` or
65-
/// `Complex` types, because these types have an `.infinity` value that
66-
/// acts as the reciprocal of `.zero`.
64+
/// If self is zero and the type has no representation for infinity (as
65+
/// in a typical finite field implementation), or if a reciprocal would
66+
/// overflow or underflow such that it cannot be accurately represented,
67+
/// the result is nil.
68+
///
69+
/// Note that `.zero.reciprocal`, somewhat surprisingly, is *not* nil
70+
/// for `Real` or `Complex` types, because these types have an
71+
/// `.infinity` value that acts as the reciprocal of `.zero`.
6772
var reciprocal: Self? { get }
6873
}
6974

Sources/RealModule/AugmentedArithmetic.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ extension Augmented {
4040
///
4141
/// Postconditions:
4242
/// -
43-
/// - If `head` is normal, then `abs(tail) < abs(head.ulp)`.
44-
/// Assuming IEEE 754 default rounding, `abs(tail) <= abs(head.ulp)/2`.
43+
/// - If `head` is normal, then `abs(tail) < head.ulp`.
44+
/// Assuming IEEE 754 default rounding, `abs(tail) <= head.ulp/2`.
4545
/// - If both `head` and `tail` are normal, then `a * b` is exactly
4646
/// equal to `head + tail` when computed as real numbers.
4747
@_transparent
@@ -84,8 +84,8 @@ extension Augmented {
8484
///
8585
/// Postconditions:
8686
/// -
87-
/// - If `head` is normal, then `abs(tail) < abs(head.ulp)`.
88-
/// Assuming IEEE 754 default rounding, `abs(tail) <= abs(head.ulp)/2`.
87+
/// - If `head` is normal, then `abs(tail) < head.ulp`.
88+
/// Assuming IEEE 754 default rounding, `abs(tail) <= head.ulp/2`.
8989
@_transparent
9090
public static func sum<T:Real>(large a: T, small b: T) -> (head: T, tail: T) {
9191
assert(!(b.magnitude > a.magnitude))

Sources/RealModule/Real.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ extension Real {
9999
return x.squareRoot()
100100
}
101101

102+
/// The (approximate) reciprocal (multiplicative inverse) of this number,
103+
/// if it is representable.
104+
///
105+
/// If `a` if finite and nonzero, and `1/a` overflows or underflows,
106+
/// then `a.reciprocal` is `nil`. Otherwise, `a.reciprcoal` is `1/a`.
102107
@inlinable
103108
public var reciprocal: Self? {
104109
let recip = 1/self

0 commit comments

Comments
 (0)