[system] / trunk / pg / lib / Parser / Complex.pm Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/lib/Parser/Complex.pm

Revision 2624 Revision 2625
10 my \$self = shift; my \$class = ref(\$self) || \$self; 10 my \$self = shift; my \$class = ref(\$self) || \$self;
11 my \$equation = shift; my \$num; 11 my \$equation = shift; my \$num;
12 my (\$value,\$ref) = @_; 12 my (\$value,\$ref) = @_;
13 \$value = [\$value,0] unless ref(\$value) eq 'ARRAY'; 13 \$value = [\$value,0] unless ref(\$value) eq 'ARRAY';
14 \$value->[1] = 0 unless defined(\$value->[1]); 14 \$value->[1] = 0 unless defined(\$value->[1]);
15 ### set values near zero to being equal to zero?
16 \$equation->Error("Complex Numbers must have real and complex parts",\$ref) 15 \$equation->Error("Complex Numbers must have real and complex parts",\$ref)
17 if (scalar(@{\$value}) != 2); 16 if (scalar(@{\$value}) != 2);
18 \$num = bless { 17 \$num = bless {
19 value => \$value, type => \$Value::Type{complex}, isConstant => 1, 18 value => \$value, type => \$Value::Type{complex}, isConstant => 1,
20 ref => \$ref, equation => \$equation, 19 ref => \$ref, equation => \$equation,
21 }, \$class; 20 }, \$class;
22 \$num->{isOne} = 1 if (\$value->[0] == 1 && \$value->[1] == 0); 21 my \$z = Value::Complex->make(@{\$value});
23 \$num->{isZero} = 1 if (\$value->[0] == 0 && \$value->[1] == 0); 22 \$num->{isOne} = 1 if \$z cmp 1;
23 \$num->{isZero} = 1 if \$z == 0;
24 return \$num; 24 return \$num;
25} 25}
26 26
27# 27#
28# We know the answer to these, so no need to compute them. 28# We know the answer to these, so no need to compute them.
45sub reduce { 45sub reduce {
46 my \$self = shift; my (\$a,\$b) = @{\$self->{value}}; 46 my \$self = shift; my (\$a,\$b) = @{\$self->{value}};
47 if (\$a <= 0 && \$b <= 0 && (\$a != 0 || \$b != 0)) { 47 if (\$a <= 0 && \$b <= 0 && (\$a != 0 || \$b != 0)) {
48 \$self->{value} = [-\$a,-\$b]; 48 \$self->{value} = [-\$a,-\$b];
49 \$self = Parser::UOP::Neg(\$self); 49 \$self = Parser::UOP::Neg(\$self);
50 \$self->{isOne} = 1 if Value::Complex->make(-\$a,-\$b) == 1;
50 } 51 }
51 return \$self; 52 return \$self;
52} 53}
53 54
54# 55#

Legend:
 Removed from v.2624 changed lines Added in v.2625