mech_math/
sinh.rs

1use crate::*;
2use mech_core::*;
3use libm::{sinh, sinhf};
4
5// Sinh ------------------------------------------------------------------------
6macro_rules! sinh_op {
7  ($arg:expr, $out:expr) => {
8    unsafe { (*$out).0 = sinh((*$arg).0); }
9  };
10}
11
12macro_rules! sinh_vec_op {
13  ($arg:expr, $out:expr) => {
14    unsafe {
15      for i in 0..(*$arg).len() {
16        ((*$out)[i]).0 = sinh(((*$arg)[i]).0);
17      }}};}
18
19macro_rules! sinhf_op {
20  ($arg:expr, $out:expr) => {
21    unsafe { (*$out).0 = sinhf((*$arg).0); }
22  };
23}
24
25macro_rules! sinhf_vec_op {
26  ($arg:expr, $out:expr) => {
27    unsafe {
28      for i in 0..(*$arg).len() {
29        ((*$out)[i]).0 = sinhf(((*$arg)[i]).0);
30      }
31    }
32  };
33}
34
35impl_math_urop!(MathSinh, F32, sinhf);
36impl_math_urop!(MathSinh, F64, sinh);
37
38fn impl_sinh_fxn(lhs_value: Value) -> Result<Box<dyn MechFunction>, MechError> {
39  impl_urnop_match_arms2!(
40    MathSinh,
41    (lhs_value),
42    F32 => MatrixF32, F32, F32::zero(), "F32";
43    F64 => MatrixF64, F64, F64::zero(), "F64";
44  )
45}
46
47pub struct MathSinh {}
48
49impl NativeFunctionCompiler for MathSinh {
50  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
51    if arguments.len() != 1 {
52      return Err(MechError {
53        file: file!().to_string(),
54        tokens: vec![],
55        msg: "".to_string(),
56        id: line!(),
57        kind: MechErrorKind::IncorrectNumberOfArguments,
58      });
59    }
60    let input = arguments[0].clone();
61    match impl_sinh_fxn(input.clone()) {
62      Ok(fxn) => Ok(fxn),
63      Err(_) => match input {
64        Value::MutableReference(input) => impl_sinh_fxn(input.borrow().clone()),
65        _ => Err(MechError {
66          file: file!().to_string(),
67          tokens: vec![],
68          msg: "".to_string(),
69          id: line!(),
70          kind: MechErrorKind::UnhandledFunctionArgumentKind,
71        }),
72      },
73    }
74  }
75}