Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / factors.cpp
blobebd2b587968bb0709b8209ee3546a2d5e23816d9
1 // Push expression factors onto the stack. For example...
2 //
3 // Input
4 //
5 // 2
6 // 3x + 2x + 1
7 //
8 // Output on stack
9 //
10 // [ 3 ]
11 // [ x^2 ]
12 // [ 2 ]
13 // [ x ]
14 // [ 1 ]
16 // but not necessarily in that order. Returns the number of factors.
18 #include "stdafx.h"
19 #include "defs.h"
21 // Local U *p is OK here because no functional path to garbage collector.
23 int
24 factors(U *p)
26 int h = tos;
27 if (car(p) == symbol(ADD)) {
28 p = cdr(p);
29 while (iscons(p)) {
30 push_term_factors(car(p));
31 p = cdr(p);
33 } else
34 push_term_factors(p);
35 return tos - h;
38 // Local U *p is OK here because no functional path to garbage collector.
40 void
41 push_term_factors(U *p)
43 if (car(p) == symbol(MULTIPLY)) {
44 p = cdr(p);
45 while (iscons(p)) {
46 push(car(p));
47 p = cdr(p);
49 } else
50 push(p);