-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds truncate, half-up rounding functions #47
base: master
Are you sure you want to change the base?
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
decContextSetRounding
functionwith_rounding
to initialize aContext
with a givenRounding
ROUND_DOWN
andHALF_UP
thread local staticContext
s initializedwith those roundings
with_round_down
andwith_half_up
that mimicwith_context
but use alternative roundingstruncate
andround
that offerquantize
likeinterfaces to these rounding settings.