Project

General

Profile

Actions

Misc #10424

open

Error message when sorting NaN

Added by jmthomas (Jason Thomas) about 10 years ago. Updated about 10 years ago.

Status:
Open
Assignee:
-
[ruby-core:65893]

Description

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

Actions

Also available in: Atom PDF

Like0
Like0