Questions tagged [pow]

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.
  • 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-point number type)
  • C#: double Pow(double x, double y) (capital Pow)
  • Python: math.pow(x, y) (Equivalent to x**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 computes x**y modulo z.

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 returns x regardless of what value x is
  • Pow(x,0) and Pow(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:

References:

695 questions
-4
votes
1 answer

Why is this instance of dynamic allocation not successful?

I am trying to create a program that raises 10 to the power of the index number (1 for index 0, 10 for index 1, 100 for index 2, etc.). When I run this program, it does not output anything. What is the…
-4
votes
1 answer

c language math library error when compiling (pow)

I pasted the wrong error in my question by mistake. Now I have fixed my question. I'm having a problem compiling a program I wrote using math.h library. I can compile the program in my computer with visual 08 and codeblocks, but then I try to use my…
Kakarotto
  • 65
  • 7
-4
votes
2 answers

pow function in C not working as intended

I have the following equation I need to represent in C: 20 * 2^((1-x)/5) my c representation is as follows, but it seems like the pow function is always returning a high integer value (1073741824) with my n values ranging from 1-5. double x = 20 *…
Clarko
  • 103
  • 5
-4
votes
1 answer

How does changing position of format specifiers change the output of a c program?

My code is: #include #include int main() { int c = pow(3,2); printf("%f %f %d \n\n",pow(3,2),c,c); printf("%f %d %f \n\n",pow(3,2),c,c); return 0; } The output is: 9.000000 0.000000 4200688 9.000000 …
-4
votes
2 answers

Return powf result to main function C Programming

I'm trying to make a separate function that takes parameters x and y from the main function use use it in the powf, assign it to a variable 'result' and output it to the main function. Any help is appreciated #include #include…
Adi
  • 9
  • 7
-4
votes
2 answers

why pow function of math.h return infinity value?

I Want to Calculate x^y. x is -0.726354 and y is 0.954. So, I Using pow Function. but return infinity value. how to calculate when x value is negative. Please Answer to me. Thanks.
user1320165
  • 331
  • 1
  • 3
  • 8
-4
votes
3 answers

Python - 0**0 == 1?

I was playing around with ** operator, and noticed that: 0**0 == 1 And pow(0, 0) == 1 And even math: math.pow(0, 0) == 1 And Google! (search for 0**0) Why is it so? As far as I know 0**0 is undefined
JadedTuna
  • 1,783
  • 2
  • 18
  • 32
-4
votes
2 answers

Using pow in php

Hi can I use pow instead of writing it like this? $round1 = $max / 2; $round2 = $round1 + ($max / 2 / 2); $round3 = $round2 + ($max / 2 / 2 / 2); $round4 = $round3 +…
Karim Ali
  • 61
  • 2
  • 10
-4
votes
1 answer

how would I convert the sqrt(x2 − x1)^2 (y2 − y1)^2 to proper java code

How would I convert the equation for the distance between two points: sqrt((x2 − x1)^2 + (y2 − y1)^2) into proper Java code?
-5
votes
3 answers

Read N and print following: 2,4 (2numbers); 3,9,27 (3 numbers)

i need help for coding a program which is read N and will do following: if n numbers given program will print n, n^2, n^3. For example if user (or variable) 5; program output will be like this: n=5 output: 2 4 3 9 27 4 16 64 256 5 25 125 625 3125 …
kadir
  • 29
  • 6
-5
votes
1 answer

BIZZARE OUTPUT. SHOULDN'T OUTPUT BE 153 INSTEAD OF 152

int main() { char arr[3]={'1','5','3'}; int sum=0; for (int i=0;i<3;i++) { sum+=pow((arr[i]-48),3); printf("%d to the power 3 is: %f\n",arr[i]-48,pow((arr[i]-48),3)); } printf("sum is %d\n",sum); } Expected Output: 1 to the…
CS Learner
  • 231
  • 2
  • 11
-5
votes
2 answers

Java for loop I want to print the result the same way that i print the numbers that i use

I want to print the result the same way that i print the numbers that i use. for ex i print 1,2,3,4 2,3,4,5 but the pow remains the same 1024,1024,1024,1024. public static void main(String[] args) { int d = 0, e = 0; double c = 0; for…
Koon
  • 1
  • 3
-5
votes
1 answer

why does Pow function return unexpected values..?

#include #include #include using namespace std; int main() { int i; i = 2; printf("%d %d %d\n", i,pow(i,2),pow(i,3)); return 0; } /* I expect the output to be 2,4,8.But the output shown is 2 0…
-5
votes
1 answer

Large mathematical operation c++

I want large mathematical operation in c++. long long h= 4294967295; long long d=7910266469; long long n=10021211227; long long result; I am need calculate this is: h^d mod n result=pow(h,d) % n; I dont know which type using.Please help me for…
-5
votes
1 answer

Implement pow(x,n)%d with integers only. (without making use of library functions)

Basically I used the classic divide and conquer whenever the exponent is even and came up with this. int mymod(int a,int b){ //returns only positive value between 0 to b-1 return a%b<0 ? (a%b)+b : a%b; } int Solution::pow(int x, int n, int d) { …
not_again_stackoverflow
  • 1,285
  • 1
  • 13
  • 27
1 2 3
46
47