roots icon indicating copy to clipboard operation
roots copied to clipboard

Easier integration with rust_decimal OR fallible functions

Open blagovestb2c2 opened this issue 4 years ago • 2 comments

Hello, thanks for the library. It works amazing. Perhaps my only source of pain is the combination of the following two facts:

  1. there is no integration with rust_decimal::Decimal; so i am forced to use conversion functions e.g. Decimal::to_f64()
  2. however, conversion functions are fallible and return Option<f64>;

Besides the clutter, my concern is that i'm usually forced to unwrap() (risking panic) or unwrap_or(meaningless) when instead I'd rather have a version of the root finding functions which accept a fallible evaluation function where None signals "user error, stop iterating".

Do you think it'd be possible to support such a use case?

blagovestb2c2 avatar Jan 07 '22 12:01 blagovestb2c2

Is must be as simple as implementing trait FloatType for rust_decimal::Decimal, so that no conversion is needed at all. The only concern is the precision of math operations in that type.

i.e.

impl FloatType for rust_decimal::Decimal {
    #[inline]
    fn zero() -> Self {
        simple
    }
    #[inline]
    fn one_third() -> Self {
        Precision???
    }
    #[inline]
    fn one() -> Self {
        simple
    }
    #[inline]
    fn two_third_pi() -> Self {
        Precision???
    }
    #[inline]
    fn pi() -> Self {
        Precision???
    }
    fn sqrt(self) -> Self {
        Precision???
    }
    fn atan(self) -> Self {
        Precision???
    }
    fn acos(self) -> Self {
        Precision???
    }
    fn sin(self) -> Self {
        Precision???
    }
    fn cos(self) -> Self {
        Precision???
    }
    fn abs(self) -> Self {
        simple
    }
    fn powf(self, n: Self) -> Self {
        Precision???
    }
}

vorot avatar Jan 10 '22 13:01 vorot

Thumbs up on this. Would be really useful.

rollo-b2c2 avatar Feb 20 '24 12:02 rollo-b2c2