New useful features in math parser, planned in 2.9.8

New changes also planed in the math parser, for 2.9.8 :

  • New functions deg2rad() and rad2deg() converts angles specified in degrees to radians (and vice versa).
  • New postfix operator ° (UTF8-symbol for degrees) can be added to convert an angle in degrees to radians, as in the expression cos(45°) (eq. to cos(deg2rad(45)) or cos(45*pi/180) ).
  • Functions rot() and ellipse() now consider that their angle arguments are specified in radians instead of degrees (just like the other trigonometric functions in the math parser).

All this avoids to add a bunch of new functions as cosd(), sind(), ... (as done in R, Matlab, etc.)
This may requires some changes in your scripts anyway (even if I tried to make the change myself).

1 Like

Could you allow something like 45d or 45deg? It may be unconventional but the key combination for ° isn’t easy to remember. It is ALT+0176 on Windows.

Ahhh, Windows and UTF-8… UTF-8 seems to be a too much advanced technology for Windows. :nauseated_face:

I’ll try to find something else then, maybe 45*, that is the closest I can think of.

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.