多分、後方互換性を持たせるためにこうなってると思うんですが
0/0
と 0.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?
を使うと覚えておけば問題ないでしょう。