# Problem with nth square root of any number

• May 14th, 2009, 03:38 PM
Freaky Chris
Problem with nth square root of any number
OK, so now I think this is sending me crazy. I'm looking at a problem that is a mathematical problem. Now I have no problem coming up with a solution to it, that runs in under 1 second. However I want to do it using some funky Math. Anyways, after working out the Math I got one of the equations I need to compute down to

n^(1/6)

Or the 6th root of n.

Now the Java code I have for this is as follows, since Java has no nth root function I'm raising it to a power of a 1/6.
Code :

`System.out.println(Math.pow(64.0, 1/6));`
Now, the only thing it will print is 1.0
However the 6th root of 64 is 2!!!!

Chris
• May 14th, 2009, 03:43 PM
Freaky Chris
Re: Mathematics in Java
ARRRRRRRRRGGGGGGGHHHHHHHHHHH

I should make the 1/6 into a double... I think I may kill someone!
• May 14th, 2009, 03:58 PM
JavaPF
Re: Mathematics in Java
Ah Chris! I was just about to submit my solution!!!

Code :

`System.out.println(Math.round(Math.pow(64.0, .16)));`
• May 14th, 2009, 04:09 PM
Freaky Chris
Re: Mathematics in Java
Hehe thanks, but I still face one problem and that is when I wish to calculate the 6th root of 64000000, which is 20. But java makes it aprox 19.999999999999998. Unfortunately rounding is not an option :(

Chris
• May 14th, 2009, 05:16 PM
JavaPF
Re: Mathematics in Java
Why is rounding not an option? #-o
• May 14th, 2009, 05:18 PM
Freaky Chris
Re: Mathematics in Java
because if i calculate the 6th root of 64999999 then it will be just under 19.9999999999999998, but it shouldn't be rounded up to 20, it should be rounded down to 19 xD

Chris
• May 14th, 2009, 05:44 PM
JavaPF
Re: Mathematics in Java
Could always substring it lol
• May 14th, 2009, 05:46 PM
Freaky Chris
Re: Mathematics in Java
How do you mean?
• January 10th, 2015, 05:13 AM
sayedbd2014
Re: Problem with nth square root of any number
System.out.println(Math.pow(64,1.0/6));

Output: 2.0 ;;)
• January 10th, 2015, 07:38 PM
pbrockway2
Re: Problem with nth square root of any number
Hi sayedbd2014, welcome to the forums!

Have a look at the date of this thread: the question was asked years ago (and answered by the OP straight away). I'll close this thread as some people find it annoying to read all the way through only to discover there isn't really any current question to consider.