Type Property 型プロパティ

nan

A quiet NaN (“not a number”). クワイエットNaN(非数)。

Declaration 宣言

static var nan: Self { get }

Discussion 解説

A NaN compares not equal, not greater than, and not less than every value, including itself. Passing a NaN to an operation generally results in NaN. NaNは、それ自身を含めてあらゆる値に対して等しくない、大きくない、少なくないと比較されます。NaNをある演算に渡すことは、一般的にNaNという結果になります。


let x = 1.21
// x > Double.nan == false
// x < Double.nan == false
// x == Double.nan == false

Because a NaN always compares not equal to itself, to test whether a floating-point value is NaN, use its isNaN property instead of the equal-to operator (==). In the following example, y is NaN. NaNは常にそれ自身に対して等しくないと比較されることから、浮動小数点値がNaNかどうかテストするには、それのisNaNプロパティを同等演算子(==)の代わりに使ってください。以下の例において、yはNaNです。


let y = x + Double.nan
print(y == Double.nan)
// Prints "false"
print(y.isNaN)
// Prints "true"