First root of a number


Posted on 16th Feb 2014 07:03 pm by admin

Hi,

I can't find any function in php to give me the first root of a number.
Is there any built-in function for it?

For example:
81 => 3
9 => 3
64 => 2
256 => 2

I wrote this function to get it, But it seems sqrt always return a float.

Code: <?php
function getRoot($num)
{
if (is_int(sqrt($num))) // (strpos(sqrt($num), '.'))
$num = sqrt($num);

return $num;
}
?>

Any idea?

No comments posted yet

Your Answer:

Login to answer
140 Like 6 Dislike
Previous forums Next forums
Other forums

Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then

Had a simple form script that suddenly stopped working
It was made about a year ago and had been working fine. Last time it was known to work for sure was

BIG file upload!
Hey guys!

I'm trying to upload a file, it works well with smaller files but with 60mb+, I get

Floating Point Precision Loss
I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D

login from external site
Hi my new experience begins, Now what i am trying to do is i make three pages, login.php logout.php

Calender Not Opening
The following code is not loading the javascript calender in another window. It's not doing anything

Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi

Error with Font and imagettfbbox
I keep getting an error that says "Warning: imagettfbbox() [function.imagettfbbox]: Could not f

Multithreading design
Hi

I have come up with a Singleton class that manages a pool of database connections. Basical

php mysql query from input textbox
Hi,

I have a text box, in that i have given the mysql query. I can able to get the query in v

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash