---
title: "Ruby 2.4 adds infinite? and finite? methods to Numeric"
description:
  "Fixnum#infinite?/Bignum#infinite? and Numeric#finite?/Bignum#finite? methods
  are now consistent with Float#infinite?/BigDecimal#infinite?"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-4-adds-infinite-method-to-numeric"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-4-adds-infinite-method-to-numeric.md"
---

# Ruby 2.4 adds infinite? and finite? methods to Numeric

Fixnum#infinite?/Bignum#infinite? and Numeric#finite?/Bignum#finite? methods are
now consistent with Float#infinite?/BigDecimal#infinite?

- Author: Abhishek Jain
- Published: December 19, 2016
- Categories: Ruby 2.4, Ruby

### Prior to Ruby 2.4

Prior to Ruby 2.4, Float and BigDecimal responded to methods `infinite?` and
`finite?`, whereas Fixnum and Bignum did not.

#### Ruby 2.3

```ruby
#infinite?

5.0.infinite?
=> nil

Float::INFINITY.infinite?
=> 1

5.infinite?
NoMethodError: undefined method `infinite?' for 5:Fixnum

```

```ruby
#finite?

5.0.finite?
=> true

5.finite?
NoMethodError: undefined method `finite?' for 5:Fixnum

```

#### Ruby 2.4

To make behavior for all the numeric values to be consistent,
[infinite? and finite? were added to Fixnum and Bignum](https://bugs.ruby-lang.org/issues/12039)
even though they would always return nil.

This gives us ability to call these methods irrespective of whether they are
simple numbers or floating numbers.

```ruby
#infinite?

5.0.infinite?
=> nil

Float::INFINITY.infinite?
=> 1

5.infinite?
=> nil

```

```ruby
#finite?

5.0.finite?
=> true

5.finite?
=> true

```

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-4-adds-infinite-method-to-numeric)
