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
require 'bigdecimal'
a = 42 . 1 ** 13
b = -BigDecimal( "10" )
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
require 'bigdecimal'
b = BigDecimal( '10' )-( 22 ** 7 . 1 ) ** 10
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
Last Updated :
08 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...