abs()

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

👉 replit

abs(-5),            // 5
abs(-3.45),         // 3.45
abs(Int.min)        // ❌ overflow

Last updated

Was this helpful?