diff --git a/pd/src/x_arithmetic.c b/pd/src/x_arithmetic.c index 94f1a5be95f422f721099587f90399bc864c2157..6d4fad6fa6b8fb51ca17a70ad3f8c2216ced8162 100644 --- a/pd/src/x_arithmetic.c +++ b/pd/src/x_arithmetic.c @@ -11,42 +11,29 @@ inputs to int and their outputs back to float. */ #include "m_pd.h" #include <math.h> -#if !defined(HAVE_SINF) -#define sinf sin -#endif - -#if !defined(HAVE_COSF) -#define cosf cos -#endif - -#if !defined(HAVE_ATANF) -#define atanf atan -#endif - -#if !defined(HAVE_ATAN2F) -#define atan2f atan2 -#endif - -#if !defined(HAVE_SQRTF) -#define sqrtf sqrt -#endif - -#if !defined(HAVE_LOGF) -#define logf log -#endif - -#if !defined(HAVE_EXPF) -#define expf exp -#endif - -#if !defined(HAVE_FABSF) -#define fabsf fabs -#endif - -#if !defined(HAVE_POWF) -#define powf pow +#if PD_FLOATSIZE == 32 +#define POW powf +#define SIN sinf +#define COS cosf +#define ATAN atanf +#define ATAN2 atan2f +#define SQRT sqrtf +#define LOG logf +#define EXP expf +#define FABS fabsf +#define MAXLOG 87.3365 +#elif PD_FLOATSIZE == 64 +#define POW pow +#define SIN sin +#define COS cos +#define ATAN atan +#define ATAN2 atan2 +#define SQRT sqrt +#define LOG log +#define EXP exp +#define FABS fabs +#define MAXLOG 87.3365 #endif - typedef struct _binop { t_object x_obj; @@ -158,10 +145,10 @@ static void binop1_pow_bang(t_binop *x) { if (x->x_f1 >= 0) outlet_float(x->x_obj.ob_outlet, - powf(x->x_f1, x->x_f2)); + POW(x->x_f1, x->x_f2)); else if (x->x_f2 <= -1 || x->x_f2 >= 1 || x->x_f2 == 0) outlet_float(x->x_obj.ob_outlet, - powf(x->x_f1, x->x_f2)); + POW(x->x_f1, x->x_f2)); else { pd_error(x, "pow: calculation resulted in a NaN"); @@ -174,10 +161,10 @@ static void binop1_pow_float(t_binop *x, t_float f) x->x_f1 = f; if (x->x_f1 >= 0) outlet_float(x->x_obj.ob_outlet, - powf(x->x_f1, x->x_f2)); + POW(x->x_f1, x->x_f2)); else if (x->x_f2 <= -1 || x->x_f2 >= 1 || x->x_f2 == 0) outlet_float(x->x_obj.ob_outlet, - powf(x->x_f1, x->x_f2)); + POW(x->x_f1, x->x_f2)); else { pd_error(x, "pow: calculation resulted in a NaN"); outlet_float(x->x_obj.ob_outlet, 0); @@ -564,7 +551,7 @@ static void *sin_new(void) static void sin_float(t_object *x, t_float f) { - outlet_float(x->ob_outlet, sinf(f)); + outlet_float(x->ob_outlet, SIN(f)); } static t_class *cos_class; /* ----------- cos --------------- */ @@ -578,7 +565,7 @@ static void *cos_new(void) static void cos_float(t_object *x, t_float f) { - outlet_float(x->ob_outlet, cosf(f)); + outlet_float(x->ob_outlet, COS(f)); } static t_class *tan_class; /* ----------- tan --------------- */ @@ -592,8 +579,8 @@ static void *tan_new(void) static void tan_float(t_object *x, t_float f) { - t_float c = cosf(f); - t_float t = (c == 0 ? 0 : sinf(f)/c); + t_float c = COS(f); + t_float t = (c == 0 ? 0 : SIN(f)/c); outlet_float(x->ob_outlet, t); } @@ -608,7 +595,7 @@ static void *atan_new(void) static void atan_float(t_object *x, t_float f) { - outlet_float(x->ob_outlet, atanf(f)); + outlet_float(x->ob_outlet, ATAN(f)); } static t_class *atan2_class; /* ----------- atan2 --------------- */ @@ -630,7 +617,7 @@ static void *atan2_new(void) static void atan2_float(t_atan2 *x, t_float f) { - t_float r = (f == 0 && x->x_f == 0 ? 0 : atan2f(f, x->x_f)); + t_float r = (f == 0 && x->x_f == 0 ? 0 : ATAN2(f, x->x_f)); outlet_float(x->x_ob.ob_outlet, r); } @@ -645,7 +632,7 @@ static void *sqrt_new(void) static void sqrt_float(t_object *x, t_float f) { - t_float r = (f > 0 ? sqrtf(f) : 0); + t_float r = (f > 0 ? SQRT(f) : 0); outlet_float(x->ob_outlet, r); } @@ -660,7 +647,7 @@ static void *log_new(void) static void log_float(t_object *x, t_float f) { - t_float r = (f > 0 ? logf(f) : -1000); + t_float r = (f > 0 ? LOG(f) : -1000); outlet_float(x->ob_outlet, r); } @@ -678,7 +665,7 @@ static void exp_float(t_object *x, t_float f) { t_float g; if (f > MAXLOG) f = MAXLOG; - g = expf(f); + g = EXP(f); outlet_float(x->ob_outlet, g); } @@ -693,7 +680,7 @@ static void *abs_new(void) static void abs_float(t_object *x, t_float f) { - outlet_float(x->ob_outlet, fabsf(f)); + outlet_float(x->ob_outlet, FABS(f)); } static t_class *wrap_class; /* ----------- wrap --------------- */