[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...

Issue #10333 has been updated by Koichi Sasada.

9 messages 2014/10/07

[ruby-core:65896] [ruby-trunk - misc #10424] Error message when sorting NaN

From: cremno@...
Date: 2014-10-25 14:13:00 UTC
List: ruby-core #65896
Issue #10424 has been updated by cremno phobia.


I think `rb_cmperr()` behaves weird anyway. If `y` is a =E2=80=9Cspecial co=
nst=E2=80=9D (e.g. `nil`, `true`, or even a flonum (boxed Float)!), then th=
e 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  # =3D> ArgumentError: comparison of Float with 1.0 =
failed
~~~

It probably would be preferable to print both - value and class. For exampl=
e:

~~~ruby
[0.0/0.0,1.0,2.0].sort  # =3D> ArgumentError: comparison of Float (NaN) wit=
h 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:=20
* Category:=20
* Target version:=20
----------------------------------------
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 Flo=
at 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




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

In This Thread

Prev Next