Wudong
Wudong

Reputation: 2360

Calculate the base of power function

Given function:

 y=power(x, z)

Where y is the base x raised to the power of z.

In Java and many other language, there is function Math.pow() to calculate this.

My question is: how to calculate x, given y and z? Is there a standard library function for this?

Upvotes: 0

Views: 307

Answers (1)

chiastic-security
chiastic-security

Reputation: 20520

This is done easily enough by remembering a mathematical law:

  • xab = (xa)b

And now because z*(1/z)=1, the inverse of raising to the power z is raising to the power 1/z. So in your case

  • x = y1/z

Once you've got your power() function, that's all you need.

Upvotes: 2

Related Questions