Bug #15432

Float の NaN のみを含む配列比較のテスト

Added by shuujii (Shuji KOBAYASHI) over 1 year ago. Updated about 1 year ago.

Target version:
ruby -v:
ruby 2.6.0rc2 (2018-12-15 trunk 66408) [x86_64-linux]


Float の NaN のみを含む配列比較のテストが以下にあります。

## spec/ruby/core/array/equal_value_spec.rb:47

# As per bug #1720
it "returns false for [NaN] == [NaN]" do
  [nan_value].should_not == [nan_value]

しかし、これは #1720 で未定義動作とするとなったと思うので不要ではないでしょうか。


[Float::NAN] == [Float::NAN]  #=> true
[Float::NAN] == [0/0.0]       #=> false

Updated by jeremyevans0 (Jeremy Evans) about 1 year ago

I agree that keeping this spec does not make sense. If nobody objects within the next week, I will delete the spec.


Updated by jeremyevans (Jeremy Evans) about 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|a0af60c7f2d852faa6d3263874224dd7950bda43.

Remove spec testing undefined behavior

Fixes [Bug #15432]

Updated by Eregon (Benoit Daloze) about 1 year ago

It makes sense in the context of #1720.

I.e., all Ruby implementations behave that way, because Float::NAN.equal? Float::NAN must be true, and Array#== uses an #equal? + a #== check, not just #==. I want to restore the spec and add that explanation.

IMHO there is no "undefined behavior" in Ruby, there is MRI behavior and that's what other Ruby implementations have to comply to, unless proven a bug or desirable to differ.

Updated by Eregon (Benoit Daloze) about 1 year ago

Actually, the should_not above indeed doesn't make much sense, because it relies on nan_value returning different NaNs, which is probably platform-specific.

I added a spec for this case: [Float::NAN].should == [Float::NAN].

Also available in: Atom PDF