Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Calculating Root Values beyond Math.sqrt

    Well, it's been a while since I last visited CF, but I'm finally back and, for the life of me, am drawing a total blank on something that seems like it should be fairly easy to handle.

    The Math.sqrt() function works just fine if all a person needs is the Square Root of a number, but what about needing the Cube Root or even a 4th Root of a number?

    My first instinct was to use the Math.pow(x,y) function with a negative value for "y." For instance;

    var z=Math.pow(27,-3)

    This should return a value of 3. Unfortunately, this doesnt seem to work when I tested it through the W3 reference pages, so I am looking for a clue as to how I might go about finding such values, or if it is even possible through Javascript.

    Oh, and for the record, I did miss everyone. Some of you have helped me out tremendously in the past. Hope all of you have had wonderful holidays and a good life while I was away.

    Greason
    Greason Wolfe
    +++++++++++
    Sometimes you don't know what you know until you know it.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    To get the nth root of something you do it to the power of 1/n:


    4 ^ 1/2 = 2

    8 ^ 1/3 = 2

    16 ^ 1/4 = 2

  • #3
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Duh! I should have thought of that!

    Thanks bunches.

    Greason
    Greason Wolfe
    +++++++++++
    Sometimes you don't know what you know until you know it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •