codeplea / tinyexpr

tiny recursive descent expression parser, compiler, and evaluation engine for math expressions
https://codeplea.com/tinyexpr
zlib License
1.61k stars 245 forks source link

Feature request : right and left shift operations #101

Open PantalaLabs opened 1 year ago

PantalaLabs commented 1 year ago

Thank you for your work! Great lib.

a >> 1 //right shift
b << 3 //left shift

operations

Blake-Madden commented 1 year ago

In case this helps, I've added support for these operators to the C++ version at:

https://github.com/Blake-Madden/tinyexpr-plusplus

PantalaLabs commented 1 year ago

Thank you a lot !

Blake-Madden commented 1 year ago

I also just added the functions BITLSHIFT() and BITRSHIFT(), which work like their counterparts in Excel. Note that if you pass a negative shift amount to BITLSHIFT(), then it calls BITRSHIFT() and vice-versa. A strange design, but that's what Excel does.

The << and >> operators have a very low operator precedence, but I emulate what C compilers do. I recommend wrapping those expressions in parentheses (as does the MSVC compiler).

PantalaLabs commented 1 year ago

Great ! Thank you!!