File: math.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (105 lines) | stat: -rw-r--r-- 3,154 bytes parent folder | download | duplicates (4)
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
/* math - Elementwise arithmetic functions                             */
/* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
/* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
/* You may give out copies of this software; for conditions see the    */
/* file COPYING included with this distribution.                       */
 
#include "xlisp.h"
#include "xlstat.h"

extern LVAL s_standard_division;

/*************************************************************************/
/*************************************************************************/
/**                                                                     **/
/**                 Recursive Vectorized Math Functions                 **/
/**                                                                     **/
/*************************************************************************/
/*************************************************************************/

/* The basic math functions have been modified to operate element-wise   */
/* on compound data. The operation is recursive: if compound data items  */
/* contain compound data items the mapping proceeds down to the next     */
/* level.                                                                */

#define DEFVECFUN(__vf__, __f__) \
LVAL __vf__(V) { \
  switch (xlargc) { \
  case 0: return __f__(); \
  case 1: if (numberp(xlargv[0])) return __f__(); else break; \
  case 2: \
    if (numberp(xlargv[0]) && numberp(xlargv[1])) return __f__(); else break; \
  } \
  return recursive_subr_map_elements(__f__, __vf__);\
}

DEFVECFUN(xsradd, xadd)
DEFVECFUN(xsrsub, xsub)
DEFVECFUN(xsrmul, xmul)
DEFVECFUN(xsrdiv, xdiv)
DEFVECFUN(xsrmin, xmin)
DEFVECFUN(xsrmax, xmax)
DEFVECFUN(xsrrem, xrem)
DEFVECFUN(xsrmod, xmod)
DEFVECFUN(xsrexpt, xexpt)
DEFVECFUN(xsrlog, xlog)

#ifdef BIGNUMS
DEFVECFUN(xsrdenominator, xdenominator)
DEFVECFUN(xsrnumerator, xnumerator)
DEFVECFUN(xsrrational, xrational)

LOCAL DEFVECFUN(xsrfexpt1,xfexpt)
LOCAL DEFVECFUN(xsrfdiv1,xfdiv)

LVAL xsrfexpt(V)
{
  if (null(getvalue(s_standard_division))) return xsrfexpt1();
  else return xsrexpt();
}

LVAL xsrfdiv(V)
{
  if (null(getvalue(s_standard_division))) return xsrfdiv1();
  else return xsrdiv();
}
#endif /* BIGNUMS */

DEFVECFUN(xsrlogand, xlogand)
DEFVECFUN(xsrlogior, xlogior)
DEFVECFUN(xsrlogxor, xlogxor)
DEFVECFUN(xsrlognot, xlognot)

DEFVECFUN(xsrabs, xabs)
DEFVECFUN(xsradd1, xadd1)
DEFVECFUN(xsrsub1, xsub1)
DEFVECFUN(xsrsin, xsin)
DEFVECFUN(xsrcos, xcos)
DEFVECFUN(xsrtan, xtan)
DEFVECFUN(xsrexp, xexp)
DEFVECFUN(xsrsqrt, xsqrt)
DEFVECFUN(xsrfloat, xfloat)
DEFVECFUN(xsrrand, xrand)
DEFVECFUN(xsrasin, xasin)
DEFVECFUN(xsracos, xacos)
DEFVECFUN(xsratan, xatan)
DEFVECFUN(xsrphase, xphase)

DEFVECFUN(xsrfloor, xfloor)
DEFVECFUN(xsrceil, xceil)
DEFVECFUN(xsrfix, xfix)
DEFVECFUN(xsrround, xround)

DEFVECFUN(xsrminusp, xminusp)
DEFVECFUN(xsrzerop, xzerop)
DEFVECFUN(xsrplusp, xplusp)
DEFVECFUN(xsrevenp, xevenp)
DEFVECFUN(xsroddp, xoddp)

DEFVECFUN(xsrlss, xlss)
DEFVECFUN(xsrleq, xleq)
DEFVECFUN(xsrequ, xequ)
DEFVECFUN(xsrneq, xneq)
DEFVECFUN(xsrgeq, xgeq)
DEFVECFUN(xsrgtr, xgtr)