Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Float#infinite?

() -> ::Integer?
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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0