-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloat.cpp
84 lines (70 loc) · 1.01 KB
/
float.cpp
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
#include "stdafx.h"
#include "defs.h"
void
eval_float(void)
{
push(cadr(p1));
eval();
yyfloat();
eval(); // normalize
}
void
yyfloat(void)
{
int i, h;
save();
p1 = pop();
if (iscons(p1)) {
h = tos;
while (iscons(p1)) {
push(car(p1));
yyfloat();
p1 = cdr(p1);
}
list(tos - h);
} else if (p1->k == TENSOR) {
push(p1);
copy_tensor();
p1 = pop();
for (i = 0; i < p1->u.tensor->nelem; i++) {
push(p1->u.tensor->elem[i]);
yyfloat();
p1->u.tensor->elem[i] = pop();
}
push(p1);
} else if (p1->k == NUM) {
push(p1);
bignum_float();
} else if (p1 == symbol(PI))
push_double(M_PI);
else if (p1 == symbol(E))
push_double(M_E);
else
push(p1);
restore();
}
#if SELFTEST
static const char *s[] = {
"float(x)",
"x",
"float(1/2)",
"0.5",
"float(pi)",
"3.14159",
"float(exp(1))",
"2.71828",
"x=(1/2,1/4)",
"",
"float(x)",
"(0.5,0.25)",
"x",
"(1/2,1/4)",
"x=quote(x)",
"",
};
void
test_float(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif