The magnitude of this value.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
Discussion
For any numeric value x
, x
is the absolute value of x
. You can use the magnitude
property in operations that are simpler to implement in terms of unsigned values, such as printing the value of an integer, which is just printing a ‘-’ character in front of an absolute value.
The global abs(_:)
function provides more familiar syntax when you need to find an absolute value. In addition, because abs(_:)
always returns a value of the same type, even in a generic context, using the function instead of the magnitude
property is encouraged.