Project

General

Profile

Actions

Feature #11918

closed

Make #finite? consistent with #nonzero?

Added by avit (Andrew Vit) over 8 years ago. Updated over 8 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:72582]

Description

Calling .nonzero? on a number returns itself (truthy) or nil, but calling .finite? on a float is just true or false.

Floats can produce Infinity without errors and cause downstream errors if that result is unexpected. This would be nice to have:

top, bottom = 9.9, 0.0
(top / bottom).finite? or raise DivisionByZero
(top / bottom).finite? || 0.0

(9.9 / 2.0).finite? #=> 0.5
(9.9 / 0.0).finite? #=> nil

These semantics would let the user handle the desired behaviour immediately in place.

Actions

Also available in: Atom PDF

Like0
Like0Like0