Article View: comp.lang.c
Article #899Re: .5 against 0.5f
From: Keith Thompson
Date: Tue, 27 Oct 2026 22:53
Date: Tue, 27 Oct 2026 22:53
34 lines
2781 bytes
2781 bytes
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
> 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".
I think you gave the wrong subsection number, and you didn't specify
which version of the standard you're quoting from. 6.5.4.3 is
"Unary arithmetic operators" in the current standard, though it
may be different in different editions. The wording you quoted
is from 6.4.4.3p4 in N3220 (C23).
(I'd like the C standard to adopt named subsections, as used in
the C++ standard.)
[...]
> You should use 0.1 when the value will be stored in a double or would
> otherwise immediately get converted to double when used (which is often
> the case). You should use 0.1f to initialize a float variable or to pass
> an argument to a function whose prototype specifies that the
> corresponding parameter has the type float.
Using 0.1 in a context where it will be converted to float is likely
to be harmless. Converting 0.1 to float is likely to yield the same
value as 0.1f. That's probably not guaranteed, but if there is a
difference it's probably insignificant.
--
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:
<11bra0u$1uh9q$2@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-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <11br5td$1to7l$1@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: Tue, 27 Oct 2026 15:53:17 -0700 Organization: None to speak of Lines: 34 Message-ID: <11bra0u$1uh9q$2@kst.eternal-september.org> 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 Injection-Date: Tue, 27 Oct 2026 22:53:18 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="2049338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kCl8KWn6kUF2zmpqlW3ae"; posting-host="9febde6641169f8329510415e264039e" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:Z8rlaYPmCfQnyk/O2VRB2z2fHPI= sha256:BPYL/pmIgSVT+hxHrstwWxNgVpxgikuSHyAZ1NbwQvw= sha1:99KwJo4fP78f0qHqUT4HjvTsxK4= sha256:kGnx5KNbz4+qBPgp6TNXoL/jYem/6Jjlu3civLrLPBE=