2 * poly - polynomial functions
4 * Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
6 * Primary author: Ernest Bowen
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.1 $
23 * @(#) $Id: poly.c,v 30.1 2007/03/16 11:09:46 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/RCS/poly.c,v $
26 * Under source code control: 1995/12/02 03:10:28
27 * File existed as early as: 1995
29 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
30 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
38 evp(LISTELEM
*cp
, LISTELEM
*x
, VALUE
*vres
)
46 mulvalue(vres
, &x
->e_value
, &tmp1
);
51 if (v
.v_type
== V_LIST
) {
52 if (evalpoly(v
.v_list
, x
->e_next
, &tmp1
)) {
54 addvalue(&tmp1
, vres
, &tmp2
);
65 addvalue(&v
, vres
, &tmp1
);
80 evalpoly(LIST
*clist
, LISTELEM
*x
, VALUE
*vres
)
90 if (v
.v_type
== V_LIST
)
91 return evalpoly(v
.v_list
, x
->e_next
, vres
);
95 return evp(clist
->l_last
, x
, vres
);
99 insertitems(LIST
*lp1
, LIST
*lp2
)
103 for (ep
= lp2
->l_first
; ep
; ep
= ep
->e_next
) {
104 if (ep
->e_value
.v_type
== V_LIST
)
105 insertitems(lp1
, ep
->e_value
.v_list
);
107 insertlistlast(lp1
, &ep
->e_value
);
113 countlistitems(LIST
*lp
)
118 for (ep
= lp
->l_first
; ep
; ep
= ep
->e_next
) {
119 if (ep
->e_value
.v_type
== V_LIST
)
120 n
+= countlistitems(ep
->e_value
.v_list
);
129 addlistitems(LIST
*lp
, VALUE
*vres
)
134 for (ep
= lp
->l_first
; ep
; ep
= ep
->e_next
) {
135 addvalue(vres
, &ep
->e_value
, &tmp
);
138 if (vres
->v_type
< 0)
144 addlistinv(LIST
*lp
, VALUE
*vres
)
149 for (ep
= lp
->l_first
; ep
; ep
= ep
->e_next
) {
150 if (ep
->e_value
.v_type
== V_LIST
) {
151 addlistinv(ep
->e_value
.v_list
, vres
);
153 invertvalue(&ep
->e_value
, &tmp1
);
154 addvalue(vres
, &tmp1
, &tmp2
);
159 if (vres
->v_type
< 0)