Article View: comp.lang.c
Article #1256Re: .5 against 0.5f
From: James Kuyper
Date: Mon, 02 Nov 2026 03:37
Date: Mon, 02 Nov 2026 03:37
39 lines
3466 bytes
3466 bytes
On 2026-10-30 05:58, Michael S wrote:
> On Wed, 28 Oct 2026 16:05:06 -0700
> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
...>> I was too quick to assume that if a compiler sees 0.1 in an expression
>> involving float operands, it can safely treat it as 0.1f. Since 0.1
>> causes the usual arithmetic conversions to convert the other operand
>> from float to double, I was very probably wrong.
>>
>> I can still imagine a compiler optimizing `f *= 0.1;` to use
>> float arithmetic. I wonder if there are more clear-cut examples.
>>
>
> I don't know what exactly is allowed by the Standard (that is, I know
> what's written, I don't know how peoples with lowyers attitude can
> interpret it), ...
"The accuracy of the floating-point operations (+, -, *, /) and of most
of the library functions in <math.h> and <complex.h> that return
floating-point results is implementation-defined, as is the accuracy of
the conversion between floating-point internal representations and
string representations performed by the library functions in <stdio.h>,
<stdlib.h>, and <wchar.h>. The implementation may state that the
accuracy is unknown." (n3998 5.3.5.33.p20)
Note that this allows sufficient inaccuracy that the expression
LDBL_MAX - LDBL_MIN < LDBL_MIN - LDBL_MAX
is permitted to evaluate to 1, so long as you either document how bad
the accuracy is, or state that it's unknown. Unless something else
imposes stronger requirements, C floating point is almost completely
useless.
> ... but will be extremely surprised if any "major" compiler
> is doing such optimization on IEEE-754 compliant platform in absence of
> non-compliance flags like fast-math.
One way to get stronger requirements is to require that
__STDC_IEC_60559_BFP__ be pre#defined, which mandates conformance with
Annex F, which essentially requires conformance to ISO/IEC 60559 ==
IEEE-754.
Technical Details
Message-ID:
<11c90ho$2hn6k$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> <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> <11btp9d$2ojn1$4@kst.eternal-september.org> <20261029001256.00001179@yahoo.com> <11btv32$2rgo2$1@kst.eternal-september.org> <20261030115805.0000644a@yahoo.com>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: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Sun, 1 Nov 2026 22:37:26 -0500 Organization: A noiseless patient Spider Lines: 39 Message-ID: <11c90ho$2hn6k$1@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> <11bs8rb$26dq0$1@dont-email.me> <11btp9d$2ojn1$4@kst.eternal-september.org> <20261029001256.00001179@yahoo.com> <11btv32$2rgo2$1@kst.eternal-september.org> <20261030115805.0000644a@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 02 Nov 2026 03:37:29 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2677972"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rH7SatlnapQKL71RF9ZwuCMboglSNljY="; posting-host="2fcd2802cad82f7fc68430a3bc530619" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:jwPKGiBESEwaqxA0x+rcLN+9EW0= sha256:2GUh9vU2JISaaR5a750eWlCX9Vt7/dl/JiBP3+pJ9c4= sha1:umLYg87n3k/EfWYiltYBwhner28= sha256:415fsaxI6w251oPjWEh+0wVBdLJwdYxMEUx7UfJVCoA= In-Reply-To: <20261030115805.0000644a@yahoo.com> Content-Language: en-US