www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggested enhancement: New basic datatype: 'dec'.

reply "DLearner" <bmqazwsx123 gmail.com> writes:
A signed decimal datatype to support writing userland accounting 
programs (major business application area), without loss of 
accuracy (including losses caused by not all 'decimal decimals' 
having exact 'binary decimal' representation).

Syntax:

dec(a,b) foo;

Where a is an integer 1<=a<=99 (total no of digits, including any 
decimal digits).
b is also an integer 0 <= b <= a (no. of decimal digits);

b = 0 implies b can be omitted e.g. 'dec(4,0) foo;' can also be 
written 'dec(4) foo;'.

Basic arithmetic supported.
Normal assignment rule is truncation/padding, but a 'round(d)' 
function to round to d decimal places provided.
Also provide a formatting function to convert dec type to 
printable character string.

Not very interesting from a theoretical viewpoint (just COBOL or 
PL/I datatype),
but (I think) of practical value in encouraging D adoption.
Jun 25 2015
next sibling parent "Dejan Lekic" <dejan.lekic gmail.com> writes:
I must admit I only quickly read the post - I think this can 
relatively easily be done as a template, and (depending on the 
quality of that template) it could go into Phobos.
Jun 25 2015
prev sibling next sibling parent "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 25 June 2015 at 09:24:28 UTC, DLearner wrote:
 A signed decimal datatype to support writing userland 
 accounting programs (major business application area), without 
 loss of accuracy (including losses caused by not all 'decimal 
 decimals' having exact 'binary decimal' representation).

 Not very interesting from a theoretical viewpoint (just COBOL 
 or PL/I datatype),
 but (I think) of practical value in encouraging D adoption.
D has excellent support for user-defined numerical data types, so you can write such as a library. You too can do it, especially if you have experience with such accounting applications.
Jun 25 2015
prev sibling parent "Adrian Matoga" <epi atari8.info> writes:
On Thursday, 25 June 2015 at 09:24:28 UTC, DLearner wrote:
 A signed decimal datatype to support writing userland 
 accounting programs (major business application area), without 
 loss of accuracy (including losses caused by not all 'decimal 
 decimals' having exact 'binary decimal' representation).

 Syntax:

 dec(a,b) foo;

 Where a is an integer 1<=a<=99 (total no of digits, including 
 any decimal digits).
 b is also an integer 0 <= b <= a (no. of decimal digits);

 b = 0 implies b can be omitted e.g. 'dec(4,0) foo;' can also be 
 written 'dec(4) foo;'.

 Basic arithmetic supported.
 Normal assignment rule is truncation/padding, but a 'round(d)' 
 function to round to d decimal places provided.
 Also provide a formatting function to convert dec type to 
 printable character string.

 Not very interesting from a theoretical viewpoint (just COBOL 
 or PL/I datatype),
 but (I think) of practical value in encouraging D adoption.
Decimal data type is something that can and should be done in library, not in the language itself. There is already a proposed implementation, you too can review it: http://wiki.dlang.org/Review_Queue https://github.com/andersonpd/eris/tree/master/decimal
Jun 25 2015