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

Pre-RFC decimal data type

Thread Next
From:
Ovid via perl5-porters
Date:
August 5, 2021 08:17
Subject:
Pre-RFC decimal data type
Message ID:
1103793896.1919607.1628151442332@mail.yahoo.com
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: https://en.wikipedia.org/wiki/Decimal_data_type
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
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