bigdecimal-rs
bigdecimal-rs copied to clipboard
Implement missing traits/functions
- [x] Rem
- [ ] UpperHex, LowerHex
- [x] abs
- [ ] asin/acos/atan
- [ ] asinh/acosh/atanh
- [ ] floor/ceil/round/trunc
- [ ] hypot
- [ ] ln/log2/log10
- [ ] not/or/and/xor
- [ ] sin/cos/san
- [ ] sinh/cosh/tanh
- [x] sqrt/cbrt
- [ ] trunc/fract
Once the Float
trait is implemented, I should be able to use this in the calculate
crate, and subsequently the calc builtin within the Ion shell.
One problem is that Float
requires Copy
, which is a bit of an issue as BigInt
cannot be Copy
'd.
EDIT: In addition I guess you could represent nan
and inf
manually, but I wonder if it would be better to represent it using an enum instead, i.e.:
enum BigDecimal {
NaN,
Inf,
...
}
abs was implemented in #34
rem is done - #38
Sqrt is highly demanded. Any progress on that? I probably could implement babylinian sqrt-ion, but i'm not sure if it's what is wanted.
Ok, sqrt()
is implemented in my develop branch. It returns Option<BigDecimal> to handle NaN case of √(negative number). Currently it still uses 100 digits of precision, but there's a new method with_prec()
that you can use to trim the digits down to a sane number.
Please check it out and let me know if I overlooked anything. The tests were verified by python's decimal sqrt method.
Great work!
Gonna try it tomorrow.
sqrt
/cbrt
implementation in 0d0e5ffa85ec482 should be "final". If someone can check my work or find a corner-case that returns incorrect value or causes an infinite loop, please let me know.
Any progress on this? This crate seems great, but I really need functions like these.
I think sqrt / cbrt should honor the precision set by with_prec(), see todo comment: https://github.com/akubera/bigdecimal-rs/blob/master/src/lib.rs#L411 It was a little confusing, since I did not find any mention of the 100 decimal digit limit in the docs.