Fix for a crash which happened when a document couldn't be opened.
[AROS-Contrib.git] / fish / icalc / complex.h
blob83c7092cabca9a165ff5e19d3ce265b6e8d51fe1
1 /*
2 * header for complex-number expression parser.
3 * MWS, March 17, 1991.
4 */
6 #ifndef NULL
7 #define NULL (0L)
8 #endif
10 typedef struct complex { /* our complex-number representation */
11 double real,
12 imag;
13 } Complex;
15 typedef struct symlist { /* parameter-list for a user-function */
16 struct symbol *sym;
17 struct symlist *next;
18 } SymList;
20 typedef struct userfunction {
21 struct remember *remkey;/* stores memory allocation list of tree */
22 struct symbol *param; /* parameter to function */
23 struct node *tree; /* the 'body' of the function */
24 } UserFunc;
26 typedef struct symbol { /* general symbol - numerous types */
27 char *name;
28 short type; /* VAR, CONST, BLTIN */
29 union {
30 Complex val; /* if VAR or CONST */
31 Complex (*cptr)(); /* C_BLTIN (function) */
32 double (*rptr)(); /* R_BLTIN (function) */
33 void (*vptr)(); /* COMMAND */
34 UserFunc ufunc; /* USER FUNCTION */
35 } u;
36 struct symbol *left, *right; /* children */
37 } Symbol;
40 typedef union {
41 Complex val; /* a complex number */
42 Symbol *sym; /* a symbol */
43 } Contents;
45 typedef struct node {
46 int type; /* type of node */
47 Contents contents; /* contents of node */
48 struct node *left, *right; /* children */
49 } Node;
52 * Convention: if node type is a builtin or unary operator,
53 * the left child will hold the expression that is the
54 * argument to the function.
57 #define sqr(x) (x)*(x)
58 #define sign(x) ((x) >= 0.0 ? '+' : '-')
60 #ifdef __GNUC__ /* Workaround for built-in function name conflicts */
61 #define cadd my_cadd
62 #define csub my_csub
63 #define cmul my_cmul
64 #define cdiv my_cdiv
65 #define cneg my_cneg
66 #define csqr my_csqr
67 #define csqrt my_csqrt
68 #define conj my_conj
69 #define cexp my_cexp
70 #define clog my_clog
71 #define cpow my_cpow
72 #define csin my_csin
73 #define ccos my_ccos
74 #define ctan my_ctan
75 #define casin my_casin
76 #define cacos my_cacos
77 #define catan my_catan
78 #define csinh my_csinh
79 #define ccosh my_ccosh
80 #define ctanh my_ctanh
81 #endif
82 /* Lattice-generated prototypes (some of them) */
83 /* Prototypes for functions defined in cmath.c */
84 Complex cadd(Complex w, Complex z);
85 Complex csub(Complex w, Complex z);
86 Complex cmul(Complex w, Complex z);
87 Complex cdiv(Complex w, Complex z);
88 Complex cneg(Complex z);
89 Complex csqr(Complex z);
90 Complex csqrt(Complex z);
91 Complex conj(Complex z);
92 Complex cexp(Complex z);
93 Complex clog(Complex z);
94 Complex cpow(Complex w, Complex z);
95 Complex csin(Complex z);
96 Complex ccos(Complex z);
97 Complex ctan(Complex z);
98 Complex casin(Complex z);
99 Complex cacos(Complex z);
100 Complex catan(Complex z);
101 Complex csinh(Complex z);
102 Complex ccosh(Complex z);
103 Complex ctanh(Complex z);
105 double Re(Complex z), Im(Complex z);
106 double arg(Complex z);
107 double norm(Complex z);
108 double _cabs(Complex z);
110 /* Prototypes for functions defined in math.c */
111 double Sqrt(double),
112 Log(double),
113 Asin(double),
114 Acos(double),
115 errcheck(double, char *);
117 /* Prototypes for functions defined in complex.y */
118 int yylex(void);
119 void warning(char *, char *),
120 yyerror(char *),
121 execerror(char *, char *),
122 welcome(void),
123 prompt(void);
124 int main(int, char **);
126 /* Prototypes for functions defined in symbol.c */
127 Symbol *lookup(char *s);
128 Symbol *allocsym(char *s, int t);
129 Symbol *install(char *s, int t, Complex cval);
130 void printlist(int type);
132 /* Prototypes for functions defined in init.c */
133 void init(void);
135 /* Prototypes for functions defined in command.c */
136 void besilent(),
137 beverbose(),
138 quiticalc(),
139 builtins(void),
140 userfuncs(void),
141 consts(void),
142 vars(void),
143 help(void);
145 /* Prototypes for functions defined in tree.c */
146 Node *n_asgn(Symbol *sym, Node *arg);
147 Node *n_binop(int op, Node *left, Node *right);
148 Node *n_unop(int op, Node *arg);
149 Node *n_func(int type, Symbol *sym, Node *arg);
150 Node *n_symbol(int type, Symbol *sym);
151 Node *n_number(double real, double imag);
152 Complex eval_tree(Node *n);
153 void delete_tree(Node *n);
155 /* Prototypes for functions defined in function.c */
156 void clear_ufunc(UserFunc *func);