Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Wed, 28 Oct 2026 08:01:10 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <86ld7hna2x.fsf@linuxsc.com>
References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 28 Oct 2026 15:01:11 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2641216"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lmQxpCTGwg/gDa4InCSz2LBLj3l29ejM="; posting-host="863330b5bd13e85d720b0575444f578b"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:QLGNuAD8cN8lj9wXzqDNYkadkcM= sha1:ZfbZOWwekR4MVqQNi1qNjFkcfII= sha256:EkNwLC+wVFV0C2WD08VXijnrTFrbyIpde5aEoZxsXzY= sha1:JUv0Hrh3iOun8vOHDb36PG1Iiyg= sha256:tuUhLqJBtS2pEYlyVJctd4e09BUzl+lH2gyLUPfoZBE=
Xref: csiph.com comp.lang.c:403719
James Kuyper writes:
> On 2026-10-27 13:45, Steven G. Kargl wrote:
>
>> On Tue, 27 Oct 2026 11:53:55 +0100, fir wrote:
>>
>>> if ai generates me some functions it puts everywhere this f at the
>>> and yet it add zeros so instead of .1 i got 0.1f
>>>
>>> and i obviously dont like it
>>>
>>> i write hvever some codes when i need speed so the question is may
>>> it give some difference?
>>>
>>> i mean .1 maybe can be treated as doube constants so mabe occupies
>>> some more memory (?) or uses some casting in coplutations (?)
>>>
>>> i doubt it probably it makes difference but im strictly not sure
>>
>> The leading zero in 0.1 or 0.1f is irrelevant, but (to me) makes
>> code easier to read. The difference between 0.1 and 0.1f with
>> their binary representations is a another matter.
>
> The number 0.1 cannot be represented exactly in binary.
>
> The C constant "0.1" implicitly has a double value. It has "either
> the nearest representable value" to exactly 0.1, "or the larger or
> smaller representable value immediately adjacent to the nearest
> representable value, chosen in an implementation-defined manner."
> (6.5.4.3p4). Since it's double precision constant, "representable"
> means "representable as a double precision number".
>
> 0.1f, on the other hand, is explicitly a float value. It follows
> the same rules, but with "representable" meaning "can be represented
> as a float".
Yes, except implementations are allowed to represent floating-point
constants using a greater range and precision than the nominal type
would imply. So 0.1 and 0.1f could have the same value.