🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #960

Re: .5 against 0.5f

#960
From: David Brown
Date: Wed, 28 Oct 2026 16:44
32 lines
2930 bytes
On 28/10/2026 17:27, Steven G. Kargl wrote:
> On Wed, 28 Oct 2026 07:55:11 +0100, fir wrote:
> 
> 
>>> but i not tested/talked yet
>> ai says even fast math not enebles that but there is a flag
>>
>>
>> -fsingle-precision-constant.
> 
> It is a poor decision to depend on any specific compiler's
> options unless you intend to never use any other compiler.

It is fine to do so in non-portable code.  Most of my work is 
specifically targeting gcc, and if the code is better (clearer, safer to 
maintain, more efficient) as a result of compiler-specific flags or 
compiler-specific extensions, that's fine.  Of course, if the same 
results can be achieved without non-portable flags or extensions, that 
is better.

The key use of flags like this is for microcontrollers with hardware 
support for single-precision floating point, but not for double 
precision - which then needs to be handled by software routines.  The 
use of "-fsingle-precision-constant" is primarily for handling 
third-party code or other code that you don't want to change, but where 
you want to use single precision as much as possible.  For your own code 
on such devices, you would use "f" suffixes.

The "-Wdouble-promotion" flag is also very useful here - it will let you 
know if you have accidentally promoted a float (such as by using a 
double-precision constant in an expression).
Technical Details
Message-ID: <11bt8ph$2jb4n$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> <11bs613$26knh$1@dont-email.me> <11bs68h$26knh$2@dont-email.me> <11bt7p9$2i0ag$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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Wed, 28 Oct 2026 17:44:33 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <11bt8ph$2jb4n$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> <11bs613$26knh$1@dont-email.me>
 <11bs68h$26knh$2@dont-email.me> <11bt7p9$2i0ag$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Oct 2026 16:44:33 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2731159"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+w1+4O5TyfqWn7ySifCx3mm1pGup2pcfw="; posting-host="7742015709800b6389fefe24fb6a2b50"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1a6v2fyhSNHqe8zTuYq4WBsH/5k= sha256:vMshJx2MVNBxfq+uwfMK+5luqZfpqaAJsjdBnrvRcQA=
	sha1:lLwhP4bIkHpShgap3qzeGA3oyA4= sha256:YIkMPL+vUws5pJSybG20LwHgaRvSYa8vDLmlOvaGAUU=
In-Reply-To: <11bt7p9$2i0ag$2@dont-email.me>
Content-Language: en-GB, nb-NO