Project

General

Profile

Bug #14014

NaN.finite?

Added by marcandre (Marc-Andre Lafortune) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
2.4.2
[ruby-core:83272]

Description

Ruby gives contradictory answers for NaN:

> (0/0.0).finite?
 => false 
> Complex(0/0.0, 0).finite?
 => true 

Note that (0/0.0).infinite? returns nil, so the float answer of false looks even more wrong.

The two solutions I see are either changing Float#finite? to return true for NaN, or to raise in both cases.

I'd lean towards raising in both cases, as NaN can not be said to be finite or infinite

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Status changed from Open to Rejected

NaN is not a (either infinite or finite) number, definitely.
Also it is not positive nor negative, so its signedness is nonsense too.
Complex(0/0.0, 0).finite? returns false in the trunk already.

Updated by Eregon (Benoit Daloze) over 2 years ago

Has this been backported to the 2.4 branch? I think it should.
What commit fixed it?

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

Not yet, it's r60040.

Updated by marcandre (Marc-Andre Lafortune) over 2 years ago

Thanks, sorry I should have tested trunk.

Updated by Eregon (Benoit Daloze) over 2 years ago

Should this be marked as closed rather than rejected and a test be added for NaN for the backport to be performed then?

#6

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN to 2.3: DONTNEED, 2.4: REQUIRED
  • Status changed from Rejected to Closed

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

  • Backport changed from 2.3: DONTNEED, 2.4: REQUIRED to 2.3: DONTNEED, 2.4: DONE

ruby_2_4 r62173 merged revision(s) 60040,60188.

Also available in: Atom PDF