🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #926

Re: .5 against 0.5f

#926
From: fir
Date: Wed, 28 Oct 2026 06:55
72 lines
3707 bytes
fir pisze:
> 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
ai says even fast math not enebles that but there is a flag


-fsingle-precision-constant.

Technical Details
Message-ID: <11bs68h$26knh$2@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> <11bs613$26knh$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:55:11 +0100
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <11bs68h$26knh$2@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> <11bs613$26knh$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:55:14 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2314993"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+m70y4Go87VUOFDRXiKX2rlOy/msPcOE8="; 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:iDgJ9U5E0kpXIvkFX0Qh1uqKftA= sha256:J+35U43c8p+jnSP7NvKQov+5xBO0D4+UXvPeZde0eAk=
	sha1:b+UiqAi8jNTZ8qDV506N/7ZXOiw= sha256:UoESRmX8bZDvKqKAfKe8M+uWjnivayE5xeTTsfKlNnI=
In-Reply-To: <11bs613$26knh$1@dont-email.me>