Article View: comp.lang.c
Article #874Re: .5 against 0.5f
From: Kaz Kylheku
Date: Tue, 27 Oct 2026 19:58
Date: Tue, 27 Oct 2026 19:58
27 lines
2155 bytes
2155 bytes
On 2026-10-27, Steven G. Kargl <sgk@REMOVEtroutmask.apl.washington.edu> wrote: > % 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. The real number 0.1 has a worse approximation in float than double, (if those are not the same size). However, every representation in float is supposed to be available in double: float to double conversion is lossless. If you write double d = 0.1f you are essentially saying you want d to take on that approximation of 0.1 that is available in float, rather than a possibly better one available in double. The abstract semantics is that 0.1f is a constant of type float. The actual semantics may be that the compiler notices that the float is used as an initialize for a double, and so just convert to a double constant of the same value. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID:
<20261027125506.75@kylheku.com>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>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: Kaz Kylheku <046-301-5902@kylheku.com> Newsgroups: comp.lang.c Subject: Re: .5 against 0.5f Date: Tue, 27 Oct 2026 19:58:57 -0000 (UTC) Organization: A noiseless patient Spider Lines: 27 Message-ID: <20261027125506.75@kylheku.com> References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> Injection-Date: Tue, 27 Oct 2026 19:58:57 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1942009"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bDCx0iKqV8nGP8cIKhx6M5yizJjuWNfY="; posting-host="affe2e68f188d099451ee49d810ad8d6" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:VzzlVXOQzKyCTeHpbJutqWPWsyM= sha256:Y4hwVzKg032pW8KsOg5s8VcJ9BfsWHmXaR6ds/bOoJ8= sha1:XMsKqNm1hkSozdZvfavWpVuKmJ8= sha256:cUM8S6HyfBiGNF0N4dy4aqRfJSBOZ8x+PgxyXECb1Pk=