Open In App

Ruby | BigDecimal class power value

Last Updated : 08 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




# Ruby code for power() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
a = 42.1**13
  
# declaring BigDecimal
b = -BigDecimal("10")
  
  
# b
puts "power value of b : #{b.power(3, 4)}\n\n"
     


Output :

power value of b : -0.1E4

Code #2 : Example for power() method




# Ruby code for power() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
b = BigDecimal("200")
  
# declaring BigDecimal
c = BigDecimal('-3')
  
# POWER 
puts "power value of b : #{b.power(4)}\n\n"
  
# c
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

Similar Reads