-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
41 lines (37 loc) · 860 Bytes
/
init.c
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
#include <stddef.h>
#include <math.h>
#include "hoc.h"
#include "y.tab.h"
static const struct {
char const *name;
double val;
} consts[] = {
{"PI", 3.14159265358979323846},
{"E", 2.71828182845904523536},
{"GAMMA", 0.57721566490153286060}, // Euler’s constant
{"DEG", 57.29577951308232087680}, // degrees per radian
{"PHI", 1.61803398874989484820}, // golden ratio
};
static const struct {
char const *name;
double (*func)(double);
} builtins[] = {
{"sin", sin},
{"cos", cos},
{"atan", atan},
{"log", log},
{"log10", log10},
{"exp", exp},
{"sqrt", sqrt},
{"abs", fabs},
};
void
init(void)
{
for (size_t c = 0; c < nelem(consts); c++)
install(consts[c].name, VAR, consts[c].val);
for (size_t b = 0; b < nelem(builtins); b++) {
Symbol *s = install(builtins[b].name, BLTIN, 0);
s->func = builtins[b].func;
}
}