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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Question about math.pow and math.sqrt

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default 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?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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".

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default 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?

  4. #4
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default 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.
    Who holds the KEY to all knowledge?

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

    ggx7 (March 6th, 2014)

  6. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default 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?

  7. #6
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default 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!
    Who holds the KEY to all knowledge?

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

    ggx7 (March 7th, 2014)

  9. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default 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?

  10. #8
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default 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'.
    Who holds the KEY to all knowledge?

Similar Threads

  1. Help with Math.sqrt()
    By Edmacelroy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 9th, 2013, 12:52 PM
  2. Question about math.pow
    By felixb in forum Java Theory & Questions
    Replies: 2
    Last Post: October 2nd, 2013, 10:59 AM
  3. Math.pow
    By britton33 in forum What's Wrong With My Code?
    Replies: 30
    Last Post: July 1st, 2012, 04:42 PM
  4. Math.sqrt causing general havoc
    By Garrett93 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2012, 03:43 AM