...

View Full Version : Calculating Root Values beyond Math.sqrt



greasonwolfe
12-14-2007, 05:01 PM
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

Mwnciau
12-14-2007, 05:18 PM
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

greasonwolfe
12-14-2007, 05:23 PM
Duh! I should have thought of that! :eek:

Thanks bunches.

Greason



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum