C++ cmath exp2() Function
Example
Return 2 to the power of different numbers:
cout << exp2(3) << "\n";
cout << exp2(10) << "\n";
cout << exp2(-1);
Definition and Usage
The exp2() function returns 2 to the power of x (2x).
For example, exp2(3) is 2 * 2 * 2, which is 8. A negative power divides instead, so exp2(-1) is 0.5.
The exp2 function is defined in the <cmath> header file.
Tip: To raise other numbers to a power, use pow().
Syntax
exp2(double x)
The function also works with float and long double values. Then it returns a value of the same type.
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. The power to raise 2 to. |
Technical Details
| Returns: | A double value with 2 to the power of x. |
|---|
Related Pages
Read more about math in our Math Tutorial.