Question about math.pow and math.sqrt

Ok, I get confused about math.pow, and how it has something to do with 0.5 or 1/2? but my teacher keeps saying be wary of integer by integer division. I was getting so nervous about the concept because it has to do with the lab, I couldn't concentrate. what exactly does math.pow do? I mean it returns a long, and obviously deals with exponents.

For example, I know math.pow(1,10) = 1 being the base number which will be exponentiated(if that is a word) to the tenth power. 1^10. What the heck else is there that I am missing, about math.pow returning a fraction or dealing with fractions or what is it?

Re: Question about math.pow and math.sqrt

Quote:

I mean it returns a long

If you are referring to

Math (Java Platform SE 7 )

both pow and sqrt return double values and use double values as their parameter(s). Math.pow: "returns the value of the first argument raised to the power of the second argument".

Re: Question about math.pow and math.sqrt

Thank you for replying, I apologize for not being clear. Is this a legitimate way to find the square root with math.pow? let's say we have x, therefore math.pow(x, 0.5) would find the square root yes?

Re: Question about math.pow and math.sqrt

Yes! If you want square roots, use Math.sqrt instead. However, Math.pow as you've mentioned can also get the job done. Yet, I could consider that 'illegitimate' as is the possibility of more resources (not significant) been pulled while executing the same task.

Re: Question about math.pow and math.sqrt

Thank you muganmbbo! So was I correct that if I DID want to find the square root WITH the math.pow, I could multiply the base number by 0.5 to find the square root yes? Because that does make sense since x^2 would multiply it times itself, but x^0.5 would get the half way point OF the ^2, right?

So basically I am asking was I correct in my assessment of my example: math.pow(x, 0.5) <----this will return the square root?

Re: Question about math.pow and math.sqrt

You're absolutely correct! By the way, you are not actually multiplying the base number by 0.5, but raising the base number to a POWer of 0.5. You'll find proofs in a high school maths text book. You can also find the fourth root of a number e.g. 8, by using Math.pow (8, 0.25). Thats it!

Re: Question about math.pow and math.sqrt

How about finding the cube root? I realize you will obviously need math.pow (basenumberhere, ____), because if you get the square root 0.5, would it be 0.25? because if you're taking the cube root, you're taking more than the regular square root. or am I thinking about it backwards? would it be 0.75?

Re: Question about math.pow and math.sqrt

Not quite ggx. Think about square root, cube root, fourth root, fifth root, etc of a number (X) as that number (X) raised to a power of 1/2 (0.5), 1/3 (~0.33), 1/4 (0.25), 1/5 (0.2), etc respectively. So for example, the fifth root of X would be, X^1/5. But, to put that argument into action, you'll want to write it like so:

and this should give you the cube root of the number X, while this:

will give you the fifth root of X. Where X is a double. Gosh! I hope you understand. To learn more of these, google 'Indices and logarithms'.