pow is a function that exists in various programming languages that usually takes two numbers as input and returns the first number to the power of the second number. DO NOT USE THIS TAG for questions relating to the Rack server, use [rack-pow] instead.
The pow(...)
function is a mathematical function commonly featured in most programming language libraries. The pow
function represents exponentiation. It takes in two numerical arguments a, b
, and returns another numerical value, a
to the power of b
.
In mathematical notation, we write ab, or if space isn't enough, a^b
using the caret. Note that the caret operator may indicate bitwise XOR notation instead. Some languages use the double-asterisk operator **
as an equivalent to pow(a,b)
.
Usages:
- C/C++:
double pow(double x, double y)
- Including a header
<math.h>
is required for C/C++. powf
is for floats,powl
is for long doubles.
- Including a header
- Erlang:
math:pow(X, Y)
- Java:
Math.pow(double x, double y)
, returns double - JavaScript:
Math.pow(number, number)
(note all JS numbers are floating-pointnumber
type) - C#:
double Pow(double x, double y)
(capitalPow
) - Python:
math.pow(x, y)
(Equivalent tox**y
, but it converts both arguments to floating-point values unlike**
).
Equivalent notations
- Lua, Mathematica:
x ^ y
(^
could mean bitwise OR in other languages) - Python, Ruby:
x ** y
- Python also have a three-argument
pow(x, y, z)
, which computesx**y modulo z
.
- Python also have a three-argument
Special Cases:
Pow(0,0)
means zero to the power of zero. Technically, it is undefined, but some implementations return 1, such as Java. Others may return NaN or even incur undefined behavior.Pow(x,1)
sometimes returnsx
regardless of what valuex
isPow(x,0)
andPow(x,±Infinity)
can result in±0
or±Infinity
based on mathematical result and the signs of the arguments.Pow(1,±Infinity)
can result in NaN.
Related tags:
- exponentiation: What
pow
means - math, math.h, standard-library:
pow(...)
is often a standard library function. - xor, bitwise-xor: The caret (
^
) symbol often meanspow
aka exponentiation, but it could also mean bitwise XOR.
References:
- Wikipedia: https://en.wikipedia.org/wiki/Exponentiation#In_programming_languages (More examples)
- C/C++: http://www.cplusplus.com/reference/cmath/pow/
- C#: https://msdn.microsoft.com/en-us/library/system.math.pow(v=vs.110).aspx (Includes F# and VB usages)
- Erlang: http://erlang.org/doc/man/math.html
- Java: https://docs.oracle.com/javase/10/docs/api/java/lang/Math.html (See the pow section)
- JavaScript: https://www.w3schools.com/jsref/jsref_pow.asp
- Lua: https://www.lua.org/pil/3.1.html
- Mathematica: http://reference.wolfram.com/language/tutorial/TypingPowers.html
- Python2: https://docs.python.org/2/library/functions.html, https://docs.python.org/2/library/math.html?highlight=pow#math.pow
- Python3: https://docs.python.org/3/library/functions.html, https://docs.python.org/3/library/math.html?highlight=pow#math.pow
- Ruby: https://www.techotopia.com/index.php/Ruby_Operators