Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / lcm.cpp
blob18b560c5caaeeac664646f6c7bdf5976e12229ba
1 // Find the least common multiple of two expressions.
3 #include "stdafx.h"
4 #include "defs.h"
6 void
7 eval_lcm(void)
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);
21 void
22 lcm(void)
24 int x;
25 x = expanding;
26 save();
27 yylcm();
28 restore();
29 expanding = x;
32 void
33 yylcm(void)
35 expanding = 1;
37 p2 = pop();
38 p1 = pop();
40 push(p1);
41 push(p2);
42 gcd();
44 push(p1);
45 divide();
47 push(p2);
48 divide();
50 inverse();
53 #if SELFTEST
55 static char *s[] = {
57 "lcm(4,6)",
58 "12",
60 "lcm(4*x,6*x*y)",
61 "12*x*y",
63 // multiple arguments
65 "lcm(2,3,4)",
66 "12",
69 void
70 test_lcm(void)
72 test(__FILE__, s, sizeof (s) / sizeof (char *));
75 #endif