- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding the Base-e Exponential of Given Number in Golang
In mathematics, the exponential function is a function that grows at a rate proportional to its current value. The base-e exponential function, also known as the natural exponential function, is defined as e raised to the power of a given number, where e is a mathematical constant approximately equal to 2.71828. In Golang, you can easily find the base-e exponential of a given number using the math.Exp() function.
Syntax
The syntax of math.Exp() function is as follows −
func Exp(x float64) float64
where x is the number whose base-e exponential needs to be found. The function returns the base-e exponential of the given number.
Example 1: Finding Base-e Exponential of a Positive Number
In the following example, we will find the base-e exponential of a positive number using the math.Exp() function −
package main import ( "fmt" "math" ) func main() { x := 2.5 result := math.Exp(x) fmt.Printf("The base-e exponential of %f is %f", x, result) }
Output
The base-e exponential of 2.500000 is 12.182494
Example 2: Finding Base-e Exponential of a Negative Number
In the following example, we will find the base-e exponential of a negative number using the math.Exp() function −
package main import ( "fmt" "math" ) func main() { x := -3.8 result := math.Exp(x) fmt.Printf("The base-e exponential of %f is %f", x, result) }
Output
The base-e exponential of -3.800000 is 0.022371
Example 3: Finding Base-e Exponential of Zero
In the following example, we will find the base-e exponential of zero using the math.Exp() function −
package main import ( "fmt" "math" ) func main() { x := 0.0 result := math.Exp(x) fmt.Printf("The base-e exponential of %f is %f", x, result) }
Output
The base-e exponential of 0.000000 is 1.000000
Conclusion
In this article, we learned how to find the base-e exponential of a given number using the math.Exp() function in Golang. We also saw three examples that illustrate how to use the function to find the base-e exponential of positive, negative, and zero values. The math.Exp() function is a useful tool for mathematical calculations involving exponential growth or decay.