Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | BigDecimal class infinite? value

  • Last Updated : 08 Jan, 2020

infinite?() is a BigDecimal class method which checks whether the BigDecimal value is infinite.

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

Example #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"   

Output :

infinite? example 1 : 

infinite? example 2 : 

infinite? example 3 : 

Example #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"

Output :

infinite? example 2 : 

infinite? example 3 : 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!