Skip to content
Snippets Groups Projects
Commit 95d82d33 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

improved pow logic to accept negative numbers and deal correctly with NaN situations

parent e4b821a2
No related branches found
No related tags found
No related merge requests found
...@@ -156,15 +156,31 @@ static void *binop1_pow_new(t_floatarg f) ...@@ -156,15 +156,31 @@ static void *binop1_pow_new(t_floatarg f)
static void binop1_pow_bang(t_binop *x) static void binop1_pow_bang(t_binop *x)
{ {
outlet_float(x->x_obj.ob_outlet, if (x->x_f1 >= 0)
(x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0)); outlet_float(x->x_obj.ob_outlet,
powf(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));
else {
pd_error(x, "pow: calculation resulted in NaN");
outlet_float(x->x_obj.ob_outlet, 0);
}
} }
static void binop1_pow_float(t_binop *x, t_float f) static void binop1_pow_float(t_binop *x, t_float f)
{ {
x->x_f1 = f; x->x_f1 = f;
outlet_float(x->x_obj.ob_outlet, if (x->x_f1 >= 0)
(x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0)); outlet_float(x->x_obj.ob_outlet,
powf(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));
else {
pd_error(x, "pow: calculation resulted in NaN");
outlet_float(x->x_obj.ob_outlet, 0);
}
} }
/* ------------------------ max -------------------------------- */ /* ------------------------ max -------------------------------- */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment