Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Klein bottle for rent -- inquire within.


devel / comp.lang.c / Re: Can this program be improved?

SubjectAuthor
* Can this program be improved?Manu Raju
+* Re: Can this program be improved?Andrey Tarasevich
|+- Re: Can this program be improved?David Brown
|+- Re: Can this program be improved?Tim Rentsch
|+- Re: Can this program be improved?Manfred
|+* Re: Can this program be improved?Manu Raju
||`* Re: Can this program be improved?Lew Pitcher
|| `* Re: Can this program be improved?Manu Raju
||  +- Re: Can this program be improved?Bart
||  +- Re: Can this program be improved?Richard Damon
||  `- Re: Can this program be improved?Lew Pitcher
|`* Re: Can this program be improved?Guillaume
| `* Re: Can this program be improved?Bart
|  +* Re: Can this program be improved?Andrey Tarasevich
|  |+* Re: Can this program be improved?James Kuyper
|  ||`* Re: Can this program be improved?Andrey Tarasevich
|  || `- Re: Can this program be improved?David Brown
|  |`* Re: Can this program be improved?Bart
|  | `- Re: Can this program be improved?Bart
|  `* Re: Can this program be improved?Keith Thompson
|   +* Re: Can this program be improved?Bart
|   |+* Re: Can this program be improved?Scott Lurndal
|   ||+- Re: Can this program be improved?Keith Thompson
|   ||`* Re: Can this program be improved?Kaz Kylheku
|   || `* Re: Can this program be improved?Bart
|   ||  `* Re: Can this program be improved?Kaz Kylheku
|   ||   `- Re: Can this program be improved?Bart
|   |`* Re: Can this program be improved?Keith Thompson
|   | +* Re: Can this program be improved?Kaz Kylheku
|   | |`* Re: Can this program be improved?Keith Thompson
|   | | `- Re: Can this program be improved?Kaz Kylheku
|   | `* Re: Can this program be improved?Bart
|   |  +- Re: Can this program be improved?Malcolm McLean
|   |  `* Re: Can this program be improved?Manfred
|   |   `* Re: Can this program be improved?Bart
|   |    +- Re: Can this program be improved?Manfred
|   |    `* Re: Can this program be improved?James Kuyper
|   |     `* Re: Can this program be improved?Bart
|   |      +- Re: Can this program be improved?james...@alumni.caltech.edu
|   |      `* Re: Can this program be improved?Keith Thompson
|   |       `* Re: Can this program be improved?Bart
|   |        `* Re: Can this program be improved?Keith Thompson
|   |         +* Re: Can this program be improved?Malcolm McLean
|   |         |`* Re: Can this program be improved?Keith Thompson
|   |         | `* Re: Can this program be improved?Malcolm McLean
|   |         |  +* Re: Can this program be improved?Keith Thompson
|   |         |  |`* Re: Can this program be improved?Malcolm McLean
|   |         |  | +- Re: Can this program be improved?Scott Lurndal
|   |         |  | `* Re: Can this program be improved?Keith Thompson
|   |         |  |  +* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |+* Re: Can this program be improved?Kenny McCormack
|   |         |  |  ||`* Re: Can this program be improved?Malcolm McLean
|   |         |  |  || `- Re: Can this program be improved?Kenny McCormack
|   |         |  |  |+- Re: Can this program be improved?David Brown
|   |         |  |  |`* Re: Can this program be improved?Keith Thompson
|   |         |  |  | `* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  +- Re: Can this program be improved?Öö Tiib
|   |         |  |  |  +* Re: Can this program be improved?Mateusz Viste
|   |         |  |  |  |`* Re: Can this program be improved?Guillaume
|   |         |  |  |  | +* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  | |`* Re: Can this program be improved?Keith Thompson
|   |         |  |  |  | | +* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  | | |`* Re: Can this program be improved?Keith Thompson
|   |         |  |  |  | | | `- Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  | | `- Re: Can this program be improved?Scott Lurndal
|   |         |  |  |  | `* Re: Can this program be improved?Bart
|   |         |  |  |  |  `* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  |   +* Re: Can this program be improved?Scott Lurndal
|   |         |  |  |  |   |`* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |  |   | `- Re: Can this program be improved?Guillaume
|   |         |  |  |  |   `* Re: Can this program be improved?Bart
|   |         |  |  |  |    +- Re: Can this program be improved?Scott Lurndal
|   |         |  |  |  |    `- Re: Can this program be improved?Manfred
|   |         |  |  |  `* Re: Can this program be improved?David Brown
|   |         |  |  |   `* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |    +* Re: Can this program be improved?David Brown
|   |         |  |  |    |`* Re: Can this program be improved?Malcolm McLean
|   |         |  |  |    | `* Re: Can this program be improved?David Brown
|   |         |  |  |    |  `- Re: Can this program be improved?Kenny McCormack
|   |         |  |  |    `- Re: Can this program be improved?Kenny McCormack
|   |         |  |  `- Re: Can this program be improved?Kenny McCormack
|   |         |  `* Re: Can this program be improved?Mateusz Viste
|   |         |   `* Re: Can this program be improved?Malcolm McLean
|   |         |    `* Re: Can this program be improved?David Brown
|   |         |     `* Re: Can this program be improved?Malcolm McLean
|   |         |      +* Re: Can this program be improved?Mateusz Viste
|   |         |      |+- Re: Can this program be improved?Bart
|   |         |      |`* Re: Can this program be improved?Malcolm McLean
|   |         |      | `* Re: Can this program be improved?Mateusz Viste
|   |         |      |  `- Re: Can this program be improved?Malcolm McLean
|   |         |      `* Re: Can this program be improved?Scott Lurndal
|   |         |       `- Re: Can this program be improved?Kenny McCormack
|   |         `- Re: Can this program be improved?Bart
|   `- Re: Can this program be improved?Kaz Kylheku
+* Re: Can this program be improved?Bart
|`- Re: Can this program be improved?Manu Raju
+* Re: Can this program be improved?Lew Pitcher
|+* Re: Can this program be improved?Öö Tiib
||+* Re: Can this program be improved?Lew Pitcher
|||`- Re: Can this program be improved?Öö Tiib
||`* Re: Can this program be improved?Chris M. Thomasson
|+* Re: Can this program be improved?Stefan Ram
|+- Re: Can this program be improved?Andrey Tarasevich
|`- Re: Can this program be improved?Manu Raju
+* Re: Can this program be improved?Tim Rentsch
+* Re: Can this program be improved?Malcolm McLean
`- Re: Can this program be improved?Lew Pitcher

Pages:12345
Re: Can this program be improved?

<5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19844&group=comp.lang.c#19844

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:cab:: with SMTP id s11mr46425664qvs.131.1641321330274;
Tue, 04 Jan 2022 10:35:30 -0800 (PST)
X-Received: by 2002:a05:622a:5d2:: with SMTP id d18mr45575994qtb.390.1641321330097;
Tue, 04 Jan 2022 10:35:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 4 Jan 2022 10:35:29 -0800 (PST)
In-Reply-To: <sr1vgu$u1j$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:1c55:7c30:ff94:4dab;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:1c55:7c30:ff94:4dab
References: <sq63mi$gom$1@dont-email.me> <sqi3p9$1bia$1@gioia.aioe.org>
<sqi72e$q7e$1@dont-email.me> <87sfub2g2t.fsf@nosuchdomain.example.com>
<sqiprq$1kk$1@dont-email.me> <87o84z2bsi.fsf@nosuchdomain.example.com>
<sqj0mf$532$1@dont-email.me> <sqkphm$p3g$1@gioia.aioe.org>
<sqlpcn$3fa$1@dont-email.me> <sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com> <9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com> <0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com>
Subject: Re: Can this program be improved?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 04 Jan 2022 18:35:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 49
 by: Malcolm McLean - Tue, 4 Jan 2022 18:35 UTC

On Tuesday, 4 January 2022 at 17:18:36 UTC, Guillaume wrote:
> Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
> > 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
> >> will have been melted down for metal. So is 53 bits enough? I don't
> >> write programs that deal withh amounts of money, so I don't really
> >> know. However if I had to choose a C type, I'd probably go for
> >> integer representation of amounts in cents, using a double.
> >
> > A double is nice to represent not-100%-precise fractional units,
> > it really does not have its place in any kind of financial
> > program, esp. if the goal is storing cents anyway.
> Absolutely. Using FP for financial calculations is for people who don't
> know arithmetics. Maybe teaching some math (again) to CS students would
> help, here? :)
>
> At the very least, if you absolutely want to use FP for this, at least
> use decimal FP. Although it can still have precision issues due to its
> floating point nature, at least rounding will not yield gross errors.
>
> And if you're OK with using integers, but are afraid fixed-size ones (at
> least 64 bits) could be an unacceptable limit down the road, just use
> arbitrary precision arithmetic. And you don't need to hand-implement
> that, unless it's your thing. GNU GMP is great.
>
> One of the many problems with FP can be easily shown. Apart from the
> usual unability to represent some numbers exactly, they also have an
> inherent problem when, for instance, adding very small numbers to very
> large ones.
>
> Of course if all you do is writing "toy programs", use whatever. But
> somehow, if this is a student work, I would have a problem with calling
> student exercises "toy programs". That would certainly give them the
> wrong idea about how to do things properly. If they once used FP for
> financial operations, even on a small exercise, how can you know they
> won't do the same later on at work when having to write code dealing
> with financial calculations?
>
The central difficulty is that people have no problem with the idea
that an integer type should hold an amount in cents. But for some reason
they think that a floating point type must hold an amount in dollars.
Probably because an amount of 110 cents is always written as 1.10
dollars for the end-user.

Once you make that leap, you'll see that you can use floating point types to
represent integers.

Re: Can this program be improved?

<sr24c4$i02$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19846&group=comp.lang.c#19846

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 4 Jan 2022 18:41:09 +0000
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <sr24c4$i02$1@dont-email.me>
References: <sq63mi$gom$1@dont-email.me> <sqi3p9$1bia$1@gioia.aioe.org>
<sqi72e$q7e$1@dont-email.me> <87sfub2g2t.fsf@nosuchdomain.example.com>
<sqiprq$1kk$1@dont-email.me> <87o84z2bsi.fsf@nosuchdomain.example.com>
<sqj0mf$532$1@dont-email.me> <sqkphm$p3g$1@gioia.aioe.org>
<sqlpcn$3fa$1@dont-email.me> <sqo2re$fdi$1@dont-email.me>
<sqo5gl$tbl$1@dont-email.me> <87v8z41efe.fsf@nosuchdomain.example.com>
<sqo8mt$cmr$1@dont-email.me> <87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 4 Jan 2022 18:41:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="95e67faf76542e62f90fb2b281e3c2f9";
logging-data="18434"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l0SDV+jm81e03HAx+gKTfNy0XXCnR9vs="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:03dTNsCke6619XDY7QbTzbnmDus=
In-Reply-To: <sr1vgu$u1j$1@gioia.aioe.org>
 by: Bart - Tue, 4 Jan 2022 18:41 UTC

On 04/01/2022 17:18, Guillaume wrote:
> Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
>> 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
>>> will have been melted down for metal. So is 53 bits enough? I don't
>>> write programs that deal withh amounts of money, so I don't really
>>> know. However if I had to choose a C type, I'd probably go for
>>> integer representation of amounts in cents, using a double.
>>
>> A double is nice to represent not-100%-precise fractional units,
>> it really does not have its place in any kind of financial
>> program, esp. if the goal is storing cents anyway.
>
> Absolutely. Using FP for financial calculations is for people who don't
> know arithmetics. Maybe teaching some math (again) to CS students would
> help, here? :)
>
> At the very least, if you absolutely want to use FP for this, at least
> use decimal FP. Although it can still have precision issues due to its
> floating point nature, at least rounding will not yield gross errors.

64-bit floating point can represent values up to c. 10 trillion dollars
to the nearest cent. (I think the limit corresponds to the 2**52 bits of
precision.)

It won't be to the exact cent if printed to many decimals, but if you
know it is supposed to represent values that end in exactly 0.00 to
0.99, then it will display properly if converted to text and rounded to
2 decimals.

So it can be used to store such values. Calculating with it is a
different matter if you are actually working with that kind of magnitude
and actually need 1-cent accuracy and reproducability (which is going to
be virtually nobody).

> And if you're OK with using integers, but are afraid fixed-size ones (at
> least 64 bits) could be an unacceptable limit down the road, just use
> arbitrary precision arithmetic. And you don't need to hand-implement
> that, unless it's your thing. GNU GMP is great.

No, it isn't. It's a massive great dependency. If you really need to use
it, look for GMP-lite (a solution using one .h and one .c file).

However to me that would be a sign of someone who doesn't know what
they're doing and just throws unnecessary precision at the problem in
the hope it will magically fix any issues.

Remember, even /decimal/ arbitrary precision integer or floating point
could implemented using just float types, by always working within the
known limitations of that type. Similarly, you can just directly work
within the known limitations of ieee754.

> One of the many problems with FP can be easily shown. Apart from the
> usual unability to represent some numbers exactly, they also have an
> inherent problem when, for instance, adding very small numbers to very
> large ones.

Can you give an example of a real-world financial calculation where that
could happen? I mean, other than adding $0.01 to $10,000,000,000,000.00
or so; just get real.

> Of course if all you do is writing "toy programs", use whatever. But
> somehow, if this is a student work, I would have a problem with calling
> student exercises "toy programs". That would certainly give them the
> wrong idea about how to do things properly. If they once used FP for
> financial operations, even on a small exercise, how can you know they
> won't do the same later on at work when having to write code dealing
> with financial calculations?

I've used floating point for financial work. The world didn't end that I
remember.

Re: Can this program be improved?

<6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19847&group=comp.lang.c#19847

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:4156:: with SMTP id k22mr35914004qko.615.1641322362613;
Tue, 04 Jan 2022 10:52:42 -0800 (PST)
X-Received: by 2002:a05:6214:21ec:: with SMTP id p12mr46645351qvj.82.1641322362429;
Tue, 04 Jan 2022 10:52:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 4 Jan 2022 10:52:42 -0800 (PST)
In-Reply-To: <sr24c4$i02$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:f819:ee2b:dcb1:6d3c;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:f819:ee2b:dcb1:6d3c
References: <sq63mi$gom$1@dont-email.me> <sqi3p9$1bia$1@gioia.aioe.org>
<sqi72e$q7e$1@dont-email.me> <87sfub2g2t.fsf@nosuchdomain.example.com>
<sqiprq$1kk$1@dont-email.me> <87o84z2bsi.fsf@nosuchdomain.example.com>
<sqj0mf$532$1@dont-email.me> <sqkphm$p3g$1@gioia.aioe.org>
<sqlpcn$3fa$1@dont-email.me> <sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com> <9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com> <0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org> <sr24c4$i02$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
Subject: Re: Can this program be improved?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 04 Jan 2022 18:52:42 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 73
 by: Malcolm McLean - Tue, 4 Jan 2022 18:52 UTC

On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
> On 04/01/2022 17:18, Guillaume wrote:
> > Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
> >> 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
> >>> will have been melted down for metal. So is 53 bits enough? I don't
> >>> write programs that deal withh amounts of money, so I don't really
> >>> know. However if I had to choose a C type, I'd probably go for
> >>> integer representation of amounts in cents, using a double.
> >>
> >> A double is nice to represent not-100%-precise fractional units,
> >> it really does not have its place in any kind of financial
> >> program, esp. if the goal is storing cents anyway.
> >
> > Absolutely. Using FP for financial calculations is for people who don't
> > know arithmetics. Maybe teaching some math (again) to CS students would
> > help, here? :)
> >
> > At the very least, if you absolutely want to use FP for this, at least
> > use decimal FP. Although it can still have precision issues due to its
> > floating point nature, at least rounding will not yield gross errors.
>
> 64-bit floating point can represent values up to c. 10 trillion dollars
> to the nearest cent. (I think the limit corresponds to the 2**52 bits of
> precision.)
>
53 bits. You get a "free" bit because the leading digit is always 1, except for
zero, which has a special representation.
>
> It won't be to the exact cent if printed to many decimals, but if you
> know it is supposed to represent values that end in exactly 0.00 to
> 0.99, then it will display properly if converted to text and rounded to
> 2 decimals.
>
> So it can be used to store such values. Calculating with it is a
> different matter if you are actually working with that kind of magnitude
> and actually need 1-cent accuracy and reproducability (which is going to
> be virtually nobody).
>
> > And if you're OK with using integers, but are afraid fixed-size ones (at
> > least 64 bits) could be an unacceptable limit down the road, just use
> > arbitrary precision arithmetic. And you don't need to hand-implement
> > that, unless it's your thing. GNU GMP is great.
>
> No, it isn't. It's a massive great dependency. If you really need to use
> it, look for GMP-lite (a solution using one .h and one .c file).
>
> However to me that would be a sign of someone who doesn't know what
> they're doing and just throws unnecessary precision at the problem in
> the hope it will magically fix any issues.
>
I checked a few real world financial implementations.
In Java, they have a class which can use either a 32-bit integer, a 64 bit integer,
or a "Big Decimal" as the underlying representation. The recommendation is
to use the Big Decimal. Presumably it will scale to arbitrarily values.

However Java isn't C. In C it's much harder to encapsulate an arbitrary-
sized number, pass it around, and perform calculations with it.

Re: Can this program be improved?

<yP0BJ.177520$VS2.44235@fx44.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19848&group=comp.lang.c#19848

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx44.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Can this program be improved?
Newsgroups: comp.lang.c
References: <sq63mi$gom$1@dont-email.me> <87bl0t1l05.fsf@nosuchdomain.example.com> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org> <sr24c4$i02$1@dont-email.me> <6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
Lines: 17
Message-ID: <yP0BJ.177520$VS2.44235@fx44.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 04 Jan 2022 19:00:46 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 04 Jan 2022 19:00:46 GMT
X-Received-Bytes: 1924
 by: Scott Lurndal - Tue, 4 Jan 2022 19:00 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:

>> However to me that would be a sign of someone who doesn't know what=20
>> they're doing and just throws unnecessary precision at the problem in=20
>> the hope it will magically fix any issues.=20
>>=20
>I checked a few real world financial implementations.
>In Java, they have a class which can use either a 32-bit integer, a 64 bit =
>integer,
>or a "Big Decimal" as the underlying representation. The recommendation is
>to use the Big Decimal. Presumably it will scale to arbitrarily values.
>
>However Java isn't C. In C it's much harder to encapsulate an arbitrary-
>sized number, pass it around, and perform calculations with it.

Which is why they don't use C, and instead use COBOL and JAVA.

Re: Can this program be improved?

<c79b4c6a-2170-4664-b788-5ceab80b1b37n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19849&group=comp.lang.c#19849

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:5ca:: with SMTP id d10mr45751945qtb.600.1641323717559;
Tue, 04 Jan 2022 11:15:17 -0800 (PST)
X-Received: by 2002:a05:622a:48e:: with SMTP id p14mr44596899qtx.553.1641323717377;
Tue, 04 Jan 2022 11:15:17 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 4 Jan 2022 11:15:17 -0800 (PST)
In-Reply-To: <yP0BJ.177520$VS2.44235@fx44.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3c41:dc75:b21b:7ff;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3c41:dc75:b21b:7ff
References: <sq63mi$gom$1@dont-email.me> <87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org>
<sr1vgu$u1j$1@gioia.aioe.org> <sr24c4$i02$1@dont-email.me>
<6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com> <yP0BJ.177520$VS2.44235@fx44.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c79b4c6a-2170-4664-b788-5ceab80b1b37n@googlegroups.com>
Subject: Re: Can this program be improved?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 04 Jan 2022 19:15:17 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 20
 by: Malcolm McLean - Tue, 4 Jan 2022 19:15 UTC

On Tuesday, 4 January 2022 at 19:00:57 UTC, Scott Lurndal wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> >On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
> >> However to me that would be a sign of someone who doesn't know what=20
> >> they're doing and just throws unnecessary precision at the problem in=20
> >> the hope it will magically fix any issues.=20
> >>=20
> >I checked a few real world financial implementations.
> >In Java, they have a class which can use either a 32-bit integer, a 64 bit =
> >integer,
> >or a "Big Decimal" as the underlying representation. The recommendation is
> >to use the Big Decimal. Presumably it will scale to arbitrarily values.
> >
> >However Java isn't C. In C it's much harder to encapsulate an arbitrary-
> >sized number, pass it around, and perform calculations with it.
> Which is why they don't use C, and instead use COBOL and JAVA.
>
That's often the real answer. Use Cobol for programs dealing mainly
with amounts of money. That's its niche.
But sometimes you might need to use C. For instance in the software
controlling a till.

Re: Can this program be improved?

<sr2cb9$1c5s$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19852&group=comp.lang.c#19852

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!UgLt14+w9tVHe1BtIa3HDQ.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 4 Jan 2022 21:57:06 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sr2cb9$1c5s$1@gioia.aioe.org>
References: <sq63mi$gom$1@dont-email.me>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
<sr24c4$i02$1@dont-email.me>
<6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
<yP0BJ.177520$VS2.44235@fx44.iad>
<c79b4c6a-2170-4664-b788-5ceab80b1b37n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="45244"; posting-host="UgLt14+w9tVHe1BtIa3HDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
 by: Guillaume - Tue, 4 Jan 2022 20:57 UTC

Le 04/01/2022 à 20:15, Malcolm McLean a écrit :
> On Tuesday, 4 January 2022 at 19:00:57 UTC, Scott Lurndal wrote:
>> Malcolm McLean <malcolm.ar...@gmail.com> writes:
>>> On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
>>>> However to me that would be a sign of someone who doesn't know what=20
>>>> they're doing and just throws unnecessary precision at the problem in=20
>>>> the hope it will magically fix any issues.=20
>>>> =20
>>> I checked a few real world financial implementations.
>>> In Java, they have a class which can use either a 32-bit integer, a 64 bit =
>>> integer,
>>> or a "Big Decimal" as the underlying representation. The recommendation is
>>> to use the Big Decimal. Presumably it will scale to arbitrarily values.
>>>
>>> However Java isn't C. In C it's much harder to encapsulate an arbitrary-
>>> sized number, pass it around, and perform calculations with it.
>> Which is why they don't use C, and instead use COBOL and JAVA.
>>
> That's often the real answer. Use Cobol for programs dealing mainly
> with amounts of money. That's its niche.
> But sometimes you might need to use C. For instance in the software
> controlling a till.

As I said, there's a whole lot of arbitrary-precision libraries for C,
Gnu GMP being a good, well known and stable one.

Re: Can this program be improved?

<sr2ckp$co8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19853&group=comp.lang.c#19853

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 4 Jan 2022 21:02:16 +0000
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <sr2ckp$co8$1@dont-email.me>
References: <sq63mi$gom$1@dont-email.me> <sqiprq$1kk$1@dont-email.me>
<87o84z2bsi.fsf@nosuchdomain.example.com> <sqj0mf$532$1@dont-email.me>
<sqkphm$p3g$1@gioia.aioe.org> <sqlpcn$3fa$1@dont-email.me>
<sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
<sr24c4$i02$1@dont-email.me>
<6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 4 Jan 2022 21:02:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="95e67faf76542e62f90fb2b281e3c2f9";
logging-data="13064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/r1udRI8Jc6NGCvKfTVMyXbp/H78Ref/A="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:YzAG/MEqFY3E8XHW3MwY2dLIWfM=
In-Reply-To: <6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
 by: Bart - Tue, 4 Jan 2022 21:02 UTC

On 04/01/2022 18:52, Malcolm McLean wrote:
> On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
>> On 04/01/2022 17:18, Guillaume wrote:
>>> Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
>>>> 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
>>>>> will have been melted down for metal. So is 53 bits enough? I don't
>>>>> write programs that deal withh amounts of money, so I don't really
>>>>> know. However if I had to choose a C type, I'd probably go for
>>>>> integer representation of amounts in cents, using a double.
>>>>
>>>> A double is nice to represent not-100%-precise fractional units,
>>>> it really does not have its place in any kind of financial
>>>> program, esp. if the goal is storing cents anyway.
>>>
>>> Absolutely. Using FP for financial calculations is for people who don't
>>> know arithmetics. Maybe teaching some math (again) to CS students would
>>> help, here? :)
>>>
>>> At the very least, if you absolutely want to use FP for this, at least
>>> use decimal FP. Although it can still have precision issues due to its
>>> floating point nature, at least rounding will not yield gross errors.
>>
>> 64-bit floating point can represent values up to c. 10 trillion dollars
>> to the nearest cent. (I think the limit corresponds to the 2**52 bits of
>> precision.)
>>
> 53 bits. You get a "free" bit because the leading digit is always 1, except for
> zero, which has a special representation.

If the 53rd bit is always 1, then isn't the precision determined by the
other 52 bits?

So if a mantissa was only going to be 0b10 or 0b11, to me that's only
1-bit precision!

>> It won't be to the exact cent if printed to many decimals, but if you
>> know it is supposed to represent values that end in exactly 0.00 to
>> 0.99, then it will display properly if converted to text and rounded to
>> 2 decimals.
>>
>> So it can be used to store such values. Calculating with it is a
>> different matter if you are actually working with that kind of magnitude
>> and actually need 1-cent accuracy and reproducability (which is going to
>> be virtually nobody).
>>
>>> And if you're OK with using integers, but are afraid fixed-size ones (at
>>> least 64 bits) could be an unacceptable limit down the road, just use
>>> arbitrary precision arithmetic. And you don't need to hand-implement
>>> that, unless it's your thing. GNU GMP is great.
>>
>> No, it isn't. It's a massive great dependency. If you really need to use
>> it, look for GMP-lite (a solution using one .h and one .c file).
>>
>> However to me that would be a sign of someone who doesn't know what
>> they're doing and just throws unnecessary precision at the problem in
>> the hope it will magically fix any issues.
>>
> I checked a few real world financial implementations.
> In Java, they have a class which can use either a 32-bit integer, a 64 bit integer,
> or a "Big Decimal" as the underlying representation.

32 bits doesn't sound much but it will represent up to £21m to the exact
penny. So fine for storage up to such limits, but you'd need a bigger
type to do anything beyond adding and subtracting.

> The recommendation is
> to use the Big Decimal. Presumably it will scale to arbitrarily values.

Say you have an amount of exactly EC$100.00 (a currency I've worked
with). You want to convert it to US$ at a rate of 1 US$ = $2.7169 EC$ (I
believe this is the official exchange rate).

The result is US$36.8066546431594832345688100408..., it goes on forever.

To the nearest US cent, it'll be US$36.81, but it's approximate. You'd
get that result with Big Decimal, float64, or float32. Big decimal
hasn't helped here.

Re: Can this program be improved?

<j73BJ.272817$IW4.135808@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19854&group=comp.lang.c#19854

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Can this program be improved?
Newsgroups: comp.lang.c
References: <sq63mi$gom$1@dont-email.me> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org> <sr24c4$i02$1@dont-email.me> <6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com> <sr2ckp$co8$1@dont-email.me>
Lines: 84
Message-ID: <j73BJ.272817$IW4.135808@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 04 Jan 2022 21:38:23 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 04 Jan 2022 21:38:23 GMT
X-Received-Bytes: 4990
 by: Scott Lurndal - Tue, 4 Jan 2022 21:38 UTC

Bart <bc@freeuk.com> writes:
>On 04/01/2022 18:52, Malcolm McLean wrote:
>> On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
>>> On 04/01/2022 17:18, Guillaume wrote:
>>>> Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
>>>>> 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
>>>>>> will have been melted down for metal. So is 53 bits enough? I don't
>>>>>> write programs that deal withh amounts of money, so I don't really
>>>>>> know. However if I had to choose a C type, I'd probably go for
>>>>>> integer representation of amounts in cents, using a double.
>>>>>
>>>>> A double is nice to represent not-100%-precise fractional units,
>>>>> it really does not have its place in any kind of financial
>>>>> program, esp. if the goal is storing cents anyway.
>>>>
>>>> Absolutely. Using FP for financial calculations is for people who don't
>>>> know arithmetics. Maybe teaching some math (again) to CS students would
>>>> help, here? :)
>>>>
>>>> At the very least, if you absolutely want to use FP for this, at least
>>>> use decimal FP. Although it can still have precision issues due to its
>>>> floating point nature, at least rounding will not yield gross errors.
>>>
>>> 64-bit floating point can represent values up to c. 10 trillion dollars
>>> to the nearest cent. (I think the limit corresponds to the 2**52 bits of
>>> precision.)
>>>
>> 53 bits. You get a "free" bit because the leading digit is always 1, except for
>> zero, which has a special representation.
>
>If the 53rd bit is always 1, then isn't the precision determined by the
>other 52 bits?
>
>So if a mantissa was only going to be 0b10 or 0b11, to me that's only
>1-bit precision!
>
>>> It won't be to the exact cent if printed to many decimals, but if you
>>> know it is supposed to represent values that end in exactly 0.00 to
>>> 0.99, then it will display properly if converted to text and rounded to
>>> 2 decimals.
>>>
>>> So it can be used to store such values. Calculating with it is a
>>> different matter if you are actually working with that kind of magnitude
>>> and actually need 1-cent accuracy and reproducability (which is going to
>>> be virtually nobody).
>>>
>>>> And if you're OK with using integers, but are afraid fixed-size ones (at
>>>> least 64 bits) could be an unacceptable limit down the road, just use
>>>> arbitrary precision arithmetic. And you don't need to hand-implement
>>>> that, unless it's your thing. GNU GMP is great.
>>>
>>> No, it isn't. It's a massive great dependency. If you really need to use
>>> it, look for GMP-lite (a solution using one .h and one .c file).
>>>
>>> However to me that would be a sign of someone who doesn't know what
>>> they're doing and just throws unnecessary precision at the problem in
>>> the hope it will magically fix any issues.
>>>
>> I checked a few real world financial implementations.
>> In Java, they have a class which can use either a 32-bit integer, a 64 bit integer,
>> or a "Big Decimal" as the underlying representation.
>
>32 bits doesn't sound much but it will represent up to £21m to the exact
>penny. So fine for storage up to such limits, but you'd need a bigger
>type to do anything beyond adding and subtracting.
>
>> The recommendation is
>> to use the Big Decimal. Presumably it will scale to arbitrarily values.
>
>Say you have an amount of exactly EC$100.00 (a currency I've worked
>with). You want to convert it to US$ at a rate of 1 US$ = $2.7169 EC$ (I
>believe this is the official exchange rate).
>
>The result is US$36.8066546431594832345688100408..., it goes on forever.
>
>To the nearest US cent, it'll be US$36.81, but it's approximate. You'd
>get that result with Big Decimal, float64, or float32. Big decimal
>hasn't helped here.
>

$ printf "%u\n" $(( 1000000000 / 27169 ))
36806

Round the LSD and insert a decimal point.

Re: Can this program be improved?

<sr2g4l$13n1$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19855&group=comp.lang.c#19855

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!WMZMUsDKyFE1ypA6X6tP9w.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 4 Jan 2022 23:01:57 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sr2g4l$13n1$1@gioia.aioe.org>
References: <sq63mi$gom$1@dont-email.me>
<87o84z2bsi.fsf@nosuchdomain.example.com> <sqj0mf$532$1@dont-email.me>
<sqkphm$p3g$1@gioia.aioe.org> <sqlpcn$3fa$1@dont-email.me>
<sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
<sr24c4$i02$1@dont-email.me>
<6d78fbba-8bde-4bf4-9f90-40e59bcd61a3n@googlegroups.com>
<sr2ckp$co8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="36577"; posting-host="WMZMUsDKyFE1ypA6X6tP9w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Tue, 4 Jan 2022 22:01 UTC

On 1/4/2022 10:02 PM, Bart wrote:
> On 04/01/2022 18:52, Malcolm McLean wrote:
>> On Tuesday, 4 January 2022 at 18:41:20 UTC, Bart wrote:
>>> On 04/01/2022 17:18, Guillaume wrote:
>>>> Le 04/01/2022 à 09:23, Mateusz Viste a écrit :
>>>>> 2022-01-03 at 15:43 -0800, Malcolm McLean wrote:
>>>>>> will have been melted down for metal. So is 53 bits enough? I don't
>>>>>> write programs that deal withh amounts of money, so I don't really
>>>>>> know. However if I had to choose a C type, I'd probably go for
>>>>>> integer representation of amounts in cents, using a double.
>>>>>
>>>>> A double is nice to represent not-100%-precise fractional units,
>>>>> it really does not have its place in any kind of financial
>>>>> program, esp. if the goal is storing cents anyway.
>>>>
>>>> Absolutely. Using FP for financial calculations is for people who don't
>>>> know arithmetics. Maybe teaching some math (again) to CS students would
>>>> help, here? :)
>>>>
>>>> At the very least, if you absolutely want to use FP for this, at least
>>>> use decimal FP. Although it can still have precision issues due to its
>>>> floating point nature, at least rounding will not yield gross errors.
>>>
>>> 64-bit floating point can represent values up to c. 10 trillion dollars
>>> to the nearest cent. (I think the limit corresponds to the 2**52 bits of
>>> precision.)
>>>
>> 53 bits. You get a "free" bit because the leading digit is always 1,
>> except for
>> zero, which has a special representation.
>
> If the 53rd bit is always 1, then isn't the precision determined by the
> other 52 bits?

No, it's 53 bits of precision, or, in other words, 53 significant binary
digits.
The extra 1 bit is the result of proper choice of the exponent
representation.
However, it is not as if this extra bit came out of some magic, it has a
price and it is called subnormal numbers (or denormals).

>
> So if a mantissa was only going to be 0b10 or 0b11, to me that's only
> 1-bit precision!

No, it's not about choosing an arbitrary prefix, it is the result of 2
facts:
- any leading zeros can be converted into proper exponent adjustment, up
to the limit given by the size of the exponent.
- in binary arithmetic the first nonzero digit is always 1 :)

>
>>> It won't be to the exact cent if printed to many decimals, but if you
>>> know it is supposed to represent values that end in exactly 0.00 to
>>> 0.99, then it will display properly if converted to text and rounded to
>>> 2 decimals.
>>>
>>> So it can be used to store such values. Calculating with it is a
>>> different matter if you are actually working with that kind of magnitude
>>> and actually need 1-cent accuracy and reproducability (which is going to
>>> be virtually nobody).
>>>
>>>> And if you're OK with using integers, but are afraid fixed-size ones
>>>> (at
>>>> least 64 bits) could be an unacceptable limit down the road, just use
>>>> arbitrary precision arithmetic. And you don't need to hand-implement
>>>> that, unless it's your thing. GNU GMP is great.
>>>
>>> No, it isn't. It's a massive great dependency. If you really need to use
>>> it, look for GMP-lite (a solution using one .h and one .c file).
>>>
>>> However to me that would be a sign of someone who doesn't know what
>>> they're doing and just throws unnecessary precision at the problem in
>>> the hope it will magically fix any issues.
>>>
>> I checked a few real world financial implementations.
>> In Java, they have a class which can use either a 32-bit integer, a 64
>> bit integer,
>> or a "Big Decimal" as the underlying representation.
>
> 32 bits doesn't sound much but it will represent up to £21m to the exact
> penny. So fine for storage up to such limits, but you'd need a bigger
> type to do anything beyond adding and subtracting.
>
>> The recommendation is
>> to use the Big Decimal. Presumably it will scale to arbitrarily values.
>
> Say you have an amount of exactly EC$100.00 (a currency I've worked
> with). You want to convert it to US$ at a rate of 1 US$ = $2.7169 EC$ (I
> believe this is the official exchange rate).
>
> The result is US$36.8066546431594832345688100408..., it goes on forever.
>
> To the nearest US cent, it'll be US$36.81, but it's approximate. You'd
> get that result with Big Decimal, float64, or float32. Big decimal
> hasn't helped here.
>

Rounding errors smaller than a cent in the final result are obviously OK
- they can't be helped, and such fractional difference couldn't be paid
for anyway :)
But the problem is that if you use naive FP arithmetic you may end up
with errors in the final result that are larger than a cent (sometimes
much larger), which is not OK.

Re: Can this program be improved?

<87tuejyx2z.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19856&group=comp.lang.c#19856

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 04 Jan 2022 14:07:00 -0800
Organization: None to speak of
Lines: 33
Message-ID: <87tuejyx2z.fsf@nosuchdomain.example.com>
References: <sq63mi$gom$1@dont-email.me> <sqj0mf$532$1@dont-email.me>
<sqkphm$p3g$1@gioia.aioe.org> <sqlpcn$3fa$1@dont-email.me>
<sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
<5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b7c4ed9c2183a3b080a530a749104d95";
logging-data="30690"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EMjdL6fgI7pUGYHCItSHg"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:7aFwr69oNFhrSa7tDD/L37Wcqhk=
sha1:HeECZhl+kW2gpddJYfCXJSVPKfs=
 by: Keith Thompson - Tue, 4 Jan 2022 22:07 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
> The central difficulty is that people have no problem with the idea
> that an integer type should hold an amount in cents. But for some reason
> they think that a floating point type must hold an amount in dollars.
> Probably because an amount of 110 cents is always written as 1.10
> dollars for the end-user.
>
> Once you make that leap, you'll see that you can use floating point types to
> represent integers.

Or -- now hear me out -- you can use integers to represent integers.

The central difficulty is that there are rules that regulate how
financial calculations must be done. I don't know what those rules are,
but I speculate that floating-point, even if used to represent cents,
does not satisfy those rules. For anything more complicated than
addition and subtraction, there will be rounding errors that have to be
resolved *correctly*. Now if IEEE 754 floating-point happens to meet
the regulatory requirements, then that's what you should use, but I
don't think that's the case.

Doing all this stuff correctly is a solved problem. I doubt that anyone
here happens to know the details; as far as I know none of the regulars
work in finance. We're all speculating.

If someone has a reference to the actual rules used by banks and other
financial institutions, it would be interesting to see that.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Can this program be improved?

<1393d15f-e5ba-4ff2-977c-0618f457e0ebn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19859&group=comp.lang.c#19859

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:4495:: with SMTP id x21mr36425929qkp.604.1641337881149; Tue, 04 Jan 2022 15:11:21 -0800 (PST)
X-Received: by 2002:a05:622a:48e:: with SMTP id p14mr45324503qtx.553.1641337881001; Tue, 04 Jan 2022 15:11:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 4 Jan 2022 15:11:20 -0800 (PST)
In-Reply-To: <87tuejyx2z.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3c41:dc75:b21b:7ff; posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3c41:dc75:b21b:7ff
References: <sq63mi$gom$1@dont-email.me> <sqj0mf$532$1@dont-email.me> <sqkphm$p3g$1@gioia.aioe.org> <sqlpcn$3fa$1@dont-email.me> <sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me> <87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me> <87r19s13w2.fsf@nosuchdomain.example.com> <9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com> <87k0fj12r3.fsf@nosuchdomain.example.com> <0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com> <87bl0t1l05.fsf@nosuchdomain.example.com> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org> <5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com> <87tuejyx2z.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1393d15f-e5ba-4ff2-977c-0618f457e0ebn@googlegroups.com>
Subject: Re: Can this program be improved?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 04 Jan 2022 23:11:21 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 50
 by: Malcolm McLean - Tue, 4 Jan 2022 23:11 UTC

On Tuesday, 4 January 2022 at 22:07:12 UTC, Keith Thompson wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> [...]
> > The central difficulty is that people have no problem with the idea
> > that an integer type should hold an amount in cents. But for some reason
> > they think that a floating point type must hold an amount in dollars.
> > Probably because an amount of 110 cents is always written as 1.10
> > dollars for the end-user.
> >
> > Once you make that leap, you'll see that you can use floating point types to
> > represent integers.
>
> Or -- now hear me out -- you can use integers to represent integers.
>
Yes, but a floating point type degrades gracefully as values get very large.
Hyperinflation. The bit that you snipped because you were so upset by
the sly little dig at a current politician that you couldn't see the point
that was being made.
Integers don't. They work perfectly until overflow occurs. Then you get nonsense
results, or a crash if you are lucky / careful.
>
> The central difficulty is that there are rules that regulate how
> financial calculations must be done. I don't know what those rules are,
> but I speculate that floating-point, even if used to represent cents,
> does not satisfy those rules. For anything more complicated than
> addition and subtraction, there will be rounding errors that have to be
> resolved *correctly*. Now if IEEE 754 floating-point happens to meet
> the regulatory requirements, then that's what you should use, but I
> don't think that's the case.
>
I've never written a real program to deal with amounts of money either.
But I'd be surprised if a legislature mandated a particular C language type
to hold monetary values. They might describe the required behaviour of
the system. That might well be satisfied by a system with 53 bits of
precision storing numbers in cents. If 53 bits are not enough, then going
to long double would probably satisfy the legislators.
>
> Doing all this stuff correctly is a solved problem. I doubt that anyone
> here happens to know the details; as far as I know none of the regulars
> work in finance. We're all speculating.
>
I'm not sure it is. No-one here except me has posted any details of real
systems. So we've no way of knowing whether hyperinflation has been
properly considered or not. It would be interesting to get someone who
has worked on financial information systems in Zimbabwe, for instance,
to hear what they did.
>
> If someone has a reference to the actual rules used by banks and other
> financial institutions, it would be interesting to see that.
>
Agreed. None of us have any real world experience.

Re: Can this program be improved?

<T%4BJ.104424$Gco3.46927@fx01.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19860&group=comp.lang.c#19860

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx01.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Can this program be improved?
Newsgroups: comp.lang.c
References: <sq63mi$gom$1@dont-email.me> <87bl0t1l05.fsf@nosuchdomain.example.com> <f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com> <b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com> <ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org> <5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com> <87tuejyx2z.fsf@nosuchdomain.example.com>
Lines: 45
Message-ID: <T%4BJ.104424$Gco3.46927@fx01.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 04 Jan 2022 23:46:59 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 04 Jan 2022 23:46:59 GMT
X-Received-Bytes: 3280
 by: Scott Lurndal - Tue, 4 Jan 2022 23:46 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>[...]
>> The central difficulty is that people have no problem with the idea
>> that an integer type should hold an amount in cents. But for some reason
>> they think that a floating point type must hold an amount in dollars.
>> Probably because an amount of 110 cents is always written as 1.10
>> dollars for the end-user.
>>
>> Once you make that leap, you'll see that you can use floating point types to
>> represent integers.
>
>Or -- now hear me out -- you can use integers to represent integers.
>
>The central difficulty is that there are rules that regulate how
>financial calculations must be done. I don't know what those rules are,
>but I speculate that floating-point, even if used to represent cents,
>does not satisfy those rules. For anything more complicated than
>addition and subtraction, there will be rounding errors that have to be
>resolved *correctly*. Now if IEEE 754 floating-point happens to meet
>the regulatory requirements, then that's what you should use, but I
>don't think that's the case.

Anecdotally, the first generation Burroughs B3500 BCD machine (1966) had
100 digit signed and unsigned integer arithmetic operations
(that could be performed on either 4-bit digits or 8-bit zoned-digits)
and had a floating point (real) unit with 2 digit signed exponent and
100 digit signed mantissa.

The machine was heavily sold into banks, insurance companies and other
finance industry customers.

In the second generation B4700 the real number (floating point) support was
completely removed because no customer used it. Note this was by
definition decimal floating point.

>
>Doing all this stuff correctly is a solved problem. I doubt that anyone
>here happens to know the details; as far as I know none of the regulars
>work in finance. We're all speculating.

We had benchmarks derived from customer code for the B3500 & successors in the MCP group,
but those have long been lost to history, bit-rot and thrown out boxes
of 9-track and 18-track tapes from Iron Mountain, sadly.

Re: Can this program be improved?

<87lezvysf8.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19861&group=comp.lang.c#19861

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Can this program be improved?
Date: Tue, 04 Jan 2022 15:47:39 -0800
Organization: None to speak of
Lines: 35
Message-ID: <87lezvysf8.fsf@nosuchdomain.example.com>
References: <sq63mi$gom$1@dont-email.me> <sqlpcn$3fa$1@dont-email.me>
<sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me>
<87v8z41efe.fsf@nosuchdomain.example.com> <sqo8mt$cmr$1@dont-email.me>
<87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com>
<87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com>
<87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com>
<8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com>
<87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com>
<sr1058$1thv$1@gioia.aioe.org> <sr1vgu$u1j$1@gioia.aioe.org>
<5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com>
<87tuejyx2z.fsf@nosuchdomain.example.com>
<1393d15f-e5ba-4ff2-977c-0618f457e0ebn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0901cb002f24d9c5d5c18296a5778f80";
logging-data="10164"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1X5V8yFvsL1L0zk0xs/ev"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:5L2V5VDyTJInXYyG3B0L97DQzSc=
sha1:wetuW81kPSaJgW0K3VNF27iseKw=
 by: Keith Thompson - Tue, 4 Jan 2022 23:47 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> On Tuesday, 4 January 2022 at 22:07:12 UTC, Keith Thompson wrote:
>> Malcolm McLean <malcolm.ar...@gmail.com> writes:
>> [...]
>> > The central difficulty is that people have no problem with the idea
>> > that an integer type should hold an amount in cents. But for some reason
>> > they think that a floating point type must hold an amount in dollars.
>> > Probably because an amount of 110 cents is always written as 1.10
>> > dollars for the end-user.
>> >
>> > Once you make that leap, you'll see that you can use floating point types to
>> > represent integers.
>>
>> Or -- now hear me out -- you can use integers to represent integers.
>>
> Yes, but a floating point type degrades gracefully as values get very large.

You're assuming that degradation is acceptable if it's "graceful".
If you know something about the actual regulations that implies that,
by all means share it.

My speculation is that regulations require specific results to be
accurate to the cent regardless of the magnitude of the quantities being
used, and that hyperinflation would not be accepted as an excuse for
off-by-one errors. If for whatever reason we started having to deal
with quantities that don't fit in 64 bits, for example, perhaps some
software would have to be updated -- or perhaps it can already handle
such cases.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Can this program be improved?

<b2c5f152-ce0c-4b5b-829b-3581c2223b10n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19862&group=comp.lang.c#19862

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:20ec:: with SMTP id 12mr46743600qvk.0.1641349826577;
Tue, 04 Jan 2022 18:30:26 -0800 (PST)
X-Received: by 2002:ac8:5950:: with SMTP id 16mr47205424qtz.462.1641349826425;
Tue, 04 Jan 2022 18:30:26 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!sewer!alphared!2.eu.feeder.erje.net!2.us.feeder.erje.net!feeder.erje.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 4 Jan 2022 18:30:26 -0800 (PST)
In-Reply-To: <87lezvysf8.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3c41:dc75:b21b:7ff;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3c41:dc75:b21b:7ff
References: <sq63mi$gom$1@dont-email.me> <sqlpcn$3fa$1@dont-email.me>
<sqo2re$fdi$1@dont-email.me> <sqo5gl$tbl$1@dont-email.me> <87v8z41efe.fsf@nosuchdomain.example.com>
<sqo8mt$cmr$1@dont-email.me> <87r19s13w2.fsf@nosuchdomain.example.com>
<9cca58b2-8310-45bb-98ac-4b71dc267a90n@googlegroups.com> <87k0fj12r3.fsf@nosuchdomain.example.com>
<0858a55c-fdd7-4aa8-9c56-0ec3b04840f4n@googlegroups.com> <87bl0t1l05.fsf@nosuchdomain.example.com>
<f96e4ea3-3c52-4869-99c6-c0806621b40cn@googlegroups.com> <8735m41lwy.fsf@nosuchdomain.example.com>
<b2918a53-acd6-4c46-9b58-6ac578bc055cn@googlegroups.com> <87y23wz9l9.fsf@nosuchdomain.example.com>
<ff338dd2-a4fe-4b06-8b4a-e3622b666c9en@googlegroups.com> <sr1058$1thv$1@gioia.aioe.org>
<sr1vgu$u1j$1@gioia.aioe.org> <5700fe69-acd6-4700-8b40-e48ad349fe33n@googlegroups.com>
<87tuejyx2z.fsf@nosuchdomain.example.com> <1393d15f-e5ba-4ff2-977c-0618f457e0ebn@googlegroups.com>
<87lezvysf8.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b2c5f152-ce0c-4b5b-829b-3581c2223b10n@googlegroups.com>
Subject: Re: Can this program be improved?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 05 Jan 2022 02:30:26 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 54
 by: Malcolm McLean - Wed, 5 Jan 2022 02:30 UTC

On Tuesday, 4 January 2022 at 23:47:49 UTC, Keith Thompson wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> > On Tuesday, 4 January 2022 at 22:07:12 UTC, Keith Thompson wrote:
> >> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> >> [...]
> >> > The central difficulty is that people have no problem with the idea
> >> > that an integer type should hold an amount in cents. But for some reason
> >> > they think that a floating point type must hold an amount in dollars.
> >> > Probably because an amount of 110 cents is always written as 1.10
> >> > dollars for the end-user.
> >> >
> >> > Once you make that leap, you'll see that you can use floating point types to
> >> > represent integers.
> >>
> >> Or -- now hear me out -- you can use integers to represent integers.
> >>
> > Yes, but a floating point type degrades gracefully as values get very large.
> You're assuming that degradation is acceptable if it's "graceful".
> If you know something about the actual regulations that implies that,
> by all means share it.
>
I'm assumignthat a graceful degradation is better than a sudden catastrophic
failure. As youu say, that doesn't necessarily hold. Sometimes no results
are better than slightly wrong results.
>
> My speculation is that regulations require specific results to be
> accurate to the cent regardless of the magnitude of the quantities being
> used, and that hyperinflation would not be accepted as an excuse for
> off-by-one errors. If for whatever reason we started having to deal
> with quantities that don't fit in 64 bits, for example, perhaps some
> software would have to be updated -- or perhaps it can already handle
> such cases.
>
Well let's look at what happened in Weimar Germany. A mark got up
to 4 trilion dollars. So if say that a hamburger is worth a dollar, a
hamburger in Hamburg in 1923 would have cost 4 trillion marks, or
400 trillion pfennigs. If the Germans had been using 64 bit computers
those days, you could sell about 10,000 hamburgers, by my calculations,
before the system fell over.
But if you look at the graph of the mark versus the dollar, whilst inflation
was severe, you didn't get into really startling figures until mid 1923.
For along time, it would have looked as though 64 bits were perfectly
adequate. The situation would have suddenly come on the developers.
By this time the Germans were starving and there were riots in the streets.

There would have been even worse riots if the transaction processing
system had fallen over. Would the bank have made the situation even
worse by kicking up a fuss over a few pfennigs? I wasn't there, I can't
answer that question. Where you've got that sort of social phenomenon
you don't always get a sane reaction.

But by all means argue that 53 bit or even 64 bit mantissa floating point
isn't enough and you need arbitrary-sized integers. That's a defensible
position. "Malcolm is an idiot becuase he mentioned the current
political situation" is not.

Pages:12345
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor