apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <bri...@apache.org>
Subject approximating division by a million Re: Why not POSIX time_t?
Date Mon, 15 Jul 2002 20:21:55 GMT
Building upon Cliff's formulas, here's another idea
for doing faster conversions of the current apr_time_t
format to seconds:

What we want is t/1000000

What we can do easily is t/1048576

But what can we add to t/1048576 to approximate t/1000000?

If I solve for 'C' in
   t/1000000 = t/1048576 + t/C
I get C= ~21,586,297
That's not a power of 2, but what if use 2^24 (~16M) as an

seconds = (t >> 20) + (t >> 24)

That probably isn't accurate enough, but you get the basic idea:
sum a couple of t/(2^n) terms to approximate t/1000000.

What do you think?


View raw message