红宝石 |数字无穷大?函数
如果数字是有限的, infinite?()是 Ruby 中的一个内置方法,它返回 nil。如果数字是 -infinity 或 +infinity,则返回 -1 和 +1。
Syntax: num.infinite?()
Parameters: The function needs a number which is to be checked.
Return Value: It returns nil, -1 or +1.
示例 1 :
# Ruby program for infinite?
# method in Numeric
# Initialize a number
num1 = 12
# Prints Imaginary number
puts num1.infinite?()
输出:
示例 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?()
输出:
1
-1