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