We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigDecimal.new("NaN")
$ ruby -v ruby 2.4.0preview3 (2016-11-07 trunk 56661) [x86_64-darwin14]
irb(main):001:0> require "bigdecimal" => true irb(main):002:0> nan = BigDecimal.new("NaN") => #<BigDecimal:7ff5f213bad8,'NaN',9(9)> irb(main):003:0> h = {nan => 1000} => {#<BigDecimal:7ff5f213bad8,'NaN',9(9)>=>1000} irb(main):004:0> h[BigDecimal.new("NaN")] => nil irb(main):005:0> h[nan] => 1000
I expected h[nan] to return nil, because nan.eql? nan returns false. This is because hash compare pointers first. https://github.com/ruby/ruby/blob/v2_4_0_preview3/hash.c#L99-L102
h[nan]
nil
nan.eql? nan
false
The text was updated successfully, but these errors were encountered:
NaN is difficult even if it is a Float.
irb(main):001:0> a = Float::NAN => NaN irb(main):002:0> b = 0.0 / 0.0 => NaN irb(main):003:0> c = Float::INFINITY * 0.0 => NaN irb(main):004:0> h = { a => 1, b => 2, c => 3 } => {NaN=>1, NaN=>2, NaN=>3} irb(main):005:0> h[a] => 1 irb(main):006:0> h[b] => 2 irb(main):007:0> h[c] => 3
Sorry, something went wrong.
IMO at least we need to discuss how to define the equivalence of NaN including Float rather than only BigDecimal in bugs.ruby-lang.org.
https://bugs.ruby-lang.org/issues/13146 discusses about Float NaN.
https://bugs.ruby-lang.org/issues/13146 was rejected.
No branches or pull requests
I expected
h[nan]
to returnnil
, becausenan.eql? nan
returnsfalse
.This is because hash compare pointers first.
https://github.com/ruby/ruby/blob/v2_4_0_preview3/hash.c#L99-L102
The text was updated successfully, but these errors were encountered: