exponent
The exponent of the floating-point value.
Declaration
var exponent: Self.Exponent { get }Discussion
The exponent of a floating-point value is the integer part of the logarithm of the value’s magnitude. For a value x of a floating-point type F, the magnitude can be calculated as the following, where ** is exponentiation:
x.significand * (F.radix ** x.exponent)In the next example, y has a value of 21.5, which is encoded as 1.34375 * 2 ** 4. The significand of y is therefore 1.34375.
let y: Double = 21.5
// y.significand == 1.34375
// y.exponent == 4
// Double.radix == 2The exponent property has the following edge cases:
If
xis zero, thenx.exponentisInt.min.If
xis +/-infinity or NaN, thenx.exponentisInt.max
This property implements the logB operation defined by the IEEE 754 specification.