RE: [PHP] Re: Perfect Squares
| From: | Stephen Craton | Date: | Wed, 26 May 2004 00:03:54 +0000 |
| Subject: | RE: [PHP] Re: Perfect Squares | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186966@lists.php.net to get a copy of this message | ||
I guess I don't mean perfect squares, more or less square roots with
terminating decimals. Thanks for all the help, and I found that Jason's code
will work for the program I'm doing right now.
Thanks,
Stephen Craton
http://www.melchior.us
- -----Original Message-----
- From: Jason Barnett [mailto:jasbarne@indiana.edu]
- Sent: Tuesday, May 25, 2004 6:59 PM
- To: php-general@lists.php.net
- Subject: [PHP] Re: Perfect Squares
-
- Stephen Craton wrote:
-
- > I'm in a bit of a pickle. I need to find out if a variable is a perfect
- > square or not, and this needs to test for decimal numbers as well, such
- as
- > 2.25. The thing is, the only function I've found in PHP is
- > gmp_perfect_square() which isn't supported on my web server, and I don't
- > know how to compile the GMP code into PHP on my windows box. So, how
- exactly
- > would you go about finding out if something is a perfect square or not?
-
- It's been a while since I studied this in math, so I figured I'd find
- out the definition of perfect square. What I found:
- http://en.wikipedia.org/wiki/Perfect_square
-
- Neither of those definitions fit what for your example number 2.25. For
- instance,
-
- $sqrt = sqrt($number);
- if ($sqrt * $sqrt == $number) {
- //should always be true, except negative values and possibly rounding
- }
-
- --
- PHP General Mailing List (http://www.php.net/)
- To unsubscribe, visit: http://www.php.net/unsub.php
-