New useful features in math parser, planned in 2.9.8

Is it completely different on your keyboards? I have it with <shift>^ . I think * has a completely different connotation!

Yes, I admit I’m not that happy about this possible alternative.

Imagine a formula e.g. sin(($alpha/3)°+pi/4) with * !

Yes, definitely ugly :slight_smile: Thanks Karsten.

Personally, I’m ok with the symbol addition. It is just a copy and paste into your gmic file, and you can always find it. I think deg2rad() and rad2deg() is more than enough with regards with degree indicator.

Also, is the ~ taken? Maybe ‘o’ as degree indicator?

What I think right now is that the postfix operator should keep the ° symbol. After all, that is the official degree symbol :slight_smile: Anything else will look weird.

Windows users that cannot use it can still use deg2rad() indeed (or *pi/180).
That’s more solutions than we actually need in fact!

A quick coding and testing here leads me to this.

rep_hex2img_test:
if narg($1)&&narg($2)
 hex2img $1
 hex2img $2
 hex_col_a={crop(#-2)}
 hex_col_b={crop(#-1)}
 rm[-2,-1]
fi

c=4
1,500,1,3,"begin(
 a=["$hex_col_a"];
 print(a);
 c=$c;
 print(c);
);
1;
"

For multiple numbers to work within a, one would have to use “” wrappers. Would it be possible to allow the math parser to read multi-number variable defined in the gmic interpreter?

Also, brings me a idea. is hex2vec a thing?

EDIT:

Got the hex2vec thing to work.

rep_hex2vec:

1,1,1,3,"begin(
  from_char(a)=a>=48&&a<=57?a-48:a-87;
  
  hex2vec(a)=(
   v=('$1');
   const vs=size(v);
   const m=int(vs/2);
   nv=vectorm(0);
   repeat(m,p,
    nv[p]=from_char(v[2*p])*16+from_char(v[2*p+1]);
   );
   nv;
  );
  
  hex_a=hex2vec($1);
 );
 hex_a[c];"

No, that’s not possible, because the $-operator in the math parser is intended to be a constant value. Vector-valued items or variables cannot be defined to be constant.
I’ve thought a long time about allowing const vectors to be defined in the math parser, but would introduce some disadvantages that do not compensate for the few advantages it provides.

Late to the party commenting here, but on the whole, a “like”. For tutorial writing purposes, I anticipate using deg2rad() and rad2deg() a good deal more than ° because the two formers clearly spell out their intent, and newcomers are already battling with understanding a script author’s intent. Neither requires special keyboard gyrations to get - for some platforms - a ‘special character’. In truth, I had to teach myself to love °. I get its convenience: I may write degrees everywhere and post-fixed ° makes them everywhere radians. That, and ensuring that every angular-related function now takes radians, is a consistency i enjoy. Nice to see this.

PS - thanks for the patches for my scripts. Much appreciated!

1 Like

Yep, I will be using the two macros (mackerels :yum:). About the degree symbol, I am curious how you input it on your system? I haven’t used Linux, etc., in a while…

Personally, I have this symbol directly on my keyboard (AZERTY / France), on the key with the right parenthesis.

Otherwise, it seems that with the Compose key, you can do COMPOSE + o + o.

That would be so useful here. But, it’s not. I wish the numberpad were replaced with some useful symbol like currency symbol and degree symbol. I never use the numberpad.

For future reference (haven’t read the answers yet), keyboard shortcuts - Compose key on Windows - Super User.

Desktop I use here is MATE with Gentoo Linux; standard US keyboard and en-US locale. No explicit ° key. Any application running on this desktop can accept SHIFT+CNTL+U+<code point> (0167 for degree symbol. More keys than Win 10). However, I mostly work in Emacs and have macros assigned for various non-keyboard characters.

Didn’t you remap the Windows key to the Compose key (Windows key is often useless) ?
This has changed my life for writing things on a computer.

The idea of compose gave me a try at remapping the window key. I had to download a software just for that in Windows.

Now, I can do this: 135°==deg2rad(135)==(135/180)*pi

Better than Altkey IMO.

Yep, alt codes aren’t easy to remember, which is why I brought this up. Which app did you install @Reptorian? I might try it when I have time.

WinCompose.

Compose + o + o = °
Compose + * + p = π

I don’t think this is possible, but I would like to see srand2(), and u2() and so forth. srand() would only affect u(), and srand2() would only affect u2().

This means setting different seeds with different random generator. A quick search reveals that srandn() where n is number from 2-9, and they don’t exist and neither does u2u9.

EDIT: I tested srand(n) inside math parser, and random values on different image. Seem to give me what I want. This’ll do.

Note that a random generator generates a new random number u_n based only on its previous value u_{n-1}.
What srand() function does is only set the value of u_{n-1} with a prescribed value given by the user.
So, if you want to manage several random generators in an expression, you just have to manage a vector of different ‘seeds’, like this:

# Manage 8 different random generators:
begin(
  seeds = vector8();
  fill(seeds,k,k*u);
);

uk(k) = (
  srand(seeds[k]);
  seeds[k] = u;
);

srandk(k,value) = (
  seeds[k] = value;
);
1 Like