Project

General

Profile

Actions

Bug #17205

closed

Misleading error message when comparing NaN with numbers in array

Added by timhwang21 (Tim Hwang) about 4 years ago. Updated about 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-09-30T11:43:19Z master 65e8a29389) [x86_64-darwin19]
[ruby-core:100236]

Description

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).

# .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)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0