repo.or.cz
/
eigenmath-fx.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git]
/
floor.cpp
blob
960731c1fbf71479374746bb2554ee34b0d32ba9
1
#include
"stdafx.h"
2
#include
"defs.h"
3
4
void
5
eval_floor
(
void
)
6
{
7
push
(
cadr
(
p1
));
8
eval
();
9
yfloor
();
10
}
11
12
void
13
yfloor
(
void
)
14
{
15
save
();
16
yyfloor
();
17
restore
();
18
}
19
20
void
21
yyfloor
(
void
)
22
{
23
double
d
;
24
25
p1
=
pop
();
26
27
if
(!
isnum
(
p1
)) {
28
push_symbol
(
FLOOR
);
29
push
(
p1
);
30
list
(
2
);
31
return
;
32
}
33
34
if
(
isdouble
(
p1
)) {
35
d
=
floor
(
p1
->
u
.
d
);
36
push_double
(
d
);
37
return
;
38
}
39
40
if
(
isinteger
(
p1
)) {
41
push
(
p1
);
42
return
;
43
}
44
45
p3
=
alloc
();
46
p3
->
k
=
NUM
;
47
p3
->
u
.
q
.
a
=
mdiv
(
p1
->
u
.
q
.
a
,
p1
->
u
.
q
.
b
);
48
p3
->
u
.
q
.
b
=
mint
(
1
);
49
push
(
p3
);
50
51
if
(
isnegativenumber
(
p1
)) {
52
push_integer
(-
1
);
53
add
();
54
}
55
}
56
57
#if SELFTEST
58
59
static char
*
s
[] = {
60
61
"floor(a)"
,
62
"floor(a)"
,
63
64
"floor(a+b)"
,
65
"floor(a+b)"
,
66
67
"floor(5/2)"
,
68
"2"
,
69
70
"floor(4/2)"
,
71
"2"
,
72
73
"floor(3/2)"
,
74
"1"
,
75
76
"floor(2/2)"
,
77
"1"
,
78
79
"floor(1/2)"
,
80
"0"
,
81
82
"floor(0/2)"
,
83
"0"
,
84
85
"floor(-1/2)"
,
86
"-1"
,
87
88
"floor(-2/2)"
,
89
"-1"
,
90
91
"floor(-3/2)"
,
92
"-2"
,
93
94
"floor(-4/2)"
,
95
"-2"
,
96
97
"floor(-5/2)"
,
98
"-3"
,
99
100
"floor(5/2.0)"
,
101
"2"
,
102
103
"floor(4/2.0)"
,
104
"2"
,
105
106
"floor(3/2.0)"
,
107
"1"
,
108
109
"floor(2/2.0)"
,
110
"1"
,
111
112
"floor(1/2.0)"
,
113
"0"
,
114
115
"floor(0.0)"
,
116
"0"
,
117
118
"floor(-1/2.0)"
,
119
"-1"
,
120
121
"floor(-2/2.0)"
,
122
"-1"
,
123
124
"floor(-3/2.0)"
,
125
"-2"
,
126
127
"floor(-4/2.0)"
,
128
"-2"
,
129
130
"floor(-5/2.0)"
,
131
"-3"
,
132
};
133
134
void
135
test_floor
(
void
)
136
{
137
test
(
__FILE__
,
s
,
sizeof
s
/
sizeof
(
char
*));
138
}
139
140
#endif