🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #925

Re: .5 against 0.5f

#925
From: fir
Date: Wed, 28 Oct 2026 06:51
64 lines
3489 bytes
fir pisze:
> Steven G. Kargl pisze:
>> 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
>>
> 
> if so its totally terrible, i was kinda not aware of that
> 
> 
> i would say its wrong and stupid probably becouse in float computations 
> such numbers should be floats imo in doubles it should be doubles
> 
> 
> i should run my own test but im too exhausted
> 
maybe no wonder i was not aware of this if this is so stupid it no come 
to my mind
(should i also write 0.0f insetad of 0 BTW?)

as to optimistation there is probably a flag wjich turns it off 0 i mean
replace .1 as doube as .1 as floats when it can help to remove this 
conversions

but im not sure which one in gcc probably -ffast-math

but i not tested/talked yet
Technical Details
Message-ID: <11bs613$26knh$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-mail
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> <11brkco$21oj5$1@dont-email.me> <11bs4tj$26daj$1@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: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Wed, 28 Oct 2026 07:51:13 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <11bs613$26knh$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> <11brkco$21oj5$1@dont-email.me>
 <11bs4tj$26daj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 28 Oct 2026 06:51:15 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2314993"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/AskcDm/dcCf9rGFCFK4ceHKCGqZ1dv5I="; posting-host="0c05802531f1a4b723135877d29c6d22"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:AYExOqLa5L27FpNpMa+Rx7YCnlk= sha256:1hAUrZ6O8tYqWsNTGCPDW40X5vTlZhCj8wbZu2Mvrf4=
	sha1:M08AqhALVultT7iZJWw0s5Bh/l8= sha256:7D7E7fQ5jbaF3BFL5bc2ojzioTB6tnCtx2HngQvt25U=
In-Reply-To: <11bs4tj$26daj$1@dont-email.me>