Deutsch   English   Français   Italiano  
<20250322191213.00005ab2@yahoo.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.lang.c
Subject: Re: Suggested method for returning a string from a C program?
Date: Sat, 22 Mar 2025 19:12:13 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <20250322191213.00005ab2@yahoo.com>
References: <vrd77d$3nvtf$2@dont-email.me>
	<87a59hvgyk.fsf@nosuchdomain.example.com>
	<vrdi0g$47cb$3@dont-email.me>
	<mm72bl-1o2.ln1@otis.foo>
	<vrmdoo$1cqb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Mar 2025 18:12:18 +0100 (CET)
Injection-Info: dont-email.me; posting-host="16a2663479d6b4bf8fb6724acca31d7c";
	logging-data="419570"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18q0ILrIs/Qco2bCAwgn03Gxz1VlrACjVo="
Cancel-Lock: sha1:mUjnjKFsks7tRY+EUhR96+bkRbE=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)
Bytes: 1937

On Sat, 22 Mar 2025 13:25:43 +0000
Richard Heathfield <rjh@cpax.org.uk> wrote:

> On 22/03/2025 08:07, Peter 'Shaggy' Haywood wrote:
> 
> <snip>
> 
> >    Here's my solution, for what it's worth:
> > 
> > #include <stdio.h>
> > 
> > unsigned long weird(unsigned long n)
> > {
> >    printf("%lu", n);
> > 
> >    if(n & 1)
> >    {
> >      /* Odd - multiply by 3 & add 1. */
> >      n = n * 3 + 1;  
> 
> Or you can save yourself a multiplication
> 
> n = (n << 2) - (n - 1);
> 
> potentially shaving entire picoseconds off the runtime.
> 
> >    }
> >    else
> >    {
> >      /* Even - divide by 2. */
> >      n /= 2;  
> 
> do
> {
>    n >>= 1;
> } while(~(n & 1));
> 
> ...and there goes another attosecond.
>