Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Numeric infinite? function

  • Last Updated : 06 Jan, 2020

The infinite?() is an inbuilt method in Ruby returns nil if the number is finite. It returns -1 and +1 if the number is -infinity or +infinity.

Syntax: num.infinite?()

Parameters: The function needs a number which is to be checked.

Return Value: It returns nil, -1 or +1.

Example 1:






# Ruby program for infinite?
# method in Numeric
  
# Initialize a number 
num1 = 12
  
# Prints Imaginary number
puts num1.infinite?()

Output:


Example 2:




# Ruby program for infinite?
# method in Numeric
  
# Initialize a number 
num1 = 12/0.0
num2 = -12/0.0
  
# Prints Imaginary number
puts num1.infinite?()
puts num2.infinite?()

Output:

1
-1
My Personal Notes arrow_drop_up
Recommended Articles
Page :