Open In App

Ruby | Numeric infinite? function

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
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
# Ruby program for infinite?
# method in Numeric

# Initialize a number 
num1 = 12

# Prints Imaginary number
puts num1.infinite?()
Output:

Example 2: Ruby
# 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

Next Article

Similar Reads