Skip to content

Commit 48dc2b2

Browse files
authored
Update docs for numericCast (#31464) (#31476)
Drops outdated random number generation example and simplifies a bit. Fixes <rdar://problem/57888487>
1 parent 60f7aa2 commit 48dc2b2

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

stdlib/public/core/Integers.swift

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,24 +3614,11 @@ extension SignedInteger where Self: FixedWidthInteger {
36143614
/// Returns the given integer as the equivalent value in a different integer
36153615
/// type.
36163616
///
3617-
/// The `numericCast(_:)` function traps on overflow in `-O` and `-Onone`
3618-
/// builds.
3619-
///
3620-
/// You can use `numericCast(_:)` to convert a value when the destination type
3621-
/// can be inferred from the context. In the following example, the
3622-
/// `random(in:)` function uses `numericCast(_:)` twice to convert the
3623-
/// argument and return value of the `arc4random_uniform(_:)` function to the
3624-
/// appropriate type.
3625-
///
3626-
/// func random(in range: Range<Int>) -> Int {
3627-
/// return numericCast(arc4random_uniform(numericCast(range.count)))
3628-
/// + range.lowerBound
3629-
/// }
3630-
///
3631-
/// let number = random(in: -10...<10)
3632-
/// // number == -3, perhaps
3617+
/// Calling the `numericCast(_:)` function is equivalent to calling an
3618+
/// initializer for the destination type. `numericCast(_:)` traps on overflow
3619+
/// in `-O` and `-Onone` builds.
36333620
///
3634-
/// - Parameter x: The integer to convert, and instance of type `T`.
3621+
/// - Parameter x: The integer to convert, an instance of type `T`.
36353622
/// - Returns: The value of `x` converted to type `U`.
36363623
@inlinable
36373624
public func numericCast<T: BinaryInteger, U: BinaryInteger>(_ x: T) -> U {

0 commit comments

Comments
 (0)