1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
20 |
|
|
21 |
|
#include <errno.h> |
22 |
|
|
23 |
+ |
#include <math.h> |
24 |
+ |
|
25 |
|
#include "calcomp.h" |
26 |
|
|
27 |
|
/* bits in argument flag (better be right!) */ |
104 |
|
fundefined(fname) /* return # of arguments for function */ |
105 |
|
char *fname; |
106 |
|
{ |
107 |
< |
LIBR *lp; |
107 |
> |
register LIBR *lp; |
108 |
|
register VARDEF *vp; |
109 |
|
|
110 |
< |
if ((vp = varlookup(fname)) == NULL || vp->def == NULL |
111 |
< |
|| vp->def->v.kid->type != FUNC) |
110 |
< |
if ((lp = liblookup(fname)) == NULL) |
111 |
< |
return(0); |
112 |
< |
else |
113 |
< |
return(lp->nargs); |
114 |
< |
else |
110 |
> |
if ((vp = varlookup(fname)) != NULL && vp->def != NULL |
111 |
> |
&& vp->def->v.kid->type == FUNC) |
112 |
|
return(nekids(vp->def->v.kid) - 1); |
113 |
+ |
lp = vp != NULL ? vp->lib : liblookup(fname); |
114 |
+ |
if (lp == NULL) |
115 |
+ |
return(0); |
116 |
+ |
return(lp->nargs); |
117 |
|
} |
118 |
|
|
119 |
|
|
154 |
|
int assign; |
155 |
|
double (*fptr)(); |
156 |
|
{ |
157 |
+ |
int oldlibsize = libsize; |
158 |
|
register LIBR *lp; |
159 |
|
|
160 |
|
if ((lp = liblookup(fname)) == NULL) { /* insert */ |
187 |
|
lp[0].atyp = assign; |
188 |
|
lp[0].f = fptr; |
189 |
|
} |
190 |
< |
libupdate(fname); /* relink library */ |
190 |
> |
if (libsize != oldlibsize) |
191 |
> |
libupdate(fname); /* relink library */ |
192 |
|
} |
193 |
|
|
194 |
|
|
340 |
|
|
341 |
|
|
342 |
|
#ifndef VARIABLE |
343 |
+ |
static VARDEF *varlist = NULL; /* our list of dummy variables */ |
344 |
+ |
|
345 |
+ |
|
346 |
|
VARDEF * |
347 |
|
varinsert(vname) /* dummy variable insert */ |
348 |
|
char *vname; |
353 |
|
vp->name = savestr(vname); |
354 |
|
vp->nlinks = 1; |
355 |
|
vp->def = NULL; |
356 |
< |
vp->lib = NULL; |
357 |
< |
vp->next = NULL; |
356 |
> |
vp->lib = liblookup(vname); |
357 |
> |
vp->next = varlist; |
358 |
> |
varlist = vp; |
359 |
|
return(vp); |
360 |
|
} |
361 |
|
|
363 |
|
varfree(vp) /* free dummy variable */ |
364 |
|
register VARDEF *vp; |
365 |
|
{ |
366 |
+ |
register VARDEF *vp2; |
367 |
+ |
|
368 |
+ |
if (vp == varlist) |
369 |
+ |
varlist = vp->next; |
370 |
+ |
else { |
371 |
+ |
for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next) |
372 |
+ |
; |
373 |
+ |
vp2->next = vp->next; |
374 |
+ |
} |
375 |
|
freestr(vp->name); |
376 |
|
efree((char *)vp); |
377 |
|
} |
378 |
+ |
|
379 |
+ |
|
380 |
+ |
libupdate(nm) /* update library */ |
381 |
+ |
char *nm; |
382 |
+ |
{ |
383 |
+ |
register VARDEF *vp; |
384 |
+ |
|
385 |
+ |
for (vp = varlist; vp != NULL; vp = vp->next) |
386 |
+ |
vp->lib = liblookup(vp->name); |
387 |
+ |
} |
388 |
|
#endif |
389 |
|
|
390 |
|
|
472 |
|
static double |
473 |
|
l_rand() /* random function between 0 and 1 */ |
474 |
|
{ |
449 |
– |
extern double floor(); |
475 |
|
double x; |
476 |
|
|
477 |
|
x = argument(1); |
485 |
|
static double |
486 |
|
l_floor() /* return largest integer not greater than arg1 */ |
487 |
|
{ |
463 |
– |
extern double floor(); |
464 |
– |
|
488 |
|
return(floor(argument(1))); |
489 |
|
} |
490 |
|
|
492 |
|
static double |
493 |
|
l_ceil() /* return smallest integer not less than arg1 */ |
494 |
|
{ |
472 |
– |
extern double ceil(); |
473 |
– |
|
495 |
|
return(ceil(argument(1))); |
496 |
|
} |
497 |
|
|
500 |
|
static double |
501 |
|
l_sqrt() |
502 |
|
{ |
482 |
– |
extern double sqrt(); |
483 |
– |
|
503 |
|
return(sqrt(argument(1))); |
504 |
|
} |
505 |
|
|
507 |
|
static double |
508 |
|
l_sin() |
509 |
|
{ |
491 |
– |
extern double sin(); |
492 |
– |
|
510 |
|
return(sin(argument(1))); |
511 |
|
} |
512 |
|
|
514 |
|
static double |
515 |
|
l_cos() |
516 |
|
{ |
500 |
– |
extern double cos(); |
501 |
– |
|
517 |
|
return(cos(argument(1))); |
518 |
|
} |
519 |
|
|
521 |
|
static double |
522 |
|
l_tan() |
523 |
|
{ |
509 |
– |
extern double tan(); |
510 |
– |
|
524 |
|
return(tan(argument(1))); |
525 |
|
} |
526 |
|
|
528 |
|
static double |
529 |
|
l_asin() |
530 |
|
{ |
518 |
– |
extern double asin(); |
519 |
– |
|
531 |
|
return(asin(argument(1))); |
532 |
|
} |
533 |
|
|
535 |
|
static double |
536 |
|
l_acos() |
537 |
|
{ |
527 |
– |
extern double acos(); |
528 |
– |
|
538 |
|
return(acos(argument(1))); |
539 |
|
} |
540 |
|
|
542 |
|
static double |
543 |
|
l_atan() |
544 |
|
{ |
536 |
– |
extern double atan(); |
537 |
– |
|
545 |
|
return(atan(argument(1))); |
546 |
|
} |
547 |
|
|
549 |
|
static double |
550 |
|
l_atan2() |
551 |
|
{ |
545 |
– |
extern double atan2(); |
546 |
– |
|
552 |
|
return(atan2(argument(1), argument(2))); |
553 |
|
} |
554 |
|
|
556 |
|
static double |
557 |
|
l_exp() |
558 |
|
{ |
554 |
– |
extern double exp(); |
555 |
– |
|
559 |
|
return(exp(argument(1))); |
560 |
|
} |
561 |
|
|
563 |
|
static double |
564 |
|
l_log() |
565 |
|
{ |
563 |
– |
extern double log(); |
564 |
– |
|
566 |
|
return(log(argument(1))); |
567 |
|
} |
568 |
|
|
570 |
|
static double |
571 |
|
l_log10() |
572 |
|
{ |
572 |
– |
extern double log10(); |
573 |
– |
|
573 |
|
return(log10(argument(1))); |
574 |
|
} |
575 |
|
#endif |