[PLUG] OT: Formula For Determining # Of Digits In An Integer

Jason Van Cleve jason at vancleve.com
Fri Feb 18 00:50:40 UTC 2005


Quoth Galen Seitz, on Thu, 17 Feb 2005 14:57:45 -0800:

> What's your concern?  Speed?  The integer loop is almost guaranteed to
> beat any floating point implementation.

Almost guaranteed, is it?  Interesting.  I didn't want to convert to a
string, because creating objects in Java is expensive.  Moreover, I'm
using this now to validate for 16 digits, and I'd half assumed that two
logarithmic operations would be better than sixteen divide-by-ten op's. 
Hard to say, though, without benchmarking, as you say.

In any case, I wanted to know the formula (and I got it in spades, thank
you!).  I'll probably time it much later on, when I'm ready to optimize.

--Jason

--
Definition of democracy:  Two lions and a lamb deciding what's for
dinner.



More information about the PLUG mailing list