Ruby Tutorial Ruby References

Ruby - Math.exp() Method



The Ruby Math.exp() method returns e raised to the power of specified number, i.e., ex. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282.

Syntax

Math.exp(x)

Parameters

x Specify the exponent of e.

Return Value

Returns e raised to the power of specified number.

Example:

In the example below, Math.exp() method is used to calculate e raised to the power of specified number.

puts "Math.exp(-1) = #{Math.exp(-1)}"
puts "Math.exp(-0.5) = #{Math.exp(-0.5)}"
puts "Math.exp(0) = #{Math.exp(0)}"
puts "Math.exp(0.5) = #{Math.exp(0.5)}"
puts "Math.exp(1) = #{Math.exp(1)}"
puts "Math.exp(2) = #{Math.exp(2)}"

The output of the above code will be:

Math.exp(-1) = 0.36787944117144233
Math.exp(-0.5) = 0.6065306597126334
Math.exp(0) = 1.0
Math.exp(0.5) = 1.6487212707001282
Math.exp(1) = 2.718281828459045
Math.exp(2) = 7.38905609893065

❮ Ruby Math Module