Initializerswift 6.1.2Swift

init(exactly:)

Creates a new instance initialized to the given value, if it can be represented without rounding.

iOS
14.0+
macOS
11.0+
tvOS
14.0+
watchOS
7.0+
init?(exactly other: Float16)

Parameters

other

The value to use for the new instance.

If other can’t be represented as an instance of Float without rounding, the result of this initializer is nil. In particular, passing NaN as other always results in nil.

let x: Float16 = 21.25
let y = Float(exactly: x)
// y == Optional.some(21.25)

let z = Float(exactly: Float16.nan)
// z == nil