Thread overview
Why does D language do not support BigDecimal type?
Mar 11, 2019
BoQsc
Mar 12, 2019
Heromyth
Mar 12, 2019
Cym13
Mar 12, 2019
Boqsc
Mar 12, 2019
spir
Mar 12, 2019
jmh530
Mar 12, 2019
Kagamin
Mar 12, 2019
Seb
March 11, 2019
There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money

But that's only for money, what about math?
Why such fundamental as BigDecimal is still not included into the D language itself?
There is BigInt.

If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?


There is an article on that, but it is not that straight forward:
https://dlang.org/articles/d-floating-point.html

Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.
March 12, 2019
On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
> There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money
>
> But that's only for money, what about math?
> Why such fundamental as BigDecimal is still not included into the D language itself?
> There is BigInt.
>
> If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?
>
>
> There is an article on that, but it is not that straight forward:
> https://dlang.org/articles/d-floating-point.html
>
> Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.

We have being porting one from Java. See https://github.com/huntlabs/hunt/blob/master/source/hunt/math/BigDecimal.d.

It's so sad that many methods are still commented out.
March 12, 2019
On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
> There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money
>
> But that's only for money, what about math?
> Why such fundamental as BigDecimal is still not included into the D language itself?
> There is BigInt.
>
> If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?
>
>
> There is an article on that, but it is not that straight forward:
> https://dlang.org/articles/d-floating-point.html
>
> Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.

How much precision is enough in your use case? There's always a limit to how precise you need to be and how precise you can be, be it only because our memory is finite.

I've never had a use case for BigDecimal myself, so forgive my ignorance, but wouldn't you get the exact same result by using BigInt?

For example, if you need 20 decimals of precisions then any value times 10^20 will be a BigInt on which you can work, it's just a matter of displaying it correctly when outputing the result but it doesn't change the operations you have to perform.

Is there anything that can't be done with BigInt really?
March 12, 2019
On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
> If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?

It's taught in a computational mathematics course. In short, you estimate how errors accumulate over operations in your algorithm, e.g. for a sum operation `x+y` of values with errors you have (x±dx)+(y±dy)±r, for which you calculate the range of values: minimum is x-dx+y-dy-r, maximum is x+dx+y+dy+r, so the error is dx+dy+r, where r is a rounding error, this error gets carried over to subsequent calculations. Similar for other operations. See for example https://en.wikipedia.org/wiki/Round-off_error#Accumulation_of_roundoff_error
March 12, 2019
On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
> There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money
>
> But that's only for money, what about math?
> Why such fundamental as BigDecimal is still not included into the D language itself?
> There is BigInt.
>
> If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?
>
>
> There is an article on that, but it is not that straight forward:
> https://dlang.org/articles/d-floating-point.html
>
> Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.

I recommend that you learn floating point math as this will help you not only in programming in D, but in any other language.

In any case, if you need super-high precision, you might want to give decimal [1] a try.

[1] https://code.dlang.org/packages/decimal
March 12, 2019
On Tuesday, 12 March 2019 at 08:48:33 UTC, Cym13 wrote:
> On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
>> There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money
>>
>> But that's only for money, what about math?
>> Why such fundamental as BigDecimal is still not included into the D language itself?
>> There is BigInt.
>>
>> If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well?
>>
>>
>> There is an article on that, but it is not that straight forward:
>> https://dlang.org/articles/d-floating-point.html
>>
>> Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.
>
> How much precision is enough in your use case? There's always a limit to how precise you need to be and how precise you can be, be it only because our memory is finite.
>
> I've never had a use case for BigDecimal myself, so forgive my ignorance, but wouldn't you get the exact same result by using BigInt?
>
> For example, if you need 20 decimals of precisions then any value times 10^20 will be a BigInt on which you can work, it's just a matter of displaying it correctly when outputing the result but it doesn't change the operations you have to perform.
>
> Is there anything that can't be done with BigInt really?

Please attach quick working examples for every sentence you write or it's just a waste of time. People want to see the results and direct actions first before anything else, it's more efficient communication. We are in the subforum of Dlang learn, after all.

Do not write "For Example".

I'm interested in writing a simple game prototype and I imagine that I would like to include some item parts in decimal. (100.00) To keep everything simple I would like to make my code as clean and simple as possible. Floating points seems to require additional arithmetics - rounding and are inprecise when comparing. I do not want to deal with it every time. But if there is any standard simple documentation that I could include into my own game documentation to avoid confusion and make everything consisten, I would like to know.

For now it seems that the only way to make it all simple is to use some kind of library to handle decimals for me, as I can't find any concise references on how to correctly use and understand floating points.
March 12, 2019
On 12/03/2019 10:31, Boqsc via Digitalmars-d-learn wrote:
> Please attach quick working examples for every sentence you write or it's just a waste of time. People want to see the results and direct actions first before anything else, it's more efficient communication. We are in the subforum of Dlang learn, after all.
> 
> Do not write "For Example".

Then you may help people helping you by giving examples of your own use cases, first.

> I'm interested in writing a simple game prototype and I imagine that I would like to include some item parts in decimal. (100.00) To keep everything simple I would like to make my code as clean and simple as possible.

From this single example, you don't need "fractal" (decimal or binary) numbers at all, just plain ints. Look up "fixed point arithmetics" on wikipedia, the article is rather good. It's easy and clean in comparison, at least if you only need simple operations. (That's how, by the way, monetary/financial software is or at least used to be implemented.)

diniz
March 12, 2019
On Tuesday, 12 March 2019 at 09:31:53 UTC, Boqsc wrote:
> [snip]
>
> Please attach quick working examples for every sentence you write or it's just a waste of time. People want to see the results and direct actions first before anything else, it's more efficient communication. We are in the subforum of Dlang learn, after all.
> [snip]

Honestly, I think this is a rather high burden to place on people. They are spending their valuable time to think about your question and answer it with what they think is the best response.