🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #970

Re: .5 against 0.5f

#970
From: Keith Thompson
Date: Wed, 28 Oct 2026 20:27
52 lines
3364 bytes
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> On 2026-10-28 02:23, Keith Thompson wrote:
>> Lawrence D’Oliveiro <ldo@nz.invalid> writes:
>>> 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.
>> If you're working with values of type float, the "f" suffix is more
>> explicit.
>> Logically, something like
>>      float f = 0.1;
>> implies a conversion from double to float, which could be
>> non-trivial.
>
> I think "logically" is a misleading word here.

Perhaps "in the abstract machine" would have been clearer than
"logically".

In the abstract machine, 0.1 is of type double.  The initialization
causes that value to be converted from double to float.

> The thought of something "implicit" going on here is a thought that
> might stem from (knowing) the inherent mechanisms and quirks of the
> C-language not necessarily what one would logically expect.

My logical expectation is based on knowing C.

> My expectation (for sensibly defined programming languages) would be
> that literals for two different "real numbers" types are generic WRT
> those types; they should be usable [in "C"] without loss (or kludges)
> with 'float' and 'double'.

Sure, a compiler can generate code to store (float)0.1 in f without
doing a conversion, as long as the semantics are consistent.  But 0.1f
and 0.1 are of different types.  If they happen to behave the same way
in some context, it's a consequence of the C language rules.

Note in particular that this:
    double d = 0.1f;
has different semantics than
    double d = 0.1;
if double has more precision than float.    

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID: <11btlrl$2ojn1$1@kst.eternal-september.org>
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!kst.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> <11brir0$1uh9q$4@kst.eternal-september.org> <11bt4ua$139ta$8@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!kst.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Wed, 28 Oct 2026 13:27:33 -0700
Organization: None to speak of
Lines: 52
Message-ID: <11btlrl$2ojn1$1@kst.eternal-september.org>
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>
	<11brir0$1uh9q$4@kst.eternal-september.org>
	<11bt4ua$139ta$8@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 28 Oct 2026 20:27:33 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="2903777"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+3sE+8CBLE7TxzRGcyMqnD"; posting-host="ac4e6fa4e505b2147f0d092402a060c4"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:wh1fnjzIF9ewIYxhvKfLZQkvFps= sha256:Ph+plAwGGaum/KiOdaVJ5RIV5qamgkQJsDdRhB6m7KU=
	sha1:zjrsGNFOPwg8eKVN1BMEA51QKmA= sha256:rjTqJ8yBvtiDUcwKdB50ptieP3gmSqZiBTCMeFcpnqQ=