GreycLab / gmic

GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
Other
69 stars 12 forks source link

Operator '=': Second argument (of type 'scalar') is not a constant, in expression #6

Closed Reptorian1125 closed 1 year ago

Reptorian1125 commented 1 year ago

Is there a reason why this problem shows up?

foo 15,10
foo:
eval "
 const max_number=int(abs($1));
 const base=int(abs($2));
 const log_base=log(base);

 logb(n)=log(n)/log_base;
 concat_consec_digits_count(n)=n>=base?(tn=floor(logb(n));n+(n+1)*tn+(base*(1-base^tn))/(base-1)):n;

 const number_of_digits_in_concatenated_number=concat_consec_digits_count(max_number);"

I'm pretty sure everything is a const.

EDIT: Oh, the additional ";". That's why.

dtschump commented 1 year ago

it seems to work for me.

Reptorian1125 commented 1 year ago

It's not working for me under Windows.

dtschump commented 1 year ago

OK, that's because your macro concat_consec_digits_count(n) returns a result that depends on variable tn, which is not defined as a const. Add const before tn = ... to makes it work:

eval "
 const max_number = int(abs($1));
 const base = int(abs($2));
 const log_base = log(base);

 logb(n) = log(n)/log_base;

 concat_consec_digits_count(n) = n>=base?(
   const tn = floor(logb(n));
   n + (n + 1)*tn + (base*(1 - base^tn))/(base - 1)
 ):n;

 const number_of_digits_in_concatenated_number = concat_consec_digits_count(max_number);"