Re: Re: Test for whole number.

From: Date: Mon, 08 Apr 2002 00:23:33 +0000
Subject: Re: Re: Test for whole number.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-91971@lists.php.net to get a copy of this message
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

« previous php.general (#91971) next »