Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## 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?  Reply With Quote

3. ## Re: Question about math.pow and math.sqrt

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".  Reply With Quote

4. ## 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?  Reply With Quote

5. ## 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.  Reply With Quote

6. ## The Following User Says Thank You to Mugambbo For This Useful Post:

ggx7 (March 6th, 2014)

7. ## 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?  Reply With Quote

8. ## 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!  Reply With Quote

9. ## The Following User Says Thank You to Mugambbo For This Useful Post:

ggx7 (March 7th, 2014)

10. ## 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?  Reply With Quote

11. ## 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:
` Math.pow (X, 1/3d)`
and this should give you the cube root of the number X, while this:
` Math.pow (X, 1/5d)`
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'.  Reply With Quote