Issue #10424 has been updated by cremno phobia.


I think `rb_cmperr()` behaves weird anyway. If `y` is a °»special const°… (e.g. `nil`, `true`, or even a flonum (boxed Float)!), then the result of `#inspect`, and not the class, is used. So the error message I get, is different from yours!

~~~ruby
[0.0/0.0,1.0,2.0].sort  # => ArgumentError: comparison of Float with 1.0 failed
~~~

It probably would be preferable to print both - value and class. For example:

~~~ruby
[0.0/0.0,1.0,2.0].sort  # => ArgumentError: comparison of Float (NaN) with Float (1.0) failed
~~~


----------------------------------------
misc #10424: Error message when sorting NaN
https://bugs.ruby-lang.org/issues/10424#change-49637

* Author: Jason Thomas
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
When sorting an array of floats with a NaN you get a very confusing message:
irb(main):001:0> [0.0/0.0,1.0,2.0].sort
ArgumentError: comparison of Float with Float failed

Sorting a nil is much friendlier:
irb(main):012:0> [nil,1.0,2.0].sort
ArgumentError: comparison of NilClass with Float failed

This is confusing for many. Simply google for "comparison of Float with Float failed" and makes for a difficult debugging session for anyone who doesn't know that NaN produces this result. What I would expect is:
irb(main):001:0> [0.0/0.0,1.0,2.0].sort
ArgumentError: comparison of NaN with Float failed




-- 
https://bugs.ruby-lang.org/