📜  红宝石 | BigDecimal 类无限?价值

📅  最后修改于: 2022-05-13 01:54:44.780000             🧑  作者: Mango

红宝石 | BigDecimal 类无限?价值

infinite?()是一个 BigDecimal 类方法,它检查 BigDecimal 值是否是无限的。

示例 #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 :