Article View: comp.lang.c
Article #863Re: .5 against 0.5f
From: Steven G. Kargl
Date: Tue, 27 Oct 2026 17:45
Date: Tue, 27 Oct 2026 17:45
44 lines
2267 bytes
2267 bytes
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.
#include <stdio.h>
int
main(void)
{
double d;
d = 0.1f;
printf("%.13a\n", d);
d = 0.1;
printf("%.13a\n", d);
return (0);
}
% cc -o z t.c && ./z
0x1.99999a0000000p-4
0x1.999999999999ap-4
The real number is 0.1 is not exactly representable in a binary
floating point format. See
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
--
steve
Technical Details
Message-ID:
<11bqnvh$1np7s$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-mailReferences:
<11bpvs7$1e6kc$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: "Steven G. Kargl" <sgk@REMOVEtroutmask.apl.washington.edu> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Tue, 27 Oct 2026 17:45:21 -0000 (UTC) Organization: A noiseless patient Spider Lines: 44 Message-ID: <11bqnvh$1np7s$1@dont-email.me> References: <11bpvs7$1e6kc$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 27 Oct 2026 17:45:22 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1828092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Y/CmpPWEtWrjLgrvPHOqd"; posting-host="788ec41b747029f4d082e3468aec6752" User-Agent: Pan/0.164 (Kupiansk) Cancel-Lock: sha1:17KEfRb4bjZeBa/3YnVZaRap/uc= sha256:lCAbhcqQZHB6vluXfxj25O85j3kXWoDAOFDH50xuKbo= sha1:zjgroHL18hFCGR6TcgDRFsn4dm0= sha256:nRcs79Wt3jVE0HeVpCMhQ/LfUxOuaq/VU5gj3Jy8hgU=