Initializer

init(exactly:)

Creates a new instance initialized to the given value, if it can be represented without rounding. それが丸めなしに表されるならば、与えられた値に初期化される新しいインスタンスを作成します。

Declaration 宣言

init?(exactly other: Float)

Parameters パラメータ

other

The value to use for the new instance. 新しいインスタンスのために使う値。

Discussion 解説

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. otherFloatのインスタンスとして表されることが丸めることなしには可能でないならば、このイニシャライザの結果はnilです。とりわけ、NaNをotherとして渡すことは常にnilの結果となります。


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


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

See Also 参照

Converting with No Loss of Precision 精度の損失なしに変換する