How can I know the power of a number without using the operator **
1 Like
import math
math.pow(x, y)
Returns the value of x
to the power of y
(For Python)
@MicaelaMartinez If any one of the answers here solved your problem, mark it as the solution
4 Likes
Adding on to above, you can use
Math.pow(x, y)
for JavaScript/TypeScript. It’s a built in static method (for both vanilla js and node), so no need to import anything.
1 Like
I think pow
and powf
would be for C.
1 Like
Or if you love inefficiency, just keep multiplying:
let acc = 1;
let pow = 10;
let base = 2;
for (let i = 0; i < pow; i++) acc *= base;
// acc is 1024
(this is javascript but it’s basically the same in almost every other language)
1 Like
Wouldn’t that also work if you want to work with two floats, but don’t want to link your program with -lm
? (C)