红宝石 | BigDecimal 类无限?价值
infinite?()是一个 BigDecimal 类方法,它检查 BigDecimal 值是否是无限的。
Syntax: BigDecimal.infinite?()
Parameter: BigDecimal values to check
Return: nil : if value is finite
-1 : if value is -ve infinite
+1 : if value is +ve infinite
示例 #1:
# Ruby code for infinite?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
a = 42.1**13/0
# declaring BigDecimal
b = -BigDecimal("10")
# declaring BigDecimal
c = -(22 ** 7.1) * 10/0
puts "infinite? example 1 : #{a.infinite?()}\n\n"
puts "infinite? example 2 : #{b.infinite?()}\n\n"
puts "infinite? example 3 : #{c.infinite?()}\n\n"
输出 :
infinite? example 1 :
infinite? example 2 :
infinite? example 3 :
示例 #2:
# Ruby code for infinite?() method
# loading BigDecimal
require 'bigdecimal'
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
# declaring BigDecimal
c = BigDecimal('-3')
puts "infinite? example 2 : #{b.infinite?()}\n\n"
puts "infinite? example 3 : #{c.infinite?()}\n\n"
输出 :
infinite? example 2 :
infinite? example 3 :