1use crate::*;
2use mech_core::*;
3use libm::{acosh, acoshf};
4use num_traits::*;
5#[cfg(feature = "matrix")]
6use mech_core::matrix::Matrix;
7
8macro_rules! acosh_op {
10 ($arg:expr, $out:expr) => {
11 unsafe { (*$out) = acosh((*$arg)); }
12 };
13}
14
15macro_rules! acosh_vec_op {
16 ($arg:expr, $out:expr) => {
17 unsafe {
18 for i in 0..(*$arg).len() {
19 ((&mut (*$out))[i]) = acosh(((&(*$arg))[i]));
20 }
21 }
22 };
23}
24
25macro_rules! acoshf_op {
26 ($arg:expr, $out:expr) => {
27 unsafe { (*$out) = acoshf((*$arg)); }
28 };
29}
30
31macro_rules! acoshf_vec_op {
32 ($arg:expr, $out:expr) => {
33 unsafe {
34 for i in 0..(*$arg).len() {
35 ((&mut (*$out))[i]) = acoshf(((&(*$arg))[i]));
36 }
37 }
38 };
39}
40
41#[cfg(feature = "f32")]
42impl_math_unop!(MathAcosh, f32, acoshf, FeatureFlag::Custom(hash_str("math/acosh")));
43#[cfg(feature = "f64")]
44impl_math_unop!(MathAcosh, f64, acosh, FeatureFlag::Custom(hash_str("math/acosh")));
45
46fn impl_acosh_fxn(lhs_value: Value) -> MResult<Box<dyn MechFunction>> {
47 impl_urnop_match_arms2!(
48 MathAcosh,
49 (lhs_value),
50 F32 => MatrixF32, F32, f32::zero(), "f32";
51 F64 => MatrixF64, F64, f64::zero(), "f64";
52 )
53}
54
55pub struct MathAcosh {}
56
57impl NativeFunctionCompiler for MathAcosh {
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_acosh_fxn(input.clone()) {
67 Ok(fxn) => Ok(fxn),
68 Err(_) => match input {
69 Value::MutableReference(input) => impl_acosh_fxn(input.borrow().clone()),
70 _ => Err(MechError2::new(
71 UnhandledFunctionArgumentKind1 { arg: input.kind(), fxn_name: "math/acosh".to_string() },
72 None
73 ).with_compiler_loc()
74 ),
75 },
76 }
77 }
78}
79
80register_descriptor! {
81 FunctionCompilerDescriptor {
82 name: "math/acosh",
83 ptr: &MathAcosh{},
84 }
85}