// Rascal, the Advanced Scientific CALculator
// Copyright (C) 2001, 2002, Sebastian Ritterbusch (Rascal@Ritterbusch.de)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more detauls.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
string polyVariable="";
valuepoly namedvaluepoly(string a)
{
polyVariable=a;
return valuepoly(0,1);
}
string output(const valuepoly & a)
{
string out("");
int i;
if(polyVariable=="")
polyVariable="X";
for(i=a.N-1;i>=0;i--)
{
if(a.a[i]!=0)
{
if( !(a.a[i]<0) && i!=a.N-1)
out+="+";
if(a.a[i]!=1 || i==0)
{
value o(output(a.a[i]));
if(o.isSTRING())
out+=o.asSTRING();
else
out+="Error";
if(i>0)
out+="*";
}
if(i==1)
out+=polyVariable;
else if(i>1)
out+=polyVariable+"^"+output(i);
}
}
return out;
}
syntax highlighted by Code2HTML, v. 0.9.1