LoginSignup
12
0

More than 5 years have passed since last update.

x == x が false になることはあるか

Posted at

Ruby についての問題です。

以下の条件のもとで x == xfalse になることはあるか。

  • x は左辺・右辺ともローカル変数である
  • x には組込みクラスのインスタンスが代入されている
  • == は再定義されていない

答えはここをめくってね
ある。x に NaN が代入されているとき。
NaN は Float のインスタンスであり,0.0/0.0 のような計算不能な演算の結果として得られるオブジェクト。そのため,たとえ自分自身とでも「数値的に等しい」とは言えない。

12
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
0