FunctionSwift

numericCast(_:)

Returns the given integer as the equivalent value in a different integer type.

func numericCast<T, U>(_ x: T) -> U where T : BinaryInteger, U : BinaryInteger

Parameters

x

The integer to convert, an instance of type T.

Returns

The value of x converted to type U.

Overview

Calling the numericCast(_:) function is equivalent to calling an initializer for the destination type. numericCast(_:) traps on overflow in -O and -Onone builds.