Strange math evaluator bug. print([y,mode,15]) => [?,?, not 15]
Reptorian1125 opened this issue · 5 comments
This doesn't look like I can reproduce in other code, but do you find this strange?
[gmic]./ Start G'MIC interpreter (v.3.4.3).
[gmic_math_parser] [y,mode,15] = (uninitialized) (mem[68]: vector3)
[gmic_math_parser] [y,mode,15] = [ 0,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 1,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 2,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 3,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 4,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 5,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 6,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 7,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 8,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 9,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 10,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 11,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 12,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 13,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 14,1,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 15,0,15 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 16,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 17,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 18,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 19,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 20,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 21,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 22,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 23,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 24,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 25,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 26,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 27,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 28,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 29,1,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 30,0,1 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 31,1,2 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 32,1,2 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 33,1,2 ] (size: 3)
[gmic_math_parser] [y,mode,15] = [ 34,1,2 ] (size: 3)
[gmic]./ Start interactive display of 2D image [0]
That's not supposed to happen, is it? Look at the 15, and see the 1 and 2.
Could you please copy/paste a minimal G'MIC command that reproduces this bug ?
This works for me:
foo :
1,35,1,1,"const mode = 1; print([y,mode,15])"
Could you please copy/paste a minimal G'MIC command that reproduces this bug ?
Without knowing what happened, I will post the one without a parameter. You can see 15 becomes 1 for some reason. I will see if I can find the minimum example.
Well, this is the current minimal example I have:
foo:
35,1,1,3,"begin(
v=vectors();
const dec_max_sum=15-1;
const end_pos=s-1;
scanline_pos=end_pos;
mode=1;
started=0;
limit=15;
old_mode=1;
);
started?(
mode?(
if((++v[end_pos])==limit,
mode=0;
);
):(
v[scanline_pos]==15?(
copy(v[scanline_pos--],0,s-scanline_pos,1,1);
v[scanline_pos]=1;
mode=1;
limit=dec_max_sum;
):(
mode=1;
temp_sum=0;
for( p = scanline_pos, p < s, ++p,
temp_sum+=v[p];
if(temp_sum==limit,
mode=0;
break();
);
);
mode?(
limit=15-temp_sum;
):(
copy(v[p],0,s-p,1,1);
++v[scanline_pos];
);
);
);
);
print([y,mode,15]);
started=1;
v;
"
EDIT: Removing some of the code makes the bug go away. So, I cannot find the minimum example other than this which triggers the bug.
Well, I'd suggest that you check your copy()
functions.
Using copy
is prone to error as you can scramble the values in the internal math parser memory.
Just for instance:
eval "
a = 0;
b = pi;
copy(a,[1,2]);
print(b);
"
will print b = 2
....
Thanks, looking a closer look at it resolved it. Now off to finish a new combinatorics command.