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