5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

0/0 と 0.0/0 は違います。

Posted at

多分、後方互換性を持たせるためにこうなってると思うんですが

0/00.0/0 はRubyにおいて違う表現になります。

前者はZeroDivisionError: divided by 0を起こしますが、後者はFloatとして計算されるためにNaN(Not a Number) になります。

[120] pry(main)> (0.0/0.0).nan?
=> true

な感じでNaNかどうかの確認もできます。

ちなみに

0.0/0 == Float::NAN
=> false

になります。私にはなんでかわかりませんが比較にはnan?を使うと覚えておけば問題ないでしょう。

5
5
7

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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?