Returns the value with greater magnitude.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
Parameters
xA floating-point value.
yAnother floating-point value.
Return Value
Whichever of x or y has greater magnitude, or whichever is a number if the other is NaN.
Discussion
This method returns the value with greater magnitude of the two given values, preserving order and eliminating NaN when possible. For two values x and y, the result of maximum is x if x, y if x, or whichever of x or y is a number if the other is a quiet NaN. If both x and y are NaN, or either x or y is a signaling NaN, the result is NaN.
Double.maximumMagnitude(10.0, -25.0)
// -25.0
Double.maximumMagnitude(10.0, .nan)
// 10.0
Double.maximumMagnitude(.nan, -25.0)
// -25.0
Double.maximumMagnitude(.nan, .nan)
// nan
The maximum method implements the max operation defined by the IEEE 754 specification.