Forum: Ruby-core [ruby-trunk - Bug #7676][Open] Comparison of Float::NAN in array behaves unexpectedly

F5d7b2efc6cfe5dcc17756c8749ea14c?d=identicon&s=25 simonrussell (Simon Russell) (Guest)
on 2013-01-09 03:11
(Received via mailing list)
Issue #7676 has been reported by simonrussell (Simon Russell).

----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
Bcb6acc9d0d9bef99e033b36c3d32ca9?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-01-09 15:00
(Received via mailing list)
Issue #7676 has been updated by charliesome (Charlie Somerville).

File bug-7676.patch added

=begin
Attached a patch fixing this issue - the pointer equality checks in
(({recursive_equal})) and (({rb_equal})) should not be performed as this
breaks in the case where (({a != a})).

I'm not committing this straight away because it causes three test
failures due to brittle mocks.
=end
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35304

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
205ca9566e14fb669ed977cae5af88e0?d=identicon&s=25 ngoto (Naohisa Goto) (Guest)
on 2013-01-09 15:41
(Received via mailing list)
Issue #7676 has been updated by ngoto (Naohisa Goto).

Status changed from Open to Rejected

duplicate of Bug #1720

See documentation in numeric.c added in r37546
https://bugs.ruby-lang.org/projects/ruby-trunk/rep...

----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35305

Author: simonrussell (Simon Russell)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
F5d7b2efc6cfe5dcc17756c8749ea14c?d=identicon&s=25 simonrussell (Simon Russell) (Guest)
on 2013-01-10 01:22
(Received via mailing list)
Issue #7676 has been updated by simonrussell (Simon Russell).


This isn't just Float::NAN, actually; as Charlie's patch shows, it's
actually any object that always returns false from ==

1.9.3p125 :001 > class X
1.9.3p125 :002?>   def ==(other)
1.9.3p125 :003?>     false
1.9.3p125 :004?>   end
1.9.3p125 :005?> end
 => nil
1.9.3p125 :006 > x = X.new
 => #<X:0x00000000ba1648>
1.9.3p125 :007 > x == x
 => false
1.9.3p125 :008 > [x] == [x]
 => true

Is this desirable behaviour?
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35306

Author: simonrussell (Simon Russell)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
F5d7b2efc6cfe5dcc17756c8749ea14c?d=identicon&s=25 simonrussell (Simon Russell) (Guest)
on 2013-01-10 01:24
(Received via mailing list)
Issue #7676 has been updated by simonrussell (Simon Russell).


At the very least, the documentation for Array#== should be updated to
state that it first does an object identity comparison, then calls ==
only if the objects aren't the same instance.
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35307

Author: simonrussell (Simon Russell)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
40e5e9fe36a1f85166493faac2c17499?d=identicon&s=25 hasari (Hiro Asari) (Guest)
on 2013-01-10 03:19
(Received via mailing list)
Issue #7676 has been updated by hasari (Hiro Asari).


I, too, found documentation still lacking. I read #1720, and I
understand the rationale for the Float::NAN case.

However, the issue still remains as Simon pointed out above. Please
reopen the issue, or update the documentation to reflect the behavior
more closely.
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35309

Author: simonrussell (Simon Russell)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
205ca9566e14fb669ed977cae5af88e0?d=identicon&s=25 ngoto (Naohisa Goto) (Guest)
on 2013-01-10 03:28
(Received via mailing list)
Issue #7676 has been updated by ngoto (Naohisa Goto).

Category set to DOC
Status changed from Rejected to Open


----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35310

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee:
Category: DOC
Target version:
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-01-10 03:31
(Received via mailing list)
Issue #7676 has been updated by mrkn (Kenta Murata).

Assignee set to matz (Yukihiro Matsumoto)
Target version set to next minor

I think this is the specification issue, so we need to confirm the mat'z
thought.
Matz, how do you think about it?

----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35311

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: DOC
Target version: next minor
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
Bcb6acc9d0d9bef99e033b36c3d32ca9?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-01-10 03:39
(Received via mailing list)
Issue #7676 has been updated by charliesome (Charlie Somerville).


=begin
I understand that matz wants (({nan == nan})) to be undefined, but I
think this should remain consistent within a platform, even though it is
undefined between platforms.
=end
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-35312

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: DOC
Target version: next minor
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
233c279c012ebac792aaa805f966cbc7?d=identicon&s=25 steveklabnik (Steve Klabnik) (Guest)
on 2013-08-05 17:51
(Received via mailing list)
Issue #7676 has been updated by steveklabnik (Steve Klabnik).


I would be happy to write a documentation patch for this if Matz can
confirm which behavior is correct.
----------------------------------------
Bug #7676: Comparison of Float::NAN in array behaves unexpectedly
https://bugs.ruby-lang.org/issues/7676#change-40906

Author: simonrussell (Simon Russell)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: doc
Target version: next minor
ruby -v: ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux]
Backport:


It seems that two arrays containing Float::NAN will be considered equal
([Float::NAN] == [Float::NAN]), despite the fact that Float::NAN !=
Float::NAN.

Tested and reproduced in 1.8.7p371, 1.9.3p362, 2.0.0preview2. (This bug
can be reproduced in Ruby 1.8 as well.)  Results below.

1.8.7 p371
---------

1.8.7 :001 > nan = 0.0/0.0
 => NaN
1.8.7 :002 > nan == nan
 => false
1.8.7 :003 > [nan] == [nan]
 => true

1.9.3 p362
---------

1.9.3p362 :001 > Float::NAN == Float::NAN
 => false
1.9.3p362 :002 > [Float::NAN] == [Float::NAN]
 => true

2.0.0 preview2
This topic is locked and can not be replied to.