[PHP] Re: Test for whole number.
That post was incomprehensible. Here it is revised: I'd like to condense the function below into one line. function isOneBitSet($n) { $x = log($n)/log(2); return ($x == intval($x)); } AND I don't want to do this: return (log($n)/log(2) == intval(log($n)/log(2))); So, is there a way to check if a number is whole only using the number once? Something like is_whole_number(log($n)/log(2)); Charlie Is there a one line test for whole numbers? I want to condense this function down to one line: function isOneBitSet($n) { $x = log($n)/log(2); return ($x == intval($x)); } TIA, Charlie -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Test for whole number.
Hi Not sure if this is the best way to do it: function isOneBitSet($n) { return !ereg(\.,strval(log($n)/log(2))); } Tom At 09:16 AM 8/04/2002, Charlie Killian wrote: That post was incomprehensible. Here it is revised: I'd like to condense the function below into one line. function isOneBitSet($n) { $x = log($n)/log(2); return ($x == intval($x)); } AND I don't want to do this: return (log($n)/log(2) == intval(log($n)/log(2))); So, is there a way to check if a number is whole only using the number once? Something like is_whole_number(log($n)/log(2)); Charlie Is there a one line test for whole numbers? I want to condense this function down to one line: function isOneBitSet($n) { $x = log($n)/log(2); return ($x == intval($x)); } TIA, Charlie -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Test for whole number.
On Mon, 8 Apr 2002, Tom Rogers wrote: At 09:16 AM 8/04/2002, Charlie Killian wrote: I'd like to condense the function below into one line. function isOneBitSet($n) { $x = log($n)/log(2); return ($x == intval($x)); } AND I don't want to do this: return (log($n)/log(2) == intval(log($n)/log(2))); Not sure if this is the best way to do it: function isOneBitSet($n) { return !ereg(\.,strval(log($n)/log(2))); } Beware; using a regular expression for this is slower than creating an intermediate variable. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php