develooper Front page | perl.perl5.porters | Postings from August 2021

Re: Pre-RFC decimal data type

Thread Previous | Thread Next
From:
Dan Book
Date:
August 5, 2021 17:00
Subject:
Re: Pre-RFC decimal data type
Message ID:
CABMkAVWANeM2iqYZ_=Lj8BTKU_uNxykiBMMX-BpkZ8fuH6fsEQ@mail.gmail.com
On Thu, Aug 5, 2021 at 12:54 PM Harald Jörg <haj@posteo.de> wrote:

> Ovid via perl5-porters <perl5-porters@perl.org> writes:
>
> > Since we're talking about wishes, would a decimal type be interesting?
> For example, in floating point, you can't represent
> > .3. So the following evaluates to false:
> >
> >  if ( 0 == .1 + .2 - .3 ) { ... }
> >
> > Fun fact: many COBOL-to-Java death marches have fallen down and not
> gotten back up because Java can't match COBOL's
> > precision due to lacking COBOL's native decimal type (and simulating a
> Decimal type via classes meant that Java couldn't
> > get the performance needed).
>
> In current Perl, you can get rather close like this:
>
>    perl -Mbignum=a,31 -E 'say (0 == 0.1 + 0.2 - 0.3)'  # prints 1
>    perl -Mbignum=a,31 -E 'say (1 == 1/3 + 1/3 + 1/3)'  # prints ''
>
> If decimals were in core instead of objects of a core library, they
> could avoid the bignum pitfall (https://perldoc.perl.org/bignum#Caveats)
> and also the overhead for objects and overloading.  Any further
> performance improvement could be applied to bignum as well.
>
> It might also encourage DB drivers to support the "decimal" data type
> where the DB engine supports it.
>

Yeah this is Math::BigFloat under the hood and that is the way to do
arbitrary precision decimals. But that has significant performance
implications even beyond the bignum problem and object overhead. If there's
a way (and this is the big question) to support limited precision decimals
with better performance than arbitrary precision decimals, I think core
support for that would be a significant boon for specific applications.

-Dan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About