Rounding without knowing what you do will never result in a correct value...
The real problem with this expression is that the argument of the sqrt function is negative. If you remember your math lessons, it is not possible to calculate the sqrt of a negative value. Mathematicians therefore introduced the so-called "imaginary numbers" to be able to do this: the sqrt(-1) is i ("imaginary unit"), and if you look at the Wolfram Alpha result you'll see the result is -5.03 i.
FPExpressionParser works only on real number, imaginary numbers are not supported.
But if you look at the expression before the sqrt you'll see that this part is zero, and the expression reduces to something like sqrt(-a)/b. Knowing that sqrt(-1) = i you still can calculate the value if you negate the expression under the sqrt: sqrt(-a) / b = sqrt(a) / b i.
program Project1;
uses
fpexprpars;
var
parser: TFPExpressionParser;
res: TFPExpressionResult;
begin
parser := TFPExpressionParser.Create(nil);
try
parser.BuiltIns := [bcMath];
Parser.Expression := '(-(2*(-1.04196816208394*0--1.04196816208394*0-0))+sqrt(-((2*(-1.04196816208394*0--1.04196816208394*0-0))^2-4*((-1.04196816208394^2+1))*(0^2-200^2+0^2-200+0^2))))/2*((-1.04196816208394^2+1))';
// added here || |
res := parser.Evaluate;
WriteLn(res.ResFloat); // -5.0299816639126842E+000
finally
parser.Free;
end;
end.
Taking the output and appending the complex unit i we get -5.0299816639126842 i, and Wolfram Alpha reports -5.029981663913... i - the same.