Closed Reptorian1125 closed 2 years ago
Here's the output so far:
c:\gmic-devel\gmic\src>gmic echo {concat(-50,20,30,.09)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ -502030.09000000003
[gmic]-0./ End G'MIC interpreter.
c:\gmic-devel\gmic\src>gmic echo {concat(5,20,30,.09)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 52030.089999999997
[gmic]-0./ End G'MIC interpreter.
c:\gmic-devel\gmic\src>gmic echo {concat(5,20,30,8)}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 520308
[gmic]-0./ End G'MIC interpreter.
For first one, since the last argument doesn't have a 0 at the beginning, a unnecessary 0 is added. But, I believe users can address that with ease.
Won't consider this for merging, because:
double
, and there is no way this concat()
function can work with any number of arguments.This functions seems rather useless by itself. Maybe you need it for a certain filter, but for general use, concatenate numbers is not a common operation, particularly when it is already possible to concatenate strings.
It's not common, yes, I agree. However, this is easier to work with when using math evaluation within G'MIC, which is exactly why I have created it in the first place. It also enables access to this function within filters that supports custom expression, which is another reason why I did this. This doesn't involve strings. One can do something like this in G'MIC with some time though with the setback of having to copy and paste this function.
Moreover, this won't work for large numbers. Numbers are stored in double, and there is no way this concat() function can work with any number of arguments.
Yes, large numbers won't work with it, I agree with that. It does work for any number of arguments from 1-n where the concatenated number is less than DBL_MAX.
That being said, at the end of the day, I respect your decision.
Also, there is a way to do this directly with macros :
foo :
eval "
nbd(x) = x>0?1+int(log10(x)):1;
concat(a,b) = (a*10^nbd(b) + b);
concat(a,b,c) = (concat(a,b)*10^nbd(c) + c);
concat(a,b,c,d) = (concat(a,b,c)*10^nbd(d) + d);
concat(a,b,c,d,e) = (concat(a,b,c,d)*10^nbd(e) + e);
print(concat(100,50,25,12,7));
"
I did not realize that functions with same name can have different numbers of arguments at all. Thanks.
I may have prematurely closed this.
After trying to make own macro generator within G'MIC. I realized that my concat() function in this pull request actually factors into conditions such as whether the first argument is a positive or a negative, and whether every arguments except the last one contains a decimal. It doesn't look very feasible to do this in G'MIC language. My solution solves most of the shortcomings with the G'MIC macro.
Maybe, I'll have another crack, but I find it very difficult to work without resorting to math-based approach. Maybe it's not worth reopening.
It doesn't seem discoverable by g'mic cli. I'm also not expecting mp_concat to work due to very little experience with C++. This is more of a starting point.