Article View: comp.lang.c
Article #956Re: .5 against 0.5f
From: Scott Lurndal
Date: Wed, 28 Oct 2026 16:23
Date: Wed, 28 Oct 2026 16:23
34 lines
2275 bytes
2275 bytes
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: >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. There are. And they explicitly forbid using binary floating point representations. Typically they use scaled fixed point 64-bit integers in modern code.
Technical Details
Message-ID:
<FjpES.74628$_pxc.26774@fx17.iad>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mailReferences:
<11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <Ue6ES.2265$y_V1.1859@fx12.iad> <20261027125914.162@kylheku.com> <11br9at$1uh9q$1@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!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail X-newsreader: xrn 9.03-beta-14-64bit Sender: scott@dragon.sl.home (Scott Lurndal) From: scott@slp53.sl.home (Scott Lurndal) Reply-To: slp53@pacbell.net Subject: Re: .5 against 0.5f Newsgroups: comp.lang.c References: <11bpvs7$1e6kc$2@dont-email.me> <11bqnvh$1np7s$1@dont-email.me> <Ue6ES.2265$y_V1.1859@fx12.iad> <20261027125914.162@kylheku.com> <11br9at$1uh9q$1@kst.eternal-september.org> Lines: 34 Message-ID: <FjpES.74628$_pxc.26774@fx17.iad> X-Complaints-To: abuse@usenetserver.com NNTP-Posting-Date: Wed, 28 Oct 2026 16:23:01 UTC Organization: UsenetServer - www.usenetserver.com Date: Wed, 28 Oct 2026 16:23:01 GMT X-Received-Bytes: 2041