Re: [quickie] Rounding up to next multiple

Rick Klement <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Paul Makepeace wrote:
> 
> This isn't really perl, but it might be mildly fun for a few seconds:
> 
>   $len += $page_size - $len % $page_size if $len % $page_size;
> 
> Any way of doing this in a single arithmetic expression, without the if?

$len += -$len % $page_size;

Mods of negative values are so much fun :)

-- 
Rick Klement
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.