dadhi / FastExpressionCompiler

Fast Compiler for C# Expression Trees and the lightweight LightExpression alternative. Diagnostic and code generation tools for the expressions.
MIT License
1.16k stars 82 forks source link

Wrong output when comparing NaN value #418

Closed hyh closed 2 weeks ago

hyh commented 3 months ago

GreaterThanOrEqual/LessThanOrEqual generates wrong result when parameter is NaN.

        var p1 = Expression.Parameter(typeof(double));
        var e1 = Expression.GreaterThanOrEqual(p1, Expression.Constant(0.0));
        var e2 = Expression.Lambda<Func<double, bool>>(e1, p1);
        var cmp1 = e2.Compile();
        var cmp2 = e2.CompileFast();
        Console.WriteLine("{0} {1} {2}", double.NaN >= 0.0, cmp1(double.NaN), cmp2(double.NaN));

resulting:

False False True
dadhi commented 3 months ago

Did not see the NaN is coming :) Thanks, will check.

dadhi commented 2 weeks ago

On it.