abs

func abs<T>(_: T)

Returns the absolute value of the given number.

The absolute value of x must be representable in the same type. In particular, the absolute value of a signed, fixed-width integer type's minimum cannot be represented.

let x = Int8.min
// x == -128
let y = abs(x)
// Overflow error

x: A signed number. Returns: The absolute value of x.

Declaration

func abs<T>(_ x: T) -> T where T : Comparable, T : SignedNumeric
func abs<T>(_: T)

Returns the absolute value of x.

Declaration

func abs<T>(_ x: T) -> T where T : FloatingPoint, T == T.Magnitude
func abs<T>(_: T)

Returns the absolute value of the given number.

x: A signed number. Returns: The absolute value of x.

Declaration

func abs<T>(_ x: T) -> T where T : SignedNumeric, T == T.Magnitude