Forums > Gen

gen changing names of parameters, screwing up my formula, causing errors.

May 2, 2014 | 1:00 am

i type this in to codebox:

round(num)
{
b = abs(num);
a = ceil(b – 1);
a = b – a;

if(a >= .5){
b = ceil(b);
}
else{
b = floor(b);
}

if(num < 0){
num = -b;
}
else{
num = b;
}

return num;
}

out1 = round(in1/in2)*in2;

i get this in "code" tab:

round(num) {
b = abs(b);
a = ceil(b – 1);
a_1 = b – a;
if(a_1 >= 0.5) {
b = ceil(b);
}
else {
b = floor(b);
}
if(b < 0) {
b = -b;
}
return b;
}

expr_2 = round(in1 / in2) * in2;
out1 = expr_2;

notice num is not even passed into the function.

whyyyyyy? :(
btw, <code tag is not working.

– Pasted Max Patch, click to expand. –
  • This topic was modified 2 months by  argitoth.
  • This topic was modified 2 months by  argitoth.

May 2, 2014 | 5:51 pm

it’s obviously gen not liking the fact im using the same variable multiple times or something. so there’s a formula that gen doesn’t mind:

round(num)
{
rounded=0.0;
pos = abs(num);
up = ceil(pos);
down = floor(pos);

checkup = up – pos;
checkdown = pos – down;

if(checkup <= checkdown){
rounded = up;
}
else{
rounded = down;
}

return sign(num)*rounded;
}

out1 = round(in1/in2)*in2;


May 6, 2014 | 1:42 pm

This is definitely a bug. Thanks for the example. Here’s a slight modification to the code that will compiler properly:

round(num) {
b = abs(num);
a = ceil(b – 1);
a = b-a;
if(a > 0.5) {
b = ceil(b);
}
else {
b = floor(b);
}

res = 0;
if(num < 0) {
res = -b;
}
else {
res = b;
}
return res;
}


May 12, 2014 | 3:02 pm

another problem

x=1;
y=2;
x,y=y,x;
out1 = x;
out2 = y;

turns into

expr_1 = 2;
expr_2 = 2;
out2 = expr_2;
out1 = expr_1;

notice how both outputs are now equal to 2.


Viewing 4 posts - 1 through 4 (of 4 total)