Thursday, September 18, 2025
HomeLanguagesJavascriptp5.js exp() Method

p5.js exp() Method

The exp() function returns the value of n (any number) to the Euler’s number e(2.71828…) raised to the power n (e^n).

Syntax:

exp(n)

Parameters: This method accepts a single parameters n i.e. the number value.

Return Value: It returns (e^n) of the given number.

Example 1: 

Javascript




function setup() {
  
    // Create Canvas of size 270*80
    createCanvas(600, 300);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Initialize the parameter and
    // return the value of the function
    let n = exp(1.1)
    let m = exp(3.3)
      
    // Set the size of text
    textSize(16);
      
    text( "Result in Eular number will be :" + n, 50, 50);
    text( "Result in Eular number will be :" + m, 50, 80);
      
}


Output: Example 2: 

Javascript




function setup() {
  
    // Create Canvas of size 270*80
    createCanvas(600, 500);
}
  
function draw() {
    let x, m;
    let step = 50
     
    // Set the background color
    background(220);
  
    // Initialize the parameter and return
    // the value of the function
    // For loop is set from numbers 0 to 10.
    for( x = 0; x <= 10; x++) {
          
        // The return value of exp() function
        m = exp(x)
        text( "Result for " + x +
             ": " + m, 50, step);
       
        step = step + 30;
      }
      
      // Set the size of text
      textSize(17);
      
      // Set the text color
      fill(color('blue'));
}


Output: Reference: https://p5js.org/reference/#/p5/exp

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11833 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7051 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS