|
FAUST compiler
0.9.9.6b8
|
#include "mterm.hh"#include "signals.hh"#include "ppsig.hh"#include "xtended.hh"#include <assert.h>
Go to the source code of this file.
Typedefs | |
| typedef map< Tree, int > | MP |
Functions | |
| static bool | isSigPow (Tree sig, Tree &x, int &n) |
| match x^p with p:int | |
| static Tree | sigPow (Tree x, int p) |
| produce x^p with p:int | |
| static int | common (int a, int b) |
| return the "common quantity" of two numbers | |
| mterm | gcd (const mterm &m1, const mterm &m2) |
| return a mterm that is the greatest common divisor of two mterms | |
| static bool | contains (int a, int b) |
| We say that a "contains" b if a/b > 0. | |
| static Tree | buildPowTerm (Tree f, int q) |
| produce the canonical tree correspoding to a mterm | |
| static void | combineMulLeft (Tree &R, Tree A) |
| Combine R and A doing R = R*A or R = A. | |
| static void | combineDivLeft (Tree &R, Tree A) |
| Combine R and A doing R = R*A or R = A. | |
| static void | combineMulDiv (Tree &M, Tree &D, Tree f, int q) |
| Do M = M * f**q or D = D * f**-q. | |
| static Tree buildPowTerm | ( | Tree | f, |
| int | q | ||
| ) | [static] |
produce the canonical tree correspoding to a mterm
Build a power term of type f**q -> (((f.f).f)..f) with q>0
Definition at line 362 of file mterm.cpp.
References sigPow().
Referenced by combineMulDiv().
{
assert(f);
assert(q>0);
if (q>1) {
return sigPow(f, q);
} else {
return f;
}
}


| static void combineDivLeft | ( | Tree & | R, |
| Tree | A | ||
| ) | [static] |
Combine R and A doing R = R*A or R = A.
Definition at line 386 of file mterm.cpp.
References sigDiv(), and tree().
Referenced by mterm::normalizedTree().


| static void combineMulDiv | ( | Tree & | M, |
| Tree & | D, | ||
| Tree | f, | ||
| int | q | ||
| ) | [static] |
Do M = M * f**q or D = D * f**-q.
Definition at line 396 of file mterm.cpp.
References buildPowTerm(), and combineMulLeft().
Referenced by mterm::normalizedTree().
{
#ifdef TRACE
cerr << "combineMulDiv (" << M << "/" << D << "*" << ppsig(f)<< "**" << q << endl;
#endif
if (f) {
assert(q != 0);
if (q > 0) {
combineMulLeft(M, buildPowTerm(f,q));
} else if (q < 0) {
combineMulLeft(D, buildPowTerm(f,-q));
}
}
}


| static void combineMulLeft | ( | Tree & | R, |
| Tree | A | ||
| ) | [static] |
Combine R and A doing R = R*A or R = A.
Definition at line 376 of file mterm.cpp.
References sigMul().
Referenced by combineMulDiv(), and mterm::normalizedTree().
{
if (R && A) R = sigMul(R,A);
else if (A) R = A;
else exit(1);
}


| static int common | ( | int | a, |
| int | b | ||
| ) | [static] |
return the "common quantity" of two numbers
Definition at line 284 of file mterm.cpp.
Referenced by gcd().
{
if (a > 0 & b > 0) {
return min(a,b);
} else if (a < 0 & b < 0) {
return max(a,b);
} else {
return 0;
}
}


| static bool contains | ( | int | a, |
| int | b | ||
| ) | [static] |
We say that a "contains" b if a/b > 0.
For example 3 contains 2 and -4 contains -2, but 3 doesn't contains -2 and -3 doesn't contains 1
Definition at line 325 of file mterm.cpp.
Referenced by mterm::hasDivisor().
{
return (b == 0) || (a/b > 0);
}

return a mterm that is the greatest common divisor of two mterms
Definition at line 299 of file mterm.cpp.
References common(), mterm::fCoef, mterm::fFactors, and tree().
Referenced by aterm::greatestDivisor().
{
//cerr << "GCD of " << m1 << " and " << m2 << endl;
Tree c = (m1.fCoef == m2.fCoef) ? m1.fCoef : tree(1); // common coefficient (real gcd not needed)
mterm R(c);
for (MP::const_iterator p1 = m1.fFactors.begin(); p1 != m1.fFactors.end(); p1++) {
Tree t = p1->first;
MP::const_iterator p2 = m2.fFactors.find(t);
if (p2 != m2.fFactors.end()) {
int v1 = p1->second;
int v2 = p2->second;
int c = common(v1,v2);
if (c != 0) {
R.fFactors[t] = c;
}
}
}
//cerr << "GCD of " << m1 << " and " << m2 << " is : " << R << endl;
return R;
}


match x^p with p:int
Definition at line 77 of file mterm.cpp.
References CTree::branch(), getUserData(), gPowPrim, and isSigInt().
Referenced by mterm::operator*=(), and mterm::operator/=().
{
//cerr << "isSigPow("<< *sig << ')' << endl;
xtended* p = (xtended*) getUserData(sig);
if (p == gPowPrim) {
if (isSigInt(sig->branch(1), &n)) {
x = sig->branch(0);
//cerr << "factor of isSigPow " << *x << endl;
return true;
}
}
return false;
}


1.8.0