Problem when using pow on an integer


I found a little glitch with the native function pow when it is used on an integer. I derive my equations to be solved with Mathematica because they are rather lenghty and it converts the formal expressions into code, in particular by using the pow function for powers. Then I copy/paste the equations in my code, using the varf formulation. It is not the first time I did this procedure but yesterday my code was not able to compile and the error was

Assertion fail : ((iscmplx) == IsComplexType::value)

on the line where I “evaluate” the varf expression. I finally figured out what was the problem and I think it is something that have to be fixed. Indeed, it comes from the power of an integer M, pow(M,2), if I replace it by M^2 it works but with pow it seems like FreeFem treat it like a complex number for some mysterious reason. And of course, if I change the definition of M by declaring it as a real, real M=2, the pow function works. Therefore it is really a little issue of the function pow when it is acting on a real.

Does anyone have the same problem ? I use the last version of FF++ on Ubuntu 20.

Please provide a minimal working example that reproduces this behavior.

Of course, on my computer the following minimal code do not compile :

int M = 2;
real n = pow(M,2);

But this work :

int M = 2;
real n = M^2;

This is expected. Here are the various ways to use pow (which is not designed for integers but rather floating-point scalars, as in C++ pow - C++ Reference):

int M = 2;
real n = pow(M,2.0);

M = 2;
n = pow(real(M),2);

M = 2;
n = M^2;

Thank you, I was used to C++ before using FF++ but I hadn’t encountered this subtlety before.

The problem is due to automatique cast
a integer can be casted in real or in complex value,

And I make a mistake by default it is in complex

cout << pow(2,2) << endl;

print : (4,0)

I will correct in the minute in develop (thanks the the help) F. Hecht.
see remove load MUMPS_seq in examples/tutorial/tgv-test.edp · FreeFem/FreeFem-sources@bd079ab · GitHub