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]
/
lcm.cpp
blob
18b560c5caaeeac664646f6c7bdf5976e12229ba
1
// Find the least common multiple of two expressions.
2
3
#include
"stdafx.h"
4
#include
"defs.h"
5
6
void
7
eval_lcm
(
void
)
8
{
9
p1
=
cdr
(
p1
);
10
push
(
car
(
p1
));
11
eval
();
12
p1
=
cdr
(
p1
);
13
while
(
iscons
(
p1
)) {
14
push
(
car
(
p1
));
15
eval
();
16
lcm
();
17
p1
=
cdr
(
p1
);
18
}
19
}
20
21
void
22
lcm
(
void
)
23
{
24
int
x
;
25
x
=
expanding
;
26
save
();
27
yylcm
();
28
restore
();
29
expanding
=
x
;
30
}
31
32
void
33
yylcm
(
void
)
34
{
35
expanding
=
1
;
36
37
p2
=
pop
();
38
p1
=
pop
();
39
40
push
(
p1
);
41
push
(
p2
);
42
gcd
();
43
44
push
(
p1
);
45
divide
();
46
47
push
(
p2
);
48
divide
();
49
50
inverse
();
51
}
52
53
#if SELFTEST
54
55
static char
*
s
[] = {
56
57
"lcm(4,6)"
,
58
"12"
,
59
60
"lcm(4*x,6*x*y)"
,
61
"12*x*y"
,
62
63
// multiple arguments
64
65
"lcm(2,3,4)"
,
66
"12"
,
67
};
68
69
void
70
test_lcm
(
void
)
71
{
72
test
(
__FILE__
,
s
,
sizeof
(
s
) /
sizeof
(
char
*));
73
}
74
75
#endif