File: node.cpp

package info (click to toggle)
faust 0.9.95~repack1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 164,732 kB
  • ctags: 18,777
  • sloc: cpp: 90,427; sh: 6,116; java: 4,501; objc: 4,428; ansic: 3,301; makefile: 1,298; ruby: 950; yacc: 511; xml: 398; lex: 218; python: 136
file content (44 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "node.hh"
#include "math.h"
#include <stdlib.h>

ostream& Node::print (ostream& fout) const 					///< print a node on a stream
{
	switch (fType) {
		case kIntNode : 	return fout << fData.i;
		case kDoubleNode : 	return fout << fData.f;
		case kSymNode : 	return fout << *(fData.s);
		case kPointerNode : return fout << "ptr:" << fData.p;
		default : 			return fout << "badnode";
	}
			
//	return fout;
}

//-----------------------------------------------------------------------------
// sameMagnitude(a,b) : true if the two nodes a and b represent numbers of same
//  absolute value. Int promoted to double if needed.
//

bool sameMagnitude(const Node& a, const Node& b)
{
    if (a.type() == kDoubleNode) {
        if (b.type() == kDoubleNode) {
            return fabs(a.getDouble()) == fabs(b.getDouble());
        } else if (b.type() == kIntNode) {
            return fabs(a.getDouble()) == fabs(double(b.getInt()));
        } else {
            return false;
        }
    } else if (a.type() == kIntNode) {
        if (b.type() == kDoubleNode) {
            return fabs(double(a.getInt())) == fabs(b.getDouble());
        } else if (b.type() == kIntNode) {
            return abs(a.getInt()) == abs(b.getInt());
        } else {
            return false;
        }
    } else {
        return false;
    }
}