Open In App

Ruby | BigDecimal class finite? value

BigDecimal#finite?() : finite?() is a BigDecimal class method which checks whether the BigDecimal value is finite.

Syntax: BigDecimal.finite?()



Parameter: BigDecimal values to check

Return: true – if the value is finite; otherwise false



Code #1 : Example for finite?() method




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

Output :

finite? example 1 : true

finite? example 2 : true

finite? example 3 : true

Code #2 : Example for finite?() method




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

Output :

finite? example 2 : true

finite? example 3 : true

Article Tags :