matheval / expression-evaluator-c-sharp

Matheval is a mathematical expressions evaluator library written in C#. Allows to evaluate mathematical, boolean, string and datetime expressions
https://matheval.org/
MIT License
107 stars 29 forks source link

OR operator return always true #2

Open drimondi1 opened 2 years ago

drimondi1 commented 2 years ago

Hi @matheval
really thanks for you library works very well. I'm facing an issue with "OR" operator that returns always "true". please find below an online example https://dotnetfiddle.net/P9zFsG

can you help me ? Thanks in advance Davide

nielll commented 2 years ago

Hi @drimondi1 and @matheval

Until it is fixed you can also generate OR with NOT and AND. This workaround works.

// according to De Morgan's Law
A OR B = NOT ( NOT A AND NOT B ) 
matheval commented 2 years ago

@drimondi1 @nielll I may have free time on June or July and i will fix it. thank for using this.

tevarg commented 1 year ago

Just change the following line "if ((item is Boolean) || (Boolean)item)" to "if ((item is Boolean) && (Boolean)item)" in the following block:

    private Boolean LogicalOr(Dictionary<string, Object> args)
    {
        foreach (Object item in args.Values)
        {
            if ((item is Boolean) && (Boolean)item)
            {
                return true;
            }
        }
        return false;
    }