It Doesn't Calculate A lot Of Numbers Right

Topics: Help
Dec 19, 2012 at 8:53 PM

So Maybe I'm just doing something wrong but I've tried a lot of larger number calculations and NCalc fails completely.  For example 

as a test


99999*99999 in NCalc it says it's 1409865409

The actual answer is 9999800001

The code I use is simple just something like this.  I get all kinds of crazy answers to formulas.  Does anyone know why?

 string equation = this.txtbx_equation.Text.Trim();
                 Expression exp = new Expression(equation, EvaluateOptions.None);
                 var answer = exp.Evaluate();
                 this.txtbx_answer.Text += answer;
  catch (Exception error)
                 this.txtbx_answer.Text += error;

Feb 6, 2013 at 7:24 PM
A little late to the party, but this is simply integer overflow. Int32's max value is 2,147,483,647.

Even a simple, non-NCalc program shows this:
Console.WriteLine(99999 * 99999); //1409865409
If you were to wrap it with a "checked" block, it would throw an OverflowException.

Not sure if NCalc can work with Int64s or not, but they would properly compute such large numbers (upwards of 9,223,372,036,854,775,807 at least)