Implicit conversion when comparing int to double fails

Nov 24, 2011 at 4:54 PM
Edited Nov 25, 2011 at 2:57 PM

I want to give flee any math or logical expression I encounter, and I don't want to have to worry about types (i had a similar implementation using the JScript library that worked fantastically, although it was slow and used floating points which was critically wrong for what I am doing).

Here is my relevant code (0.9.26 of flee):

 

context = new ExpressionContext();

context.Options.RealLiteralDataType = RealLiteralDataType.Decimal;

context.Options.IntegersAsDoubles = true;

context.Options.ParseCulture = System.Globalization.CultureInfo.InvariantCulture;

 

 

Using these options, when I try to evaluate 2 = 2.0, I get an exception:

 

context.CompileDynamic("(2 = 2.0)").Evaluate();

'context.CompileDynamic("(2 = 2.0)")' threw an exception of type 'Ciloci.Flee.ExpressionCompileException'

 

 

Various combinations of these options give me what I need. In short, i need to be able to execute the following types of expressions without having to worry about data types:

2.0 = 2 (works if either integersAsDoubles is off or i dont set the RealLiteralDataType to Decimal, not when i do both)

1111111111 + 2222222222 > 200000 (works when integersAsDoubles is on and RealLiteralDataType is set)

1.1 + 2.2 = 3.3 (works when RealLiteralDataType is set)

 

The options do not seem to play nice together (or, more likely, i dont fully understand the options).

Any way to do what I need?

Thanks,

Andrew

Nov 24, 2011 at 5:51 PM

It seems as though there are differences whether or not the Flee library is compiled in release or debug mode.

 

If I use the following options and compile in debug mode all of the above expressions evaluate with no exceptions:

context = new ExpressionContext();

context.Options.RealLiteralDataType = RealLiteralDataType.Decimal;

context.Options.ParseCulture = System.Globalization.CultureInfo.InvariantCulture;


If I compile the exact same thing in release mode, the following expression throws an overflow exception:
1111111111 + 2222222222 > 200000


Any reason for this difference?