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
# Ruby code for power() method # loading BigDecimalrequire 'bigdecimal' # declaring BigDecimala = 42.1**13 # declaring BigDecimalb = -BigDecimal("10") # bputs "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 BigDecimalrequire 'bigdecimal' # declaring BigDecimalb = BigDecimal("200") # declaring BigDecimalc = BigDecimal('-3') # POWER puts "power value of b : #{b.power(4)}\n\n" # cputs "power value of c : #{c.power(2)}\n\n" |
Output :
power value of b : 0.16E10 power value of c : 0.9E1


