some improvements (hopefully) for the printing routines.

Chris Dams chrisd at sci.kun.nl
Tue Oct 22 16:04:21 CEST 2002


Hello everybody,

I have two problems with the current CLN-source printing functions.
Firstly, it prints integers as approximate real numbers. This is a problem
in exponentials. If I have something to the power two (i.e., the integer
two) it gets printed as something that is two only approximately. If the
base of this power is negative, I do not even get a real result out of
this, which certainly is what I would expect if I square a real number!
Generally, I would say that if one has, say, some polynomial that contains
only integer coeffiecients the user probably is interested in the integer
result after filling in numbers and not is some approximation of it.
Furthermore I don't think it hardly ever hurts, printing an integer as an
integer in CLN-source. For these reason I think it is bad to print in CLN
C++-source output integers as if they were real numbers.

Secondly, if you print a floating point number as CLN-source it does not
contain the precision. This way, it may be that a lot of precision is
wasted.

A patch is included that is supposed to solve these two things.

Greetings,
Chris Dams
-------------- next part --------------
*** numeric.cpp	Tue Oct 22 15:40:37 2002
--- numeric.cpp.modified	Tue Oct 22 15:44:28 2002
***************
*** 360,366 ****
  			c.s.precision(16);
  		else
  			c.s.precision(7);
! 		if (this->is_rational() && !this->is_integer()) {
  			if (compare(_num0) > 0) {
  				c.s << "(";
  				if (is_a<print_csrc_cl_N>(c))
--- 360,371 ----
  			c.s.precision(16);
  		else
  			c.s.precision(7);
! 		if (is_a<print_csrc_cl_N>(c) && this->is_integer()) {
! 			c.s << "cln::cl_I(\"";
! 			const cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
! 			print_real_number(c,r);
! 			c.s << "\")";
! 		} else if (this->is_rational() && !this->is_integer()) {
  			if (compare(_num0) > 0) {
  				c.s << "(";
  				if (is_a<print_csrc_cl_N>(c))
***************
*** 382,388 ****
  			c.s << ")";
  		} else {
  			if (is_a<print_csrc_cl_N>(c))
! 				c.s << "cln::cl_F(\"" << evalf() << "\")";
  			else
  				c.s << to_double();
  		}
--- 387,393 ----
  			c.s << ")";
  		} else {
  			if (is_a<print_csrc_cl_N>(c))
! 				c.s << "cln::cl_F(\"" << evalf() << "_" << Digits << "\")";
  			else
  				c.s << to_double();
  		}


More information about the GiNaC-devel mailing list