2Decimal floats are (a) part of the IEEE 758-2008 standard for
floating-point arithmetic,
(b) implemented as part of the instruction set in IBM z/Series and
POWER computers,
(c) allowed for in the current C standard, (d) partially supported by GCC
https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Decimal-Float.html
and (e) available for most machines via the "reference implementation" in C.
The current COBOL standard basically defines its arithmetic in terms of this.
Java of course has BigDecimal.  While decimal floats became part of IEEE 754 in
2008, they were previously covered by IEEE 854.

Reverting to ScaledDecimal, let us consider the 10.0s1 / 3 example.
There is a huge problem here with no really satisfactory answer.
In my library, it currently answers 3.3s1, exactly equal to 33/10.
In Squeak/Pharo, it answers "I am really 10/3 but print me with one decimal",
so you see 3.3a1 but it *behaves* like 10.3.
In VisualAge Smalltalk you get  3.333333333333333333333333333333
If it were not for the fact that the ANSI Smalltalk standard appears to
require that <scaled decimal> / <integer> yield a <scaled decimal>,
I would prefer to answer 10/3.  Decimals just plain are not closed under
division (although they are closed under addition, subtraction, and
multiplication).  When it comes to scaled decimals, the ANSI Smalltalk
standard is frankly a mess.  Amongst other things, it defers the
semantics of operations on them to the Language-Independent
Arithmetic standard, which explicitly denies having anything to say about them!

I understand why my library does what it does.  I even tried to
publish a paper about it.
I understand why VisualAge Smalltalk does what it does.  (I've read
IBM/360 PrincOps.)
I do NOT understand why Squeak and Pharo do what they do, and if anyone knows
the rationale for their ScaledDecmal please tell me.

On Thu, 17 Jun 2021 at 06:29, Esteban Maringolo <emaring...@gmail.com> wrote:
>
> I didn't know there were decimal floats.
>
> Are they used elsewhere?
>
> Esteban A. Maringolo
>
> On Wed, Jun 16, 2021 at 11:20 AM Konrad Hinsen
> <konrad.hin...@fastmail.net> wrote:
> >
> > On 16/06/2021 15:52, Sven Van Caekenberghe wrote:
> > > I am also a bit intrigued by this. Like you said: several other 
> > > programming languages (I tried a couple of Common Lisp and Scheme 
> > > implementations) do the same as Pharo, but handheld calculators, normal 
> > > and scientific, do not.
> >
> > Handheld calculators use decimal floats, not binary floats. That doesn't
> > remove rounding issues, but it makes conversion to and from print
> > representations loss-free.
> >
> >
> > Konrad

Reply via email to