[GiNaC-devel] Floating complex numbers

Stefan Weinzierl stefanw at thep.physik.uni-mainz.de
Wed Jan 8 21:05:11 CET 2014


Hi,

I'm currently fixing some bugs in inifcns_nstdsums.cpp and came across the 
following strange behaviour:
The GiNaC manual says "Complex numbers are automatically converted to real 
numbers if the imaginary part becomes zero".
However, this does not seem to be the case, as the following lines show:

   ex w1 = numeric(3)+I*numeric(2);
   ex w2 = numeric(2)+I*numeric(2);
   ex w3 = w1-w2;
   if ( (w3 == 1) && ex_to<numeric>(w3).is_real() ) std::cout << "o.k., equal to one and real" << std::endl;

   ex z1 = numeric(3)+I*numeric("2.1");
   ex z2 = numeric(2)+I*numeric("2.1");
   ex z3 = z1-z2;
   if ( (z3 == 1) && !ex_to<numeric>(z3).is_real() ) std::cout << "bug, equal to one, but not real" << std::endl;

The bug seems to be in CLN, as it does not downgrade z3 to an instance of 
cln::cl_R_ring.
Currently this leads to an error in the file inifcns_nstdsums.cpp. In this 
file a variable z is first checked to be equal to +1 or -1, and later on a 
comparison z>0 is carried out. The comparison leads to the exception
numeric::operator>(): complex inequality, since for the computer z 
is equal to +/- 1, but not real, similar to the last line in the 
code fragment above.

I can work around this bug in the file inifcns_nstdsums.cpp, but the clean 
solution would be to fix this in CLN. Any chances for that ?

  Best wishes,

     Stefan



More information about the GiNaC-devel mailing list