-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathpoly.c
More file actions
172 lines (157 loc) · 3.99 KB
/
Copy pathpoly.c
File metadata and controls
172 lines (157 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* poly - polynomial functions
*
* Copyright (C) 1999,2021,2023,2026 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc 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 Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 1995/12/02 03:10:28
* File existed as early as: 1995
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* important <system> header includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
/*
* calc local src includes
*/
#include "value.h"
#include "banned.h" /* include after all other includes */
bool
evp(LISTELEM *cp, LISTELEM *x, VALUE *vres)
{
VALUE v, tmp1, tmp2;
bool s;
s = false;
while (cp) {
if (s) {
mulvalue(vres, &x->e_value, &tmp1);
freevalue(vres);
*vres = tmp1;
}
v = cp->e_value;
if (v.v_type == V_LIST) {
if (evalpoly(v.v_list, x->e_next, &tmp1)) {
if (s) {
addvalue(&tmp1, vres, &tmp2);
freevalue(&tmp1);
freevalue(vres);
*vres = tmp2;
} else {
s = true;
*vres = tmp1;
}
}
} else {
if (s) {
addvalue(&v, vres, &tmp1);
freevalue(vres);
*vres = tmp1;
} else {
s = true;
copyvalue(&v, vres);
}
}
cp = cp->e_prev;
}
return s;
}
bool
evalpoly(LIST *clist, LISTELEM *x, VALUE *vres)
{
LISTELEM *cp;
VALUE v;
cp = clist->l_first;
if (cp == NULL) {
return false;
}
if (x == NULL) {
v = cp->e_value;
if (v.v_type == V_LIST) {
return evalpoly(v.v_list, x->e_next, vres);
}
copyvalue(&v, vres);
return true;
}
return evp(clist->l_last, x, vres);
}
void
insertitems(LIST *lp1, LIST *lp2)
{
LISTELEM *ep;
for (ep = lp2->l_first; ep; ep = ep->e_next) {
if (ep->e_value.v_type == V_LIST) {
insertitems(lp1, ep->e_value.v_list);
} else {
insertlistlast(lp1, &ep->e_value);
}
}
}
long
countlistitems(LIST *lp)
{
LISTELEM *ep;
long n = 0;
for (ep = lp->l_first; ep; ep = ep->e_next) {
if (ep->e_value.v_type == V_LIST) {
n += countlistitems(ep->e_value.v_list);
} else {
n++;
}
}
return n;
}
void
addlistitems(LIST *lp, VALUE *vres)
{
LISTELEM *ep;
VALUE tmp;
for (ep = lp->l_first; ep; ep = ep->e_next) {
addvalue(vres, &ep->e_value, &tmp);
freevalue(vres);
*vres = tmp;
if (vres->v_type < 0) {
return;
}
}
}
void
addlistinv(LIST *lp, VALUE *vres)
{
LISTELEM *ep;
VALUE tmp1, tmp2;
for (ep = lp->l_first; ep; ep = ep->e_next) {
if (ep->e_value.v_type == V_LIST) {
addlistinv(ep->e_value.v_list, vres);
} else {
invertvalue(&ep->e_value, &tmp1);
addvalue(vres, &tmp1, &tmp2);
freevalue(&tmp1);
freevalue(vres);
*vres = tmp2;
}
if (vres->v_type < 0) {
return;
}
}
}