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

Pre-RFC decimal data type

Thread Next
Ovid via perl5-porters
August 5, 2021 08:17
Pre-RFC decimal data type
Message ID:
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).
Imagine this evaluating as true (fake syntax):

if ( 0 == .1d + .2d - .3d ) { ... }

This would be a huge boon to anyone writing financial applications in Perl, or who otherwise needs to guarantee accuracy to a certain number of significant digits. Obviously, when decimal and floating points are mixed, we'd have to figure out the best way to address that. (C# requires casting, but I suspect we can't have nice toys).
Many languages currently support decimal data types natively (COBOL, C#) or via core libraries (Java, Python).
For what it's worth (not much), here's a Wikipedia page:
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile development 
Buy my book! -
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About