www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Decimal Floating Point types.

reply "Iain Buclaw" <ibuclaw ubuntu.com> writes:
Speaking on behalf of Dejan, he expressed a wish to have such a 
type in D. (eg: such that assert(3.6 * 10 == 36.0) - which may 
not always be true on all architectures).


As maybe a new backend type is out of the question.  Perhaps we 
should create a new library type for the job - eg: _Decimal32, 
_Decimal64, _Decimal128.

Thoughts?


Regards
Iain.
Oct 29 2012
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Oct 29, 2012 at 07:43:35PM +0100, Iain Buclaw wrote:
 Speaking on behalf of Dejan, he expressed a wish to have such a type
 in D. (eg: such that assert(3.6 * 10 == 36.0) - which may not always
 be true on all architectures).
 
 As maybe a new backend type is out of the question.  Perhaps we
 should create a new library type for the job - eg: _Decimal32,
 _Decimal64, _Decimal128.

Implementing it in the library makes sense. T -- There's light at the end of the tunnel. It's the oncoming train.
Oct 29 2012
prev sibling next sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
10/29/2012 6:43 PM, Iain Buclaw пишет:
 Speaking on behalf of Dejan, he expressed a wish to have such a type in
 D. (eg: such that assert(3.6 * 10 == 36.0) - which may not always be
 true on all architectures).


 As maybe a new backend type is out of the question.  Perhaps we should
 create a new library type for the job - eg: _Decimal32, _Decimal64,
 _Decimal128.

 Thoughts?

I recall there was proposal for Phobos with both fixed decimal floating point types and arbitrary precision variants. And taking the role of good jinn: https://github.com/andersonpd/decimal/tree/master/decimal (seems very much alive and kicking)
 Regards
 Iain.

-- Dmitry Olshansky
Oct 29 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 29 October 2012 23:30, Dmitry Olshansky <dmitry.olsh gmail.com> wrote:
 10/29/2012 6:43 PM, Iain Buclaw =D0=BF=D0=B8=D1=88=D0=B5=D1=82:

 Speaking on behalf of Dejan, he expressed a wish to have such a type in
 D. (eg: such that assert(3.6 * 10 =3D=3D 36.0) - which may not always be
 true on all architectures).


 As maybe a new backend type is out of the question.  Perhaps we should
 create a new library type for the job - eg: _Decimal32, _Decimal64,
 _Decimal128.

 Thoughts?

I recall there was proposal for Phobos with both fixed decimal floating point types and arbitrary precision variants. And taking the role of good jinn: https://github.com/andersonpd/decimal/tree/master/decimal (seems very much alive and kicking)
 Regards
 Iain.

-- Dmitry Olshansky

Looks like just the ticket - however on a brief overview is still very incomplete. Regards, --=20 Iain Buclaw *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
Oct 29 2012
prev sibling next sibling parent "Rob T" <rob ucora.com> writes:
On Monday, 29 October 2012 at 18:43:36 UTC, Iain Buclaw wrote:
 Speaking on behalf of Dejan, he expressed a wish to have such a 
 type in D. (eg: such that assert(3.6 * 10 == 36.0) - which may 
 not always be true on all architectures).


 As maybe a new backend type is out of the question.  Perhaps we 
 should create a new library type for the job - eg: _Decimal32, 
 _Decimal64, _Decimal128.

 Thoughts?


 Regards
 Iain.

I would definitely want these. They are necessary for doing math on currency values. --rt
Oct 29 2012
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Oct 29, 2012 at 11:41:45PM +0100, Rob T wrote:
 On Monday, 29 October 2012 at 18:43:36 UTC, Iain Buclaw wrote:
Speaking on behalf of Dejan, he expressed a wish to have such a
type in D. (eg: such that assert(3.6 * 10 == 36.0) - which may not
always be true on all architectures).


As maybe a new backend type is out of the question.  Perhaps we
should create a new library type for the job - eg: _Decimal32,
_Decimal64, _Decimal128.

Thoughts?


Regards
Iain.

I would definitely want these. They are necessary for doing math on currency values.

I thought it was better to use fixed-point with currency? Or at least, so I've heard. T -- Mediocrity has been pushed to extremes.
Oct 29 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Oct 29, 2012, at 3:51 PM, "H. S. Teoh" <hsteoh quickfur.ath.cx> wrote:

 On Mon, Oct 29, 2012 at 11:41:45PM +0100, Rob T wrote:
 On Monday, 29 October 2012 at 18:43:36 UTC, Iain Buclaw wrote:
 Speaking on behalf of Dejan, he expressed a wish to have such a
 type in D. (eg: such that assert(3.6 * 10 =3D=3D 36.0) - which may not
 always be true on all architectures).
=20
=20
 As maybe a new backend type is out of the question.  Perhaps we
 should create a new library type for the job - eg: _Decimal32,
 _Decimal64, _Decimal128.
=20
 Thoughts?
=20
=20
 Regards
 Iain.

I would definitely want these. They are necessary for doing math on currency values.

=20 I thought it was better to use fixed-point with currency?

With currency, as in most other instances, you usually want to do your round= ing once at the end of the calculation, or at least control exactly where an= d how the rounding is done. Rounding implicitly on each step means money ef= fectively vanishing into the ether, and people tend not to like that.=20=
Oct 29 2012
prev sibling next sibling parent "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Monday, 29 October 2012 at 22:49:16 UTC, H. S. Teoh wrote:
 I thought it was better to use fixed-point with currency? Or at 
 least, so I've heard.

Depends on the application. Years ago (10?) I made a little interest calculating C program, floating point and rounding gave me so many issues with 1-2 pennies off that I went with an int and just took the bottom 2 digits as pennies. Worked far better than fighting with the floating point issues. I do remember somewhere that the double could be used to accurately calculate money up to 18 digits, but I can't remember if there was a specific mode you had to tell the FPU.
Oct 29 2012
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Monday, 29 October 2012 at 22:49:16 UTC, H. S. Teoh wrote:
 [...]

 I thought it was better to use fixed-point with currency? Or at 
 least,
 so I've heard.


 T

In most countries, if you are a bank, doing otherwise would actually be *illegal* ...
Oct 29 2012