Article View: comp.lang.c
Article #906Re: .5 against 0.5f
From: Steven G. Kargl
Date: Wed, 28 Oct 2026 01:50
Date: Wed, 28 Oct 2026 01:50
43 lines
2342 bytes
2342 bytes
On Wed, 28 Oct 2026 00:49:19 -0000 (UTC), Lawrence D’Oliveiro wrote:
> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>
>> However, if you need double precision, you shouldn't be using the
>> "f" suffix.
>
> Is there any situation where you *should* use the “f” suffix?
>
> I am thinking: no.
% cat j8.c
float
foo(int n, float *x)
{
float s = 0;
for (int i = 0; i < n; ++i) {
s += x[i] * 0.1;
}
return (s);
}
% cc -o z.s -O3 -S j8.c && grep cvts z.s
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
cvtss2sd %xmm3, %xmm2
cvtss2sd %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
cvtss2sd %xmm0, %xmm1
cvtss2sd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
That's a lot of useless conversion if 0.1f would have been
good enough. Change 0.1 to 0.1f in the above code.
% cc -o z.s -O3 -S j8.c && grep cvts z.s | wc -l
0
HTH
--
steve
Technical Details
Message-ID:
<11brkco$21oj5$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@dont-email.me> <11br792$1u7e5$1@dont-email.me> <11brgqf$21170$2@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Wed, 28 Oct 2026 01:50:16 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: <11brkco$21oj5$1@dont-email.me> References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@dont-email.me> <11br792$1u7e5$1@dont-email.me> <11brgqf$21170$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 28 Oct 2026 01:50:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2155109"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ik2SiOQ3a1L9lSFFzAFGS"; posting-host="1bf873808c53778ca982afc43c23d859" User-Agent: Pan/0.164 (Kupiansk) Cancel-Lock: sha1:bxPGCfG/4y71xlCEUEGLR2TYpO8= sha256:LDI6nzkLXl2O5/4QrumnlY+2s/r9JI3NQ+MAzhjVBDs= sha1:WO50s8jjOHgEhVc1VB8OTwdEOlI= sha256:C5EeYCOssf556ws6YU0Eo6pnU9LF4CbnAZwqxWM3dXk=