What is the exp() method in Dart?

exp() is a dart:math package function that returns the natural exponent, ee, to the power of a specified number.

Syntax

The syntax of the exp() method is as follows:

double exp(num x)

Parameters

  • num x: A mandatory numerical value that serves as the power to which the natural exponent, ee, is raised.

Return value

exp() returns the natural exponent, ee, raised to the power of x. The result is returned as a double.

exp() returns NaN (Not-A-Number) if x is also NaN.

Code

In the code below, we will demonstrate the use of the exp() method:

// Importing the dart math package
import "dart:math";
// Main function
void main(){
// Not NaN values or real values
double no1 = 4.00; // Real Number
double no2 = 100.00; // Real Number
double no3 = 3.50; // Real Number
// NaN Values
double no4 = 0/0; // NaN
double no5 = pow(-2, 0.5); // NaN
// Print values returned by the exp() function
print(exp(no1));
print(exp(no2));
print(exp(no3));
print(exp(no4));
print(exp(no5));
}

Explanation

In the code above, we call the exp() method with both numerical and NaN arguments.

The function calls to the exp() method in lines 17āˆ’1917-19 return the value of the natural exponent, ee, raised to the power of the provided parameter.

On the other hand, the function calls in lines 20āˆ’2120-21 provide NaN as the argument, so the exp() method also returns NaN.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
šŸ† Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources