红宝石 |数值有限?()函数
finite?()是 Ruby 中的一个内置方法,它返回一个布尔值。如果数字是有限的,则返回 true,否则返回 false。
Syntax: num.finite?()
Parameters: The function needs a number which is to be checked for.
Return Value: It returns returns a boolean value.
示例 1 :
# Ruby program for finite?()
# method in Matrix
# Initialize a number
num1 = 15
# Prints finite or not
puts num1.finite?()
输出:
true
示例 2 :
# Ruby program for finite?()
# method in Matrix
# Initialize a number
num1 = 1/0.0
# Prints finite or not
puts num1.finite?()
输出:
false