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

pow(base, exponent)

Parameter Values

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

Return Values

  • The result of the exponentiation. Data type: double.

Example Code

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

void setup() { Serial.begin(9600); int x = 2; int y = 3; double z = pow(x, y); Serial.print(x); Serial.print(" raised to the power of "); Serial.print(y); Serial.print(" is "); Serial.println(z); } void loop() {}

The result in Serial Monitor:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
2 raised to the power of 3 is 8.00
Ln 11, Col 1
Arduino Uno on COM15
2

See the (fscale) sketch for a more complex example of the use of pow().

See Also

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

※ OUR MESSAGES