Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / float.cpp
blob3fffd8fc19cd676ba401c2fbb0b486db4fc31588
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 eval_float(void)
7 push(cadr(p1));
8 eval();
9 yyfloat();
10 eval(); // normalize
13 void
14 yyfloat(void)
16 int i, h;
17 save();
18 p1 = pop();
19 if (iscons(p1)) {
20 h = tos;
21 while (iscons(p1)) {
22 push(car(p1));
23 yyfloat();
24 p1 = cdr(p1);
26 list(tos - h);
27 } else if (p1->k == TENSOR) {
28 push(p1);
29 copy_tensor();
30 p1 = pop();
31 for (i = 0; i < p1->u.tensor->nelem; i++) {
32 push(p1->u.tensor->elem[i]);
33 yyfloat();
34 p1->u.tensor->elem[i] = pop();
36 push(p1);
37 } else if (p1->k == NUM) {
38 push(p1);
39 bignum_float();
40 } else if (p1 == symbol(PI))
41 push_double(M_PI);
42 else if (p1 == symbol(E))
43 push_double(M_E);
44 else
45 push(p1);
46 restore();
49 #if SELFTEST
51 static char *s[] = {
53 "float(x)",
54 "x",
56 "float(1/2)",
57 "0.5",
59 "float(pi)",
60 "3.14159",
62 "float(exp(1))",
63 "2.71828",
65 "x=(1/2,1/4)",
66 "",
68 "float(x)",
69 "(0.5,0.25)",
71 "x",
72 "(1/2,1/4)",
74 "x=quote(x)",
75 "",
78 void
79 test_float(void)
81 test(__FILE__, s, sizeof s / sizeof (char *));
84 #endif