lkml.org 
[lkml]   [2012]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer
On Tue, Aug 21, 2012 at 11:06:13PM +0100, Al Viro wrote:
> On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote:
> > J. Bruce Fields wrote:
> >
> > From: "J. Bruce Fields" <bfields@redhat.com>
> >
> > I've seen a couple examples recently where we've gotten this wrong.
> > Maybe something like this would help? Is there some better way?
> >
> > (Approximation due to Jim Rees).
> >
> > Please add Suggested-by: Jim Rees <rees@umich.edu>. I'm thinking of
> > patenting the algorithm.
>
> Is that a joke? Patenting the fact that log10(256) is 2.408..., which
> is about 2.4, which is 24/10? I really hope we are Poe'd... BTW, NAK
> the comment - s/36/26/ in there; check it yourself -
> $ echo '2^(8*27)' | bc
> 105312291668557186697918027683670432318895095400549111254310977536
> which is 66-digit, not 65 as the estimate would be.

Erp, you're right.

Anyway, does something like base10len(type) seem reasonable? Or define
macros that enumerate the sizes? (ULONG_STR_MAX or something?)

--b.


\
 
 \ /
  Last update: 2012-08-22 01:01    [W:0.059 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site