ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: timhwang21@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100236] [Ruby master Bug#17205] Misleading error message when comparing NaN with numbers in array
Date: Wed, 30 Sep 2020 13:14:37 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-17205.20200930131436.44722@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17205.20200930131436.44722@ruby-lang.org

Issue #17205 has been reported by timhwang21 (Tim Hwang).

----------------------------------------
Bug #17205: Misleading error message when comparing NaN with numbers in array
https://bugs.ruby-lang.org/issues/17205

* Author: timhwang21 (Tim Hwang)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-09-30T11:43:19Z master 65e8a29389) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
The closest issue I could find is this: https://bugs.ruby-lang.org/issues/10424

There is quite a lot of inconsistency when dealing with arrays containing `NaN`, dependent on 1) if comparing against an integer or a float, 2) order of comparison. The one that stands out to me as "least correct" is the last one (`[Float::NAN, 1.0].min`) which raises `TypeError (no implicit conversion from nil to integer)`.

``` ruby
# .sort
[1, Float::NAN].sort
# Most sensible error message
# ArgumentError (comparison of Integer with NaN failed)

[1.0, Float::NAN].sort
# Somewhat sensible error message
# TypeError (no implicit conversion from nil to integer)

[Float::NAN, 1].sort
# Somewhat sensible error message
# TypeError (no implicit conversion from nil to integer)

[Float::NAN, 1.0].sort
# Somewhat sensible error message
# TypeError (no implicit conversion from nil to integer)

# .min
[1, Float::NAN].min
# Most sensible error message
# ArgumentError (comparison of Float with 1 failed)

[1.0, Float::NAN].min
# Somewhat sensible error message
# TypeError (no implicit conversion from nil to integer)

[Float::NAN, 1].min
# Most sensible error message
# ArgumentError (comparison of Integer with NaN failed)

[Float::NAN, 1.0].min
# Very misleading error message
# TypeError (no implicit conversion from nil to integer)
```




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

       reply	other threads:[~2020-09-30 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 13:14 timhwang21 [this message]
2020-09-30 13:17 ` [ruby-core:100237] [Ruby master Bug#17205] Misleading error message when comparing NaN with numbers in array timhwang21
2020-10-01  2:38 ` [ruby-core:100246] " shyouhei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-17205.20200930131436.44722@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).