Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: why is there not a ipow version of pow?
Date: Tue, 18 Aug 2026 17:44:10 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <86qzjv0wit.fsf@linuxsc.com>
References: <115eks4$3pn1s$1@dont-email.me> <115f7v8$1b5d$1@raubtier-asyl.eternal-september.org> <115facm$1659$3@dont-email.me> <115favq$2ckl$1@raubtier-asyl.eternal-september.org> <115fe3u$1659$5@dont-email.me> <115feje$3nf1$1@raubtier-asyl.eternal-september.org> <115ffag$1659$9@dont-email.me> <115g94d$2pb62$1@paganini.bofh.team> <115h9mb$kpdk$1@dont-email.me> <115hjka$o7k2$1@kst.eternal-september.org> <20260812224333.000065c4@yahoo.com> <115im0c$136js$1@kst.eternal-september.org> <20260813002409.00003f1d@yahoo.com> <115ippl$15jbt$1@dont-email.me> <86lda740ix.fsf@linuxsc.com> <20260815231716.00002b94@yahoo.com> <868q643ccm.fsf@linuxsc.com> <20260818003501.00002080@yahoo.com> <86zeyj1lrw.fsf@linuxsc.com> <20260818221740.00002511@yahoo.com> <86v797124x.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 19 Aug 2026 00:44:12 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2387547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/j9QIw5t+jTheFM/q8ot1uPqCutpd9S4E="; posting-host="d6f68e827472d35b9db1fc199aad88a7"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:gKECKExfG0UpoEMuccIiqKjKsWs= sha1:tom8NRhFvqrGOb+7+JwtX8R7rlI= sha256:f+ZVmXFLzWBDFcXFkAFnQD8pXovNzhS5eu+prgksBnI= sha1:AaloE6iDr+WbvpIu/vYMthJlHgg= sha256:ZlMCP4a1tCfh5pFqCV+wyyrfEbdG5a9XkxsZWw2CXBU=
Xref: csiph.com comp.lang.c:401320
Tim Rentsch writes:
> If I were to take a similar approach, I might write
> something like this (disclaimer: not compiled):
>
> wword
> xpow( wword a, wword n ){
> if( n < 2 ){
> // handle powers less than 2
> // exercise for the reader
> }
>
> wword r = 1;
> do {
> if( n & 1 ) r *= a;
> a *= a;
> } while( n /= 2, n > 1 );
>
> return r*a;
> }
Sorry about that.. darn tab characters..
wword
xpow( wword a, wword n ){
if( n < 2 ){
// handle powers less than 2
// exercise for the reader
}
wword r = 1;
do {
if( n & 1 ) r *= a;
a *= a;
} while( n /= 2, n > 1 );
return r*a;
}