Skip to content

Commit 8552bec

Browse files
authored
Documented overflow behavior of gcd
1 parent 89c4e42 commit 8552bec

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/IntegerUtilities/GCD.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
/// If both inputs are zero, the result is zero. If one input is zero, the
1515
/// result is the absolute value of the other input.
1616
///
17+
/// The resulting value must be representable within the value's type. In
18+
/// particular, the gcd of a signed, fixed-width integer type's minimum
19+
/// with itself or zero results in a value that cannot be represented:
20+
///
21+
/// gcd(Int.min, Int.min) // Overflow error
22+
/// gcd(Int.min, 0) // Overflow error
23+
///
1724
/// [wiki]: https://en.wikipedia.org/wiki/Greatest_common_divisor
1825
@inlinable
1926
public func gcd<T: BinaryInteger>(_ a: T, _ b: T) -> T {

0 commit comments

Comments
 (0)