mech_math/
acot.rs

1use crate::*;
2use mech_core::*;
3
4// Acot ------------------------------------------------------------------------
5
6use libm::{atan, atanf};
7macro_rules! acot_op {
8  ($arg:expr, $out:expr) => {
9    unsafe{(*$out).0 = atan(1.0 / (*$arg).0);}
10  };}
11
12macro_rules! acot_vec_op {
13  ($arg:expr, $out:expr) => {
14    unsafe {
15      for i in 0..(*$arg).len() {
16        ((*$out)[i]).0 = atan(1.0 / ((*$arg)[i]).0);
17      }}};}
18
19macro_rules! acotf_op {
20  ($arg:expr, $out:expr) => {
21    unsafe{(*$out).0 = atanf(1.0 / (*$arg).0);}
22  };}  
23
24macro_rules! acotf_vec_op {
25  ($arg:expr, $out:expr) => {
26    unsafe {
27      for i in 0..(*$arg).len() {
28        ((*$out)[i]).0 = atanf(1.0 / ((*$arg)[i]).0);
29      }}};}
30
31impl_math_urop!(MathAcot, F32, acotf);
32impl_math_urop!(MathAcot, F64, acot);
33
34fn impl_acot_fxn(lhs_value: Value) -> Result<Box<dyn MechFunction>, MechError> {
35  impl_urnop_match_arms2!(
36    MathAcot,
37    (lhs_value),
38    F32 => MatrixF32, F32, F32::zero(), "F32";
39    F64 => MatrixF64, F64, F64::zero(), "F64";
40  )
41}
42
43pub struct MathAcot {}
44
45impl NativeFunctionCompiler for MathAcot {
46  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
47    if arguments.len() != 1 {
48      return Err(MechError{file: file!().to_string(), tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::IncorrectNumberOfArguments});
49    }
50    let input = arguments[0].clone();
51    match impl_acot_fxn(input.clone()) {
52      Ok(fxn) => Ok(fxn),
53      Err(_) => {
54        match (input) {
55          (Value::MutableReference(input)) => {impl_acot_fxn(input.borrow().clone())}
56          x => Err(MechError{file: file!().to_string(),  tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
57        }
58      }
59    }
60  }
61}