-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparisons and logical operators #29
Comments
Commit cschreib@9de3ed2 fixes the issue with This commit also fixes the right-to-left version of TinyExpr (which I had broken badly by mistake), and will correctly optimize stuff like |
This seems like a useful feature. Have you considered making a pull request? |
I have considered it, but as per the guidelines set in https://github.com/codeplea/tinyexpr/blob/master/CONTRIBUTING I have opened an issue first to gauge interest. I interpret the subsequent lack of reply as a hint that this is not a desired feature, but I'm happy to be wrong :) Also, my fork was based on another fork which included CMake build scripts. Adding these CMake scripts has been proposed here and rejected, so perhaps this is also a source of restraint. |
Sorry for the very late reply. I will likely merge this into a branch, spend some time tweaking and adding documentation, and then merge into master. I've already created a pull request here. Most of my hesitation was exactly as you expected. However, I've had people ask for both CMake support and logical operators recently, so I'm giving in. It only took a year. lol Nice work! |
Excellent news! Glad you found it to be an interesting addition. |
It would be nice to see this branch get merged into master now. Are there any plans? |
It's merged into the "logic" branch. It needs documentation before going to master. It also needs test cases added. I won't have time to work on it for a while. Feel free to help. |
If I'm not wrong, the Operator Precedence, in the logical branch is wrong. it should be: https://en.cppreference.com/w/c/language/operator_precedence |
I forked a C++ version of this library that includes logic and comparison operators in case that is useful to anyone: |
@codeplea - There seem to be a reasonable number of test cases, were there others you had in mind for rounding out what is already there? I'll work on adding some documentation. |
I've been using TinyExpr in my project and recently needed standard comparison operators (<, <=, >, >=) and boolean logic (!, &&, ||). I've just implemented this in my fork with this commit cschreib@c1b01d8 and this one cschreib@4cdeb91 (adding == and !=).
Booleans are simply
0.0
forfalse
and1.0
(or any non-zero value) fortrue
.I've written a test suite to make sure that the precedence with respect to other binary operators is correct, and it all seems to work fine. There is one little thing that I do not understand though, is that I was expecting
!!1
to produce1
, since--1
produces1
in TinyExpr. I do not understand what the difference is, but!!1
currently produces0
regardless of how many negation operators are used. It's no big deal for me, but it would be good if this worked to be consistent with the other unary operators.Let me know if you're interested in merging this feature, then I'll prepare a pull request.
The text was updated successfully, but these errors were encountered: