pow()

Description

Calculates the value of a number raised to a power.

pow()
can be used to raise a number to a fractional power. This is useful for generating exponential mapping of values or curves.

Syntax

Use the following function to raise a number to a given power:

pow(base, exponent)

Parameters

The function admits the following parameters:

  • base
    : the function input number to compute. Allowed data types:
    float
    .
  • exponent
    : the power to which the base is raised. Allowed data types:
    float
    .

Returns

The function returns the result of the exponentiation. Data type:

double
.

Example Code

Calculate the value of x raised to the power of y:

1float x = 2.0; // base number
2float y = 10.0; // exponent number
3
4void setup() {
5 Serial.begin(9600);
6
7 double z = pow(x, y);
8
9 Serial.print("The power result is: ");
10 Serial.println(z);
11}
12
13void loop() {
14}

See also

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.