[GiNaC-list] Re: Behaviour of evalf()

Alexei Sheplyakov varg at theor.jinr.ru
Wed Nov 14 18:28:05 CET 2007


On Wed, Nov 14, 2007 at 04:41:03PM +0100, Martin Sandve Alnæs wrote:

> Is it possible to make evalf() let integer constants stay integers?

evalf() turns exact numbers into inexact _by definition_. Keeping the
coefficient exact (for instance, integer) does not make sense anyway,
since they are multiplied by inexact number. If you still insist on it,
you could roll down your own evalf-alike function, e.g.

struct weird_evalf() : public map_function {
	ex operator()(const ex& e) {
		if (is_a<add>(e) || is_a<mul>(e))
			return e.map(*this);
		if (is_a<power>(e))
			return power(e.op(0).map(*this), e.op(1));
		if (is_a<numeric>(e))
			return e;
		else
			return e.evalf();
}

Best regards,
	Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20071114/25936197/attachment.pgp


More information about the GiNaC-list mailing list