use dynamic::Type;
macro_rules! math_unary {
($name:ident, $method:ident) => {
extern "C" fn $name(value: f64) -> f64 {
f64::$method(value)
}
};
}
math_unary!(sin, sin);
math_unary!(cos, cos);
math_unary!(tan, tan);
math_unary!(asin, asin);
math_unary!(acos, acos);
math_unary!(atan, atan);
math_unary!(ln, ln);
math_unary!(log10, log10);
math_unary!(exp, exp);
math_unary!(sqrt, sqrt);
math_unary!(abs, abs);
math_unary!(floor, floor);
math_unary!(ceil, ceil);
math_unary!(round, round);
extern "C" fn atan2(y: f64, x: f64) -> f64 {
f64::atan2(y, x)
}
extern "C" fn pow(base: f64, exp: f64) -> f64 {
f64::powf(base, exp)
}
extern "C" fn max(a: f64, b: f64) -> f64 {
a.max(b)
}
extern "C" fn min(a: f64, b: f64) -> f64 {
a.min(b)
}
extern "C" fn pi() -> f64 {
std::f64::consts::PI
}
pub const MATH_NATIVE: &[(&str, &[Type], Type, *const u8)] = &[
("sin", &[Type::F64], Type::F64, sin as *const u8),
("cos", &[Type::F64], Type::F64, cos as *const u8),
("tan", &[Type::F64], Type::F64, tan as *const u8),
("asin", &[Type::F64], Type::F64, asin as *const u8),
("acos", &[Type::F64], Type::F64, acos as *const u8),
("atan", &[Type::F64], Type::F64, atan as *const u8),
("ln", &[Type::F64], Type::F64, ln as *const u8),
("log10", &[Type::F64], Type::F64, log10 as *const u8),
("exp", &[Type::F64], Type::F64, exp as *const u8),
("sqrt", &[Type::F64], Type::F64, sqrt as *const u8),
("abs", &[Type::F64], Type::F64, abs as *const u8),
("floor", &[Type::F64], Type::F64, floor as *const u8),
("ceil", &[Type::F64], Type::F64, ceil as *const u8),
("round", &[Type::F64], Type::F64, round as *const u8),
("atan2", &[Type::F64, Type::F64], Type::F64, atan2 as *const u8),
("pow", &[Type::F64, Type::F64], Type::F64, pow as *const u8),
("max", &[Type::F64, Type::F64], Type::F64, max as *const u8),
("min", &[Type::F64, Type::F64], Type::F64, min as *const u8),
("pi", &[], Type::F64, pi as *const u8),
];