🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #988

Re: .5 against 0.5f

#988
From: Janis Papanagnou
Date: Wed, 28 Oct 2026 23:08
62 lines
4089 bytes
On 2026-10-28 21:27, Keith Thompson wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...]
>> 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.

And knowing also a lot of the internals, and C-standards documents,
I'm sure. (My point was just that "normal" C-programmers might not
have that background and would "logically" assume different. - But
since you had clarified the word by using a more appropriate one in
this post I'm fine with that now. Thanks.)

> 
>> 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. 

Only that my view here is that you need a "conversion" in both cases,
since you primarily have to convert from a string representation of
the literal to the appropriate internal (binary) form. And given the
_program contexts_ you can do _the one_ appropriate conversion for
the types involved (i.e. Text->Float and Text->Double, respectively).

Note: my argumentation is based on questioning the existence of 'F'.
So I'd appreciate to hear of any enlightening application cases, ones
that would be impossible when 'F' in literals wouldn't be present.

(And, ideally, practically relevant usages. - We know that "C" is as
it is, and as it is there's some unavoidable consequences from that.)

> 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.

Yes, sure. Only that I think that context should suffice to interpret
"0.1" appropriately!

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

Sure. But isn't that difference basically just a home-brewed C-issue?

I'd be curious why one would write the former in the first place.
Will a programmer or program designer gain something by assigning a
'float' constant literal to a 'double' variable?

I've never needed such, erm.., "hacks" ever in any of my C-code or
in other languages. So I'm honestly asking.

Janis
Technical Details
Message-ID: <11btv9c$139ta$12@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> <11brir0$1uh9q$4@kst.eternal-september.org> <11bt4ua$139ta$8@dont-email.me> <11btlrl$2ojn1$1@kst.eternal-september.org>

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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Thu, 29 Oct 2026 00:08:28 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <11btv9c$139ta$12@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> <11brir0$1uh9q$4@kst.eternal-september.org>
 <11bt4ua$139ta$8@dont-email.me> <11btlrl$2ojn1$1@kst.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Oct 2026 23:08:28 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1157034"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18CCpu11uHc72jWX28spcbg"; posting-host="880663668c89bd06f8f144317597f206"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WUBMZ5WUFFcXM9sQaM4v2ZNTHME= sha256:BOLmhsEyJ3kxf1Pc1xD2a6HYKaZT7zQzhb1vPRyiv/M=
	sha1:PekZX9LuIvoys0qYcslIdEK3Uxc= sha256:kjBfhSmM/G9qrVW89agwXJcDwZJ80VO2w0NCpkvMg0Y=
In-Reply-To: <11btlrl$2ojn1$1@kst.eternal-september.org>
Content-Language: en-US