21#include "mdb_thread.h"
23static double x_offset = 0;
24static double x_scale = 1;
25static MDB_THREAD_LOCK argument_transform_lock = MDB_THREAD_LOCK_INITIALIZER;
27static void get_argument_transform(
double *offset,
double *scale) {
28 mdb_thread_lock(&argument_transform_lock);
31 mdb_thread_unlock(&argument_transform_lock);
43 mdb_thread_lock(&argument_transform_lock);
45 mdb_thread_unlock(&argument_transform_lock);
58 bomb(
"argument scale factor is zero", NULL);
59 mdb_thread_lock(&argument_transform_lock);
61 mdb_thread_unlock(&argument_transform_lock);
71 mdb_thread_lock(&argument_transform_lock);
73 mdb_thread_unlock(&argument_transform_lock);
84 mdb_thread_lock(&argument_transform_lock);
86 mdb_thread_unlock(&argument_transform_lock);
101 double offset, scale;
102 get_argument_transform(&offset, &scale);
103 x = (x - offset) / scale;
104 if (x > 1 || x < -1) {
109 return (cos(n * acos(x)));
123 double offset, scale;
124 get_argument_transform(&offset, &scale);
125 x = (x - offset) / scale;
126 if (x > 1 || x < -1) {
131 if (x != 1 && x != -1)
132 return (n * sin(n * acos(x)) / sqrt(1 - sqr(x)));
133 return (1.0 * n * n);
146 double offset, scale;
147 get_argument_transform(&offset, &scale);
148 x = (x - offset) / scale;
162 double offset, scale;
163 get_argument_transform(&offset, &scale);
164 x = (x - offset) / scale;
165 return (n *
ipow(x, n - 1));
181double eval_sum(
double (*fn)(
double x,
long ord),
double *coef, int32_t *order,
182 long n_coefs,
double x0) {
186 for (i = sum = 0; i < n_coefs; i++)
187 sum += (fn)(x0, order[i]) * coef[i];
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
double ipow(const double x, const int64_t p)
Compute x raised to the power p (x^p).
void set_argument_scale(double scale)
Set the scale factor applied to the input argument of basis functions.
double dtcheby(double x, long n)
Evaluate the derivative of the Chebyshev polynomial T_n(x).
void set_argument_offset(double offset)
Set the offset applied to the input argument of basis functions.
double ipower(double x, long n)
Evaluate a power function x^n.
double get_argument_offset()
Get the current argument offset applied before function evaluations.
double dipower(double x, long n)
Evaluate the derivative of x^n.
double tcheby(double x, long n)
Evaluate the Chebyshev polynomial of the first kind T_n(x).
double get_argument_scale()
Get the current argument scale factor used before function evaluations.
double eval_sum(double(*fn)(double x, long ord), double *coef, int32_t *order, long n_coefs, double x0)
Evaluate a sum of basis functions.