use crate::*;
use mech_core::*;
use num_traits::*;
#[cfg(feature = "matrix")]
use mech_core::matrix::Matrix;
use libm::{asin, asinf};
macro_rules! acsc_op {
($arg:expr, $out:expr) => {
unsafe{(*$out) = asin(1.0 / (*$arg));}
};}
macro_rules! acsc_vec_op {
($arg:expr, $out:expr) => {
unsafe {
for i in 0..(*$arg).len() {
((&mut (*$out))[i]) = asin(1.0 / ((&(*$arg))[i]));
}}};}
macro_rules! acscf_op {
($arg:expr, $out:expr) => {
unsafe{(*$out) = asinf(1.0 / (*$arg));}
};}
macro_rules! acscf_vec_op {
($arg:expr, $out:expr) => {
unsafe {
for i in 0..(*$arg).len() {
((&mut (*$out))[i]) = asinf(1.0 / ((&(*$arg))[i]));
}}};}
#[cfg(feature = "f32")]
impl_math_unop!(MathAcsc, f32, acscf, FeatureFlag::Custom(hash_str("math/acsc")));
#[cfg(feature = "f64")]
impl_math_unop!(MathAcsc, f64, acsc, FeatureFlag::Custom(hash_str("math/acsc")));
fn impl_acsc_fxn(lhs_value: Value) -> MResult<Box<dyn MechFunction>> {
impl_urnop_match_arms2!(
MathAcsc,
(lhs_value),
F32 => MatrixF32, F32, f32::zero(), "f32";
F64 => MatrixF64, F64, f64::zero(), "f64";
)
}
pub struct MathAcsc {}
impl NativeFunctionCompiler for MathAcsc {
fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
if arguments.len() != 1 {
return Err(MechError::new(IncorrectNumberOfArguments { expected: 1, found: arguments.len() }, None).with_compiler_loc());
}
let input = arguments[0].clone();
match impl_acsc_fxn(input.clone()) {
Ok(fxn) => Ok(fxn),
Err(_) => {
match (input) {
(Value::MutableReference(input)) => {impl_acsc_fxn(input.borrow().clone())}
x => Err(MechError::new(
UnhandledFunctionArgumentKind1 { arg: x.kind(), fxn_name: "math/acsc".to_string() },
None
).with_compiler_loc()
),
}
}
}
}
}
register_descriptor! {
FunctionCompilerDescriptor {
name: "math/acsc",
ptr: &MathAcsc{},
}
}