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