Ruby | Math exp() function

The exp() function in Ruby returns the value of e^value. It takes value in range [-inf, +inf] and returns the answer in range [0, infinity].

Syntax: Math.exp(value)

Parameter: The function takes the value which is to be raised to the power of e.



Return Value: The function returns the value of e^value.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for exp() function 
  
# Assigning values
val1 = 0.98
val2 = -0.9
val3 = 6
val4 = 1
  
# Prints the exp() value 
puts Math.exp(val1)
puts Math.exp(val2)
puts Math.exp(val3)
puts Math.exp(val4)

chevron_right


Output:

2.664456241929417
0.4065696597405991
403.4287934927351
2.718281828459045

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for exp() function 
  
# Assigning values
val1 = 0.67
val2 = -0.12
val3 = 2.4
val4 = 89
  
  
# Prints the exp() value 
puts Math.exp(val1)
puts Math.exp(val2)
puts Math.exp(val3)
puts Math.exp(val4)

chevron_right


Output:

1.9542373206359396
0.8869204367171575
11.023176380641601
4.4896128191743455e+38

Reference: https://devdocs.io/ruby~2.5/math#method-c-exp



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.