#include "math_functions.h" #include #define MAKE_FUNCTION_1_ARG(name) \ static double mf_##name(const double *args) { \ return name(args[0]); \ } MAKE_FUNCTION_1_ARG(fabs) MAKE_FUNCTION_1_ARG(exp) MAKE_FUNCTION_1_ARG(log) MAKE_FUNCTION_1_ARG(log10) MAKE_FUNCTION_1_ARG(sin) MAKE_FUNCTION_1_ARG(cos) MAKE_FUNCTION_1_ARG(tan) MAKE_FUNCTION_1_ARG(asin) MAKE_FUNCTION_1_ARG(acos) MAKE_FUNCTION_1_ARG(atan) MAKE_FUNCTION_1_ARG(sinh) MAKE_FUNCTION_1_ARG(cosh) MAKE_FUNCTION_1_ARG(tanh) MAKE_FUNCTION_1_ARG(floor) MAKE_FUNCTION_1_ARG(ceil) static double mf_sgn(const double *args) { if (args[0] < 0.0) return -1.0; else if (args[0] > 0.0) return 1.0; else return 0.0; } static double mf_min(const double *args) { if (args[0] < args[1]) return args[0]; return args[1]; } static double mf_max(const double *args) { if (args[0] > args[1]) return args[0]; return args[1]; } static double mf_mod(const double *args) { return fmod(args[0], args[1]); } const struct math_function *fns_get(void) { static const struct math_function fns[] = { { "abs", 1, mf_fabs }, { "exp", 1, mf_exp }, { "ln", 1, mf_log }, { "log", 1, mf_log10 }, { "sin", 1, mf_sin }, { "cos", 1, mf_cos }, { "tan", 1, mf_tan }, { "asin", 1, mf_asin }, { "acos", 1, mf_acos }, { "atan", 1, mf_atan }, { "sinh", 1, mf_sinh }, { "cosh", 1, mf_cosh }, { "tanh", 1, mf_tanh }, { "min", 2, mf_min }, { "max", 2, mf_max }, { "mod", 2, mf_mod }, { "sgn", 1, mf_sgn }, { "floor", 1, mf_floor }, { "ceil", 1, mf_ceil }, { NULL } }; return fns; }