[Top][All Lists]
[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);
}
- [bug-gnulib] base64, Simon Josefsson, 2004/11/23
- Re: [bug-gnulib] base64, Bruno Haible, 2004/11/24
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/25
- Re: [bug-gnulib] Re: base64,
Stepan Kasal <=
- Re: [bug-gnulib] Re: base64, Jim Meyering, 2004/11/25
- Re: [bug-gnulib] Re: base64, Stepan Kasal, 2004/11/25
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/25
- Re: [bug-gnulib] Re: base64, Stepan Kasal, 2004/11/25
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/25
- Re: [bug-gnulib] Re: base64, Bruno Haible, 2004/11/25
- Re: [bug-gnulib] Re: base64, Paul Eggert, 2004/11/26
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/26
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/26
- [bug-gnulib] Re: base64, Simon Josefsson, 2004/11/28