Project

General

Profile

Actions

Feature #12039

closed

Fixnum#infinite?/Bignum#infinite or Numeric#infinte, consistent with Float#infinite? and BigDecimal#infinite?

Added by ioquatix (Samuel Williams) almost 9 years ago. Updated about 8 years ago.

Status:
Closed
Target version:
-
[ruby-core:73618]

Description

We have an issue where it is not easy to ask if a number is +ve or -ve infinity. https://github.com/rails/arel/issues/411

Both Float and BigDecimal do respond to infinite? but Integer derivatives don't. It sort of makes sense, since we don't have an infinity value for Fixnum/Bignum. However, it makes polymorphic code hard.

[13] pry(main)> Float::INFINITY.infinite?                                       
=> 1
[14] pry(main)> -Float::INFINITY.infinite?                                      
=> -1
[15] pry(main)> BigDecimal::INFINITY.infinite?                                  
=> 1
[16] pry(main)> -BigDecimal::INFINITY.infinite?                                 
=> -1

Given a Numeric value x, it would be nice to query if it is INFINITY or not. Propose adding a default implementation to Numeric, which always returns false or nil.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #10641: Introduce Fixnum#finite? and Bignum#finite?ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0