mech_math/trig/
asinh.rs

1use crate::*;
2use mech_core::*;
3use libm::{asinh, asinhf};
4use num_traits::*;
5#[cfg(feature = "matrix")]
6use mech_core::matrix::Matrix;
7
8// Asinh Macros
9macro_rules! asinh_op {
10  ($arg:expr, $out:expr) => {
11    unsafe { (*$out) = asinh((*$arg)); }
12  };
13}
14
15macro_rules! asinh_vec_op {
16  ($arg:expr, $out:expr) => {
17    unsafe {
18      for i in 0..(*$arg).len() {
19        ((&mut (*$out))[i]) = asinh(((&(*$arg))[i]));
20      }
21    }
22  };
23}
24
25macro_rules! asinhf_op {
26  ($arg:expr, $out:expr) => {
27    unsafe { (*$out) = asinhf((*$arg)); }
28  };
29}
30
31macro_rules! asinhf_vec_op {
32  ($arg:expr, $out:expr) => {
33    unsafe {
34      for i in 0..(*$arg).len() {
35        ((&mut (*$out))[i]) = asinhf(((&(*$arg))[i]));
36      }
37    }
38  };
39}
40
41#[cfg(feature = "f32")]
42impl_math_unop!(MathAsinh, f32, asinhf, FeatureFlag::Custom(hash_str("math/asinh")));
43#[cfg(feature = "f64")]
44impl_math_unop!(MathAsinh, f64, asinh, FeatureFlag::Custom(hash_str("math/asinh")));
45
46fn impl_asinh_fxn(lhs_value: Value) -> MResult<Box<dyn MechFunction>> {
47  impl_urnop_match_arms2!(
48    MathAsinh,
49    (lhs_value),
50    F32 => MatrixF32, F32, f32::zero(), "f32";
51    F64 => MatrixF64, F64, f64::zero(), "f64";
52  )
53}
54
55pub struct MathAsinh {}
56
57impl NativeFunctionCompiler for MathAsinh {
58  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
59    if arguments.len() != 1 {
60      return Err(MechError2::new(
61        IncorrectNumberOfArguments { expected: 1, found: arguments.len() },
62        None
63      ).with_compiler_loc());
64    }
65    let input = arguments[0].clone();
66    match impl_asinh_fxn(input.clone()) {
67      Ok(fxn) => Ok(fxn),
68      Err(_) => match input {
69        Value::MutableReference(input) => impl_asinh_fxn(input.borrow().clone()),
70        _ => Err(MechError2::new(
71            UnhandledFunctionArgumentKind1 { arg: input.kind(), fxn_name: "math/asinh".to_string() },
72            None
73          ).with_compiler_loc()
74        ),
75      },
76    }
77  }
78}
79
80register_descriptor! {
81  FunctionCompilerDescriptor {
82    name: "math/asinh",
83    ptr: &MathAsinh{},
84  }
85}