Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c++
communitycreator

What is the exp2() function in C++?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The exp2() function is used to return the base-2 exponential function of a given parameter value, x.

Mathematically, exp2() is given as follows:

exp2(x) = 2x2^{x}

Note: The base-2 exponential function simply means 2x2^{x}.

Syntax

double exp2(double x);
float exp2(float x);
long double exp2(long double x);

Parameters

This function takes a single parameter x, which is a number that can be positive, negative, or zero.

Return value

The exp2() function returns the value of numbers within 0 and ∞.

Example

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// creating our variables
double x = -5.5, result;
// using the exp2() function
result = exp2(x);
cout << "exp2(-5.5) = " << result << endl;
return 0;
}
Implementing the exp2() function

Explanation

  • Line 9: We create the variables x and result.

  • Line 12: We implement the exp2() function on the x variable and assign the output to the result variable.

  • Line 13: We print the result variable.

RELATED TAGS

c++
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring