红宝石 | BigDecimal 类有限?价值
BigDecimal#finite?() :finite?()是一个 BigDecimal 类方法,用于检查 BigDecimal 值是否是有限的。
Syntax: BigDecimal.finite?()
Parameter: BigDecimal values to check
Return: true – if the value is finite; otherwise false
代码 #1:finite?() 方法的示例
# Ruby code for finite?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
a = 42.1**13
# declaring BigDecimal
b = -BigDecimal("10")
# declaring BigDecimal
c = -(22 ** 7.1) * 10
puts "finite? example 1 : #{a.finite?()}\n\n"
puts "finite? example 2 : #{b.finite?()}\n\n"
puts "finite? example 3 : #{c.finite?()}\n\n"
输出 :
finite? example 1 : true
finite? example 2 : true
finite? example 3 : true
代码 #2:finite?() 方法的示例
# Ruby code for finite?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring BigDecimal
c = BigDecimal('-3')
puts "finite? example 2 : #{b.finite?()}\n\n"
puts "finite? example 3 : #{c.finite?()}\n\n"
输出 :
finite? example 2 : true
finite? example 3 : true