decimal icon indicating copy to clipboard operation
decimal copied to clipboard

Adds truncate, half-up rounding functions

Open jonathanstrong opened this issue 6 years ago • 7 comments

This is an alternative approach to allowing the user to specify a mode for a closure, namely, providing two specific and commonly used rounding functions in a quantize-like interface.

This commit adds

  • A binding to the decContextSetRounding function
  • A d128 method, with_rounding to initialize a Context with a given Rounding
  • ROUND_DOWN and HALF_UP thread local static Contexts initialized with those roundings
  • Two methods on d128, with_round_down and with_half_up that mimic with_context but use alternative roundings
  • Two methods, truncate and round that offer quantize like interfaces to these rounding settings.

jonathanstrong avatar Jan 30 '18 02:01 jonathanstrong

@jonathanstrong do you want to make this merge cleanly so that it can be merged? Then we can push a new version out.

alkis avatar Oct 01 '20 22:10 alkis

you're interested in the code that fixes the uninitialized usage, correct? happy to setup a clean pull request with those changes if so.

jonathanstrong avatar Oct 02 '20 00:10 jonathanstrong

I think we can merge the whole thing. I also sent you an invite to commit directly if that helps.

alkis avatar Oct 02 '20 14:10 alkis

Are you sure? There are quite a few unrelated differences, including a d64 type, some From and TryFrom conversion routines that should probably be reviewed, some dependencies brought in for benchmarking that are probably not a good idea to include in the upstream repo, etc.

jonathanstrong avatar Oct 02 '20 17:10 jonathanstrong

If you are happy to do it in smaller steps that would be even better.

alkis avatar Oct 02 '20 17:10 alkis

ok, I pushed a branch to upstream (i.e. this repo) as I am now a collaborator (thank you). it is only the MaybeUninit conversion changes: https://github.com/alkis/decimal/compare/uninit-fix. next week I can setup pull requests for the other things. if you have the bandwidth it'd be nice to get a second set of eyes on the changes (the stuff other than MaybeUninit). I am pretty good at rust but not experienced at C.

jonathanstrong avatar Oct 02 '20 18:10 jonathanstrong

Will do. Thanks @jonathanstrong!

alkis avatar Oct 02 '20 20:10 alkis