bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] Re: base64


From: Stepan Kasal
Subject: Re: [bug-gnulib] Re: base64
Date: Thu, 25 Nov 2004 15:08:18 +0100
User-agent: Mutt/1.4.1i

Hi,

On Thu, Nov 25, 2004 at 02:40:01PM +0100, Simon Josefsson wrote:
> Bruno Haible <address@hidden> writes:
> 
> >> +#define BASE64_LENGTH(inlen) (((4 - (inlen) % 3) % 4) + (4 * (inlen) / 3))
> >
> > This is overly complex. You can also write it as
> >    ((inlen) + 2) / 3) * 4

there is a typo here, one left parenthesis is missing:

       (((inlen) + 2) / 3) * 4

> I don't think that give the same result, try tabulating the two macros
> for, say, inlen = 0...15.

Well, I did it, the results are the same. (The awk program I used is
attached at the end of this mail.  (Of course, we suppose that
``inlen'' is an integer variable, so / is integer division.)

I also vote for the simpler expression.  The expression

        (n + (k-1)) / k

menst the smallest integer >= n/k, ie. the ceiling of (n / k).

Perhaps you'll find the macro more readable this way:

#define BASE64_CEILING_DIV(n, k)  (n + (k-1)) / k
#define BASE64_LENGTH(inlen)    BASE64_CEILING_DIV(inlen, 3) * 4

Have a nice day,
        Stepan Kasal

function f1(inlen) {
        return (((4 - (inlen) % 3) % 4) + int(4 * (inlen) / 3));
}
function f2(inlen) {
        return int(((inlen) + 2) / 3) * 4;
}
BEGIN {
        for (i=0; i<=16; i++)
                print f1(i), f2(i);
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]