-
Notifications
You must be signed in to change notification settings - Fork 149
Add BigDecimal #193
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
Add BigDecimal #193
Conversation
Div is currently broken, as it only returns the integer portion instead of a float as one might expect. Other traits are stubbed out to satisfy the Num trait.
It seems like a good start! I won't nitpick this too much yet, but I'm glad you're working on it. A big consideration is what you expose in the public interface. In particular, Do you really want the semantics of a negative In general, try to avoid clones if you can. For instance in |
Hey there, |
I'm still open to it. Perhaps if @iterion is too busy or no longer interested, someone else could run with it. |
There's the option for anyone to publish it as a separate crate/repo first and then discuss inclusion. That might help speed of development in the start. |
I'm still interested, but don't have time right now. So, if someone has time/motivation they should definitely take this over. |
I've extended @iterion's BigDecimal class and added more test cases, and I think things are looking pretty solid: https://github.com/akubera/num/blob/topic/big-decimal/bigdecimal/src/lib.rs. My first step was to merge the current master with @iterion branch, so the diffs might look like more complex than it is. Here's the simplified diff-to-iterion-fork. I added an arbitrary precision limit to 100. This is something that should be discussed; should there be a 'precision context' object that may be set during runtime or a compile-time constant which simplifies use? You can see the effect of this magic 100 number at this line of the division operator test. I tried to make pretty thorough tests (bottom of file). The parser ignores underscores in numbers, and understands exponential form (1e3). Please send me any questions/comments! I'm not sure what the procedure is to merge a fork of a fork. Let me know if I should create a pull request directly to the @iterion fork. If requested, I could rebase my work before my "master merge" to make the graph a little nicer, or do it as-is. |
I don't have time to review today, but I'd say open a new PR with a linear
history. Either rebased before master or fully rebased onto master is
fine, though I lean toward the latter. It's nice if you can keep the full
commit history with @iterion's commits before yours, but if that's too hard
than a simple attribution/acknowledgement in your own commit message should
suffice, I think.
|
Thanks @akubera! Closing this since we have a replacement in the works. |
This is a totally naive and somewhat broken implementation. I'm new to rust and BigDecimal implementation, but I thought I'd get this out there early for some guidance on ways I can improve my code before getting too deep.
#8 is the second oldest issue on this repo and I hadn't seen any code. So, I figured the work I've done would be useful to future prospective implementors, even if I don't manage to finish.
Add
,Sub
, andMul
all seem to work correctly (for my single test case each 😄)Div
is currently broken, as it only returns the integer portion insteadof a float as one might expect. Other traits are stubbed out to satisfy
the
Num
trait.