🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #897

Re: .5 against 0.5f

#897
From: Keith Thompson
Date: Tue, 27 Oct 2026 22:41
32 lines
2476 bytes
Kaz Kylheku <046-301-5902@kylheku.com> writes:
> On 2026-10-27, Scott Lurndal <scott@slp53.sl.home> wrote:
>> I ordered a couple of blu-rays from amazon last week, and the
>> confirmation email had the following for the total price:
>>
>>    Total
>>    75.71000000000001 USD

[...]

> FP is fine for pricing: look at how ridiculously close to 75.71
> the above approximation is. You just have to make sure never to
> let enough error accumulate so that an intermediate value
> is suddenly closer to the wrong penny value than the right one.

And how do you do that?

> (Actually you don't even want to get anywhere near that level
> of error.)

An arbitrarily small error can result in an ambiguity.  If you
calculate a result that should, mathematically, be very close to
75.715, it could round either to 75.71 or to 75.72.

I presume there are financial regulations that specify exactly how
these calculations are to be performed.  I have no idea what those
regulations say, but anyone writing financial code had better know
about the requirements and implement them correctly.

-- 
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: <11br9at$1uh9q$1@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-mail
References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <Ue6ES.2265$y_V1.1859@fx12.iad> <20261027125914.162@kylheku.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!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:41:33 -0700
Organization: None to speak of
Lines: 32
Message-ID: <11br9at$1uh9q$1@kst.eternal-september.org>
References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me>
	<Ue6ES.2265$y_V1.1859@fx12.iad> <20261027125914.162@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 27 Oct 2026 22:41:34 +0000 (UTC)
Injection-Info: kst.eternal-september.org;
	logging-data="2049338"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19j7e7cJLGIo70UewnS3ouv"; posting-host="9febde6641169f8329510415e264039e"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:fLChE+P0SQYxfWOqFT9nhOBGsos= sha256:6p83Hn5U0trx/xXwpZbvSOzPmvDBX5L9Eptjmkrdr8A=
	sha1:WE8ShBE/w+dN0+JGLK+dRA+xYLs= sha256:1kAUPwQaVQPQrb7VJwRTu2WRe+J4JBMl+yFrt6LDldg=