Ruby | BigDecimal class power value
Last Updated :
08 Jan, 2020
BigDecimal#power() : power() is a BigDecimal class method which returns the BigDecimal value raised to the power of n.
Syntax: BigDecimal.power()
Parameter: BigDecimal values to find the power the value
Return:
n – value raised to the power of n
prec – precision
Code #1 : Example for power() method
require 'bigdecimal'
a = 42 . 1 ** 13
b = -BigDecimal( "10" )
puts "power value of b : #{b.power(3, 4)}\n\n"
|
Output :
power value of b : -0.1E4
Code #2 : Example for power() method
require 'bigdecimal'
b = BigDecimal( "200" )
c = BigDecimal( '-3' )
puts "power value of b : #{b.power(4)}\n\n"
puts "power value of c : #{c.power(2)}\n\n"
|
Output :
power value of b : 0.16E10
power value of c : 0.9E1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...