Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Float#infinite?

infinite? → -1, 1, or nil

Returns:

  • 1, if self is Infinity.

  • -1 if self is -Infinity.

  • nil, otherwise.

Examples:

Example
f = 1.0/0.0  # => Infinity
f.infinite?  # => 1
f = -1.0/0.0 # => -Infinity
f.infinite?  # => -1
f = 1.0      # => 1.0
f.infinite?  # => nil
f = 0.0/0.0  # => NaN
f.infinite?  # => nil
See also #hash #inspect #floor #magnitude also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0