vb.netmathexpressionncalc

NCalc evaluation is wrong?


I am trying to evaluate the following expression:

7088.800/(((((((24.65995+24.43061+24.54517+24.65192)/4)-32.0)*5/9)+273.15)/288.15)^.5)

If you are asking yourself why I didn't use Sqrt() instead of ^0.5 it's because I'm doing some things with the string beforehand that require there be no letters.

I am using this simple code:

Expression.CacheEnabled = False
x = New Expression(xEquation)
y = New Expression(yEquation)
System.Diagnostics.Debug.Write(x.Error)
System.Diagnostics.Debug.Write(y.Error)
Return New PointF(x.Evaluate, y.Evaluate)

The answer I get is: 7088.800

The correct answer is:7336.46922305(according to google)

I am using .net 3.5 and ncalc 1.3.8

I suspect it doesn't like the amount of brackets there are but I can't find any mention of that being a problem anywhere...

Thanks!


Solution

  • I cannot get Ncalc or Ncalc-edge (v1.4.1) to use the exponentiation operator ^ and produce the correct result. E.g., "4 ^ 2" gives 6. It does not accept ** as an operator.

    A little bit of investigation shows that it uses ^ as the Xor operator, in the style of C#. C# does not have an exponentiation operator, so you will have to devise a way of parsing your actual input string and using Sqrt.

    There are currently were some requests on the Ncalc discussion forum regarding this, such as Override ^ operator (link now dead, and it's not even available on the Wayback Machine).