Skip to content
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

Support for rust_decimal #49

Open
julama opened this issue Jan 4, 2021 · 2 comments
Open

Support for rust_decimal #49

julama opened this issue Jan 4, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@julama
Copy link

julama commented Jan 4, 2021

I want to deploy smartcore without using floating-point numbers. I'll try to change the crate math::num::RealNumber to support rust_decimal.

Do you think it's possible to have something like impl RealNumber for Decimal in the trait in RealNumber or would a completely new trait be necessary?

@VolodymyrOrlov
Copy link
Collaborator

The trait math::num::RealNumber is largely based on num-traits Float. This is the biggest obstacle in bringing rust_decimal:: Decimal into Smartcore so far, but it is possible if you are willing to refactor Smartcore's code a bit.

Take a look at https://github.com/smartcorelib/smartcore/blob/development/src/math/num.rs#L13. All you need to bring a new numerical type into Smartcore is to make sure this type implements num_traits::float::Float and a handful of additional functions defined in Smartcore.

One way you can do it is by working together with the author of rust_decimal, Paul Mason, to see whether is it possible to add implementation of num_traits::float::Float for rust_decimal::Decimal. Please note that you won't be able to keep implementation of num_traits::float::Float for rust_decimal::Decimal in Smartcore since Rust won't let you implement a trait on a type if both the trait and the type are not local to the crate.

Anther possibility is to refactor Smartcore's code and get rid of Float in the signature of math::num::RealNumber by moving all the methods we need from Float directly into the trait.

I would start from reaching out to Paul to discuss possibility of extending rust_decimal::Decimal with implementation of Float. If it is not possible I would consider refactoring Smartcore.

@VolodymyrOrlov VolodymyrOrlov added the enhancement New feature or request label Jan 4, 2021
@julama
Copy link
Author

julama commented Jan 5, 2021

Sounds like a good plan. Thanks for the explanations!

@morenol morenol added the help wanted Extra attention is needed label Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants