numericCast

func numericCast<T : _SignedInteger, U : _SignedInteger>(_: T)

Convert x to type U, trapping on overflow in -Onone and -O builds.

Typically used to do conversion to any contextually-deduced integer type:

func f(_ x: Int32) {}
func g(_ x: Int64) { f(numericCast(x)) }

Declaration

func numericCast<T : _SignedInteger, U : _SignedInteger>(_ x: T) -> U
func numericCast<T : _SignedInteger, U : UnsignedInteger>(_: T)

Convert x to type U, trapping on overflow in -Onone and -O builds.

Typically used to do conversion to any contextually-deduced integer type:

func f(_ x: UInt32) {}
func g(_ x: Int64) { f(numericCast(x)) }

Declaration

func numericCast<T : _SignedInteger, U : UnsignedInteger>(_ x: T) -> U
func numericCast<T : UnsignedInteger, U : _SignedInteger>(_: T)

Convert x to type U, trapping on overflow in -Onone and -O builds.

Typically used to do conversion to any contextually-deduced integer type:

func f(_ x: Int32) {}
func g(_ x: UInt64) { f(numericCast(x)) }

Declaration

func numericCast<T : UnsignedInteger, U : _SignedInteger>(_ x: T) -> U
func numericCast<T : UnsignedInteger, U : UnsignedInteger>(_: T)

Convert x to type U, trapping on overflow in -Onone and -O builds.

Typically used to do conversion to any contextually-deduced integer type:

func f(_ x: UInt32) {}
func g(_ x: UInt64) { f(numericCast(x)) }

Declaration

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