Skip to content

Commit eea5267

Browse files
committed
Add documentation for SignedNumberRepresentation
1 parent c51d6d9 commit eea5267

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Sources/SignedNumberRepresentation.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@
33
//
44
// See LICENSE for license information
55

6+
/// Represents a method to encode signed integers in a binary format.
67
public enum SignedNumberRepresentation {
78

9+
/// Signed magnitude representation.
810
case signMagnitude
11+
/// One's complement representation of negative integers.
912
case oneComplementNegatives
13+
/// Two's complement representation of negative integers.
1014
case twoComplementNegatives
15+
/// Biased representation with a custom `bias`.
1116
case biased(bias: Int)
17+
/// Base (radix) -2 representation.
1218
case radixNegativeTwo
1319

1420
// Generally speaking, there is a natural limit of the maximum and minimum values that Swift's Int type can hold.
1521
// So when the bitsCount matches the bit width of the Int type we need to be careful.
1622

23+
/**
24+
Returns a minimum signed integer that is possible to represent in a binary format within `bitsCount` bits using the
25+
current representation.
26+
27+
- Precondition: Parameter `bitsCount` must be greater than zero.
28+
- Precondition: For the `SignedNumberRepresentation.biased` representation, the `bias` must be non-negative.
29+
*/
1730
public func minRepresentableNumber(bitsCount: Int) -> Int {
1831
precondition(bitsCount > 0)
1932

@@ -53,6 +66,13 @@ public enum SignedNumberRepresentation {
5366
}
5467
}
5568

69+
/**
70+
Returns a maximum signed integer that is possible to represent in a binary format within `bitsCount` bits using the
71+
current representation.
72+
73+
- Precondition: Parameter `bitsCount` must be greater than zero.
74+
- Precondition: For the `SignedNumberRepresentation.biased` representation, the `bias` must be non-negative.
75+
*/
5676
public func maxRepresentableNumber(bitsCount: Int) -> Int {
5777
precondition(bitsCount > 0)
5878

0 commit comments

Comments
 (0)