Ruby | Numeric infinite? function
Last Updated :
19 Mar, 2024
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:
num1 = 12
puts num1.infinite?()
|
Output:
Example 2:
num1 = 12 / 0 . 0
num2 = - 12 / 0 . 0
puts num1.infinite?()
puts num2.infinite?()
|
Output:
1
-1
Share your thoughts in the comments
Please Login to comment...