Jump to page: 1 2
Thread overview
Proposal for a standard Decimal type in alpha
Dec 22
Nathan S.
Jan 13
rumbu
December 21
A couple of months ago, Andrei noted that a donor asked for a precise decimal type for D specifically: https://forum.dlang.org/post/osnema$d5s$1@digitalmars.com. I've also heard this asked for many times, so I decided to start work on a library for eventual proposal to Phobos.

I just finished getting the type into an alpha version, and I wanted to solicit people's opinions on the API and if I'm heading in the right direction with this.

The dub page: https://code.dlang.org/packages/stdxdecimal

The docs: https://jackstouffer.github.io/stdxdecimal/

What you can do so far:

* Control behavior with a Hook type a-la std.experimental.checkedint
* Addition, subtraction, multiplication, division
* Construction from a strings and built-in number types

For the full list of planned features, see: https://github.com/JackStouffer/stdxdecimal

Please let me know what you think!
December 21
On Thursday, 21 December 2017 at 13:59:28 UTC, Jack Stouffer wrote:
> A couple of months ago, Andrei noted that a donor asked for a precise decimal type for D specifically: https://forum.dlang.org/post/osnema$d5s$1@digitalmars.com. I've also heard this asked for many times, so I decided to start work on a library for eventual proposal to Phobos.
>
> I just finished getting the type into an alpha version, and I wanted to solicit people's opinions on the API and if I'm heading in the right direction with this.
>
> The dub page: https://code.dlang.org/packages/stdxdecimal
>
> The docs: https://jackstouffer.github.io/stdxdecimal/
>
> What you can do so far:
>
> * Control behavior with a Hook type a-la std.experimental.checkedint
> * Addition, subtraction, multiplication, division
> * Construction from a strings and built-in number types
>
> For the full list of planned features, see: https://github.com/JackStouffer/stdxdecimal
>
> Please let me know what you think!

That are fantastic news. Thanks for working on this topic.
Is it possible to define a decimal type with a defined scale and precision?
From the examples and the documentation I am not sure whether it is possible.

Kind regards
Andre

December 22
On Thursday, 21 December 2017 at 23:08:22 UTC, Andre Pany wrote:
> That are fantastic news. Thanks for working on this topic.
> Is it possible to define a decimal type with a defined scale and precision?
> From the examples and the documentation I am not sure whether it is possible.

Yes, the Hook template parameter currently controls how many significant digits your decimal can have and will eventually be able to control the min and max allowed exponents as well. By default, it's set at 9 digits, but you can have as many as int.max - 1 since it auto uses BigInt under the hood. Once your decimal has more than the allowed number of digits, it's rounded according to the Hook prescribed rounding method, which is half up by default.
December 21
On 12/21/2017 5:59 AM, Jack Stouffer wrote:
> I just finished getting the type into an alpha version, and I wanted to solicit people's opinions on the API and if I'm heading in the right direction with this.

Thanks for doing this.

Your proposal would be enhanced a lot if it included a comparison with successful decimal packages in other languages, and why your solution is better!
December 22
On Thursday, 21 December 2017 at 13:59:28 UTC, Jack Stouffer wrote:
> I just finished getting the type into an alpha version, and I wanted to solicit people's opinions on the API and if I'm heading in the right direction with this.
>
> The dub page: https://code.dlang.org/packages/stdxdecimal
>
> The docs: https://jackstouffer.github.io/stdxdecimal/
>
> What you can do so far:
>
> * Control behavior with a Hook type a-la std.experimental.checkedint
> * Addition, subtraction, multiplication, division
> * Construction from a strings and built-in number types

I think it would be clearer if the precision, the rounding mode, and the error behavior were three separate parameters instead of a single Hook. Predefined settings named "Abort", "Throw", and "NoOp" would then be self-explanatory, and it wouldn't be necessary to entirely rewrite them if you wanted precision of 10 or 20 decimal digits instead of 9 or wanted to use a different rounding mode.
December 22
On Friday, 22 December 2017 at 08:32:03 UTC, Nathan S. wrote:
> I think it would be clearer if the precision, the rounding mode, and the error behavior were three separate parameters instead of a single Hook. Predefined settings named "Abort", "Throw", and "NoOp" would then be self-explanatory, and it wouldn't be necessary to entirely rewrite them if you wanted precision of 10 or 20 decimal digits instead of 9 or wanted to use a different rounding mode.

I agree. I worked with languages which have decimal type built into the language
  (DATA price TYPE p LENGTH 16 DECIMALS 2)
and having the possibility to set precision and scale directly without have to think about rounding options would be great.

Kind regards
Andre
January 05
On Thursday, 21 December 2017 at 13:59:28 UTC, Jack Stouffer wrote:
> ...

Updated version out:

* Added unary +,-,++,--
* Added casting to bool and floating point types
* Added static ctors for infinite and nan for floating point type compatibility
* Added abs, isNaN, isInfinite
* Added support to opBinary for mixing different precision levels on each side of the operation
January 05
On Fri, Jan 05, 2018 at 02:30:21PM +0000, Jack Stouffer via Digitalmars-d-announce wrote:
> On Thursday, 21 December 2017 at 13:59:28 UTC, Jack Stouffer wrote:
> > ...
> 
> Updated version out:
> 
> * Added unary +,-,++,--
> * Added casting to bool and floating point types
> * Added static ctors for infinite and nan for floating point type
> compatibility
> * Added abs, isNaN, isInfinite
> * Added support to opBinary for mixing different precision levels on each
> side of the operation

Very nice to see this taking shape.  What's the link to the code again?


T

-- 
Why do conspiracy theories always come from the same people??
January 05
On Friday, 5 January 2018 at 15:22:01 UTC, H. S. Teoh wrote:
> Very nice to see this taking shape.  What's the link to the code again?

https://github.com/JackStouffer/stdxdecimal
January 05
On Fri, Jan 05, 2018 at 03:38:45PM +0000, Jack Stouffer via Digitalmars-d-announce wrote:
> On Friday, 5 January 2018 at 15:22:01 UTC, H. S. Teoh wrote:
> > Very nice to see this taking shape.  What's the link to the code again?
> 
> https://github.com/JackStouffer/stdxdecimal

Thanks! Will take a look sometime. Might throw in a PR or two if I can.


T

-- 
Why did the mathematician reinvent the square wheel?  Because he wanted to drive smoothly over an inverted catenary road.
« First   ‹ Prev
1 2