Article View: comp.lang.c
Article #1201Re: .5 against 0.5f
From: Waldek Hebisch
Date: Sat, 31 Oct 2026 12:18
Date: Sat, 31 Oct 2026 12:18
25 lines
2217 bytes
2217 bytes
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 28/10/2026 21:25, Michael S wrote:
> [...]
>>> I'd still likely prefer to write it as (float)0.1 instead of 0.1f.
>>> It somewhat depends on my mood in specific day, but likelihood is
>>> certainly not in favor of 0.1f.
>>>
>> That seems a bit excessive to me, but okay. The principle is the
>> same, making it clear to the reader and the compiler that no
>> double-precision arithmetic is involved.
>
> Except that, at least in the abstract machine, `(float)0.1` produces
> a value of type double and converts it to float. It's likely that
> a compiler would generate the same code as for `0.1f`, but I'd want
> to confirm that if it mattered. (Actually, I'd just write `0.1f`.)
Maybe the code will be the same. But in general going via doubles
produces less accurate result, so `0.1f` "unquestionably"* better.
* "unquestionably" in this group meaning that somebody will
disagree.
--
Waldek Hebisch
Technical Details
Message-ID:
<11c4mab$jkma$1@paganini.bofh.team>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!not-for-mailReferences:
<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> <11bs8rb$26dq0$1@dont-email.me> <20261028222504.00004b8b@yahoo.com> <11bv4q0$37eth$1@dont-email.me> <11bvcea$3a06t$2@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!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.lang.c
Subject: Re: .5 against 0.5f
Date: Sat, 31 Oct 2026 12:18:21 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11c4mab$jkma$1@paganini.bofh.team>
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> <11bs8rb$26dq0$1@dont-email.me> <20261028222504.00004b8b@yahoo.com> <11bv4q0$37eth$1@dont-email.me> <11bvcea$3a06t$2@kst.eternal-september.org>
Injection-Date: Sat, 31 Oct 2026 12:18:21 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="643786"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2