-
Notifications
You must be signed in to change notification settings - Fork 183
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
Unsigned Decimal? #664
Comments
This is an interesting use case. It's certainly possible - effectively a Decimal is a 96 bit unsigned mantissa with the only thing denoting it as a negative is a single bit in the Can you perhaps share your use case a bit more? |
Sure. In the context of high freq trading, there are 2 ways to define a trade: // currently
struct Trade {
price: Decimal,
quantity: Decimal, // sign indicates the direction, negative means sell
} // ideally, UDecimal is unsigned
enum Side {
Buy,
Sell,
}
struct Trade {
price: UDecimal,
quantity: UDecimal,
Side: Side,
} The ideal definition rules out the undefined behavior of negative price, and prevents confusion of whether So my question is can we add |
Adding The new type pattern in your application logic may be a little easier right now, only because you'd only need to (re)implement the traits/functions that you care about. If implementing directly into the library (which can be done if you have the appetite) it'd need to handle quite a lot of cases (e.g. enable the U variant, consider how to handle it with db access etc). I'm not familiar with that crate, however if it can provide transparent forwarding then it may be a quick and easy way to implement this, so long as you can intercept and assert non-negative values. |
Hey! Thank you for this crate, I just wanted to say that I came here exactly for this issue, and also for an Unsigned Strictly Positive Decimal. |
It's a bit cumbersome to validate the signs in every function where sign is meaningless.
Is it considered something useful to add to this crate? And what's the best practice for creating one from the user side?
The text was updated successfully, but these errors were encountered: