C Math exp2() Function
Example
Return 2 to the power of different numbers:
printf("%f\n", exp2(3));
printf("%f\n", exp2(10));
printf("%f", 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 <math.h> header file.
Tip: To raise other numbers to a power, use pow().
Syntax
double exp2(double x);
There are also versions for float and long double values: exp2f() and exp2l().
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 C Math Tutorial.