bigdecimal-rs icon indicating copy to clipboard operation
bigdecimal-rs copied to clipboard

Implement missing traits/functions

Open jD91mZM2 opened this issue 6 years ago • 10 comments

  • [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

jD91mZM2 avatar Oct 03 '17 16:10 jD91mZM2

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.

mmstick avatar Oct 08 '17 15:10 mmstick

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,
  ...
}

hgoldstein avatar Jan 01 '18 20:01 hgoldstein

abs was implemented in #34

thargor avatar May 24 '18 11:05 thargor

rem is done - #38

aidanhs avatar May 27 '18 19:05 aidanhs

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.

Pzixel avatar Jul 14 '18 14:07 Pzixel

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.

akubera avatar Jul 16 '18 17:07 akubera

Great work!

Gonna try it tomorrow.

Pzixel avatar Jul 16 '18 18:07 Pzixel

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.

akubera avatar Jul 23 '18 17:07 akubera

Any progress on this? This crate seems great, but I really need functions like these.

PaddiM8 avatar Dec 09 '20 21:12 PaddiM8

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.

calvincramer avatar Jun 06 '21 22:06 calvincramer