-
Notifications
You must be signed in to change notification settings - Fork 8
/
primdeftest.c
69 lines (58 loc) · 1005 Bytes
/
primdeftest.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
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
/*
Test primitive definition in Atlast
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "atldef.h"
prim ptime()
{
So(1);
Push = time(NULL);
}
prim phhmmss()
{
struct tm *lt;
Sl(1);
So(2);
lt = localtime(&S0);
S0 = lt->tm_hour;
Push = lt->tm_min;
Push = lt->tm_sec;
}
prim pleibniz()
{
long nterms;
double sum = 0.0,
numer = 1.0,
denom = 1.0;
Sl(1);
nterms = S0;
Pop;
So(Realsize);
Push = 0;
while (nterms-- > 0) {
sum += numer / denom;
numer = -numer;
denom += 2.0;
}
SREAL0(sum * 4.0);
}
static struct primfcn timep[] = {
{"0TIME", ptime},
{"0HHMMSS", phhmmss},
{"0LEIBNIZ", pleibniz},
{NULL, (codeptr) 0}
};
int main()
{
char t[132];
atl_init();
atl_primdef(timep);
while (printf("-> "),
fgets(t, 132, stdin) != NULL)
atl_eval(t);
return 0;
}