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

Re: Pre-RFC decimal data type

Thread Previous | Thread Next
From:
Darren Duncan
Date:
August 5, 2021 10:19
Subject:
Re: Pre-RFC decimal data type
Message ID:
ea091a29-7a39-6615-4c0c-5d4cd9181af2@darrenduncan.net
On 2021-08-05 1:17 a.m., Ovid via perl5-porters wrote:
> 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:
> 
> Imagine this evaluating as true (fake syntax):
> 
>     if ( 0 == .1d + .2d - .3d ) { ... }
> 
> Many languages currently support decimal data types natively (COBOL, C#) or via 
> core libraries (Java, Python).

I would suggest that the simplest implementation is just as a scaled integer.

So its precision would be the same as a Perl integer because it would be 
implementing using the same kind of machine integer, likely a 64-bit one.

Is about 18 digits of precision enough or do you need more?

I would expect that should handle fine the finance use case you mention.

In my experience finance apps often use scaled integers implemented at the app 
level anyway in absence of a decimal type, say as an integer that counts in 
100ths of a currency unit for example.

-- Darren Duncan

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