Ruby | BigDecimal class power value

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

power value of b : -0.1E4

Code #2 : Example for power() method

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

power value of b : 0.16E10

power value of c : 0.9E1
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.