MiSawa / xq

Pure rust implementation of jq
MIT License
333 stars 18 forks source link

Implement trigonometric and hyperbolic functions #84

Closed itchyny closed 2 years ago

itchyny commented 2 years ago

This PR adds trigonometric functions, inverse trigonometric functions, hyperbolic functions, and inverse hyperbolic functions. In tests, I used floor to round the results because we cannot get some floating-point number exactly (for example, we can't test 2 | sin equals to 0.9092974268256817 due to deserializing error). Also note that current testing macro does not allow to test nan value (and maybe infinite as well).

itchyny commented 2 years ago

Maybe we can use macro here?

macro_rules! pub_math_fn {
    ($($name: ident),*) => {
        $(
            pub(crate) fn $name(v: Number) -> Result<Number> {
                Ok(v.$name())
            }
        )*
    };
}

pub_math_fn!(floor, sqrt, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh);
MiSawa commented 2 years ago

Niiice, thank you!