Adds truncate, half-up rounding functions#47
Adds truncate, half-up rounding functions#47jonathanstrong wants to merge 80 commits intoalkis:masterfrom
Conversation
merging some tiny upstream updates to try to eliminate a compiler warning.
- removed unsafe designation for `from_raw_bytes` because otherwise every use of the d128! plugin macro would need an unsafe. - macro can be used to create a `const A: d128 = d128!(1);` - decimal-macros has basic tests but they don't run when `cargo test` is called from the root project dir (e.g. ~/src/decimal). You need to navigate up to the decimal-macros dir to run them.
This 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 `Context`s 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.
This allows d128 to be used as a key-value pair via the slog logging macros, e.g. ``` let x = d128::zero(); info!(logger, "something important"; "x" => x); ```
…tion since it's fast now)
… d64 is GOOD TO GO
|
@jonathanstrong do you want to make this merge cleanly so that it can be merged? Then we can push a new version out. |
|
you're interested in the code that fixes the |
|
I think we can merge the whole thing. I also sent you an invite to commit directly if that helps. |
|
Are you sure? There are quite a few unrelated differences, including a |
|
If you are happy to do it in smaller steps that would be even better. |
|
ok, I pushed a branch to upstream (i.e. this repo) as I am now a collaborator (thank you). it is only the |
|
Will do. Thanks @jonathanstrong! |
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
decContextSetRoundingfunctionwith_roundingto initialize aContextwith a givenRoundingROUND_DOWNandHALF_UPthread local staticContexts initializedwith those roundings
with_round_downandwith_half_upthat mimicwith_contextbut use alternative roundingstruncateandroundthat offerquantizelikeinterfaces to these rounding settings.