[system] / trunk / pg / lib / Value / Complex.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Value/Complex.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2624 Revision 2625
14 '/' => \&div, 14 '/' => \&div,
15 '**' => \&power, 15 '**' => \&power,
16 '.' => \&Value::_dot, 16 '.' => \&Value::_dot,
17 'x' => \&Value::cross, 17 'x' => \&Value::cross,
18 '<=>' => \&compare, 18 '<=>' => \&compare,
19 'cmp' => \&Value::cmp,
19 '~' => sub {$_[0]->conj}, 20 '~' => sub {$_[0]->conj},
20 'neg' => sub {$_[0]->neg}, 21 'neg' => sub {$_[0]->neg},
21 'abs' => sub {$_[0]->norm}, 22 'abs' => sub {$_[0]->norm},
22 'sqrt'=> sub {$_[0]->sqrt}, 23 'sqrt'=> sub {$_[0]->sqrt},
23 'exp' => sub {$_[0]->exp}, 24 'exp' => sub {$_[0]->exp},
135 if ($l->promotePrecedence($r)) {return $r->power($l,!$flag)} 136 if ($l->promotePrecedence($r)) {return $r->power($l,!$flag)}
136 $r = promote($r); 137 $r = promote($r);
137 if ($flag) {my $tmp = $l; $l = $r; $r = $tmp} 138 if ($flag) {my $tmp = $l; $l = $r; $r = $tmp}
138 my ($a,$b) = (@{$l->data}); 139 my ($a,$b) = (@{$l->data});
139 my ($c,$d) = (@{$r->data}); 140 my ($c,$d) = (@{$r->data});
140 return 1 if ($a == 1 && $b == 0) || ($c == 0 && $d == 0); 141 return Value::Real->make(1) if ($a eq '1' && $b == 0) || ($c == 0 && $d == 0);
141 return 0 if $c > 0 && ($a == 0 && $b == 0); 142 return Value::Real->make(0) if $c > 0 && ($a == 0 && $b == 0);
142 return CORE::exp($r * CORE::log($l)) 143 return exp($r * log($l))
143 } 144 }
144 145
145sub equal { 146sub equal {
146 my ($l,$r,$flag) = @_; 147 my ($l,$r,$flag) = @_;
147 my ($a,$b) = (@{$l->data}); 148 my ($a,$b) = (@{$l->data});
340 my $equation = shift; 341 my $equation = shift;
341 $a = Value::Real->make($a) unless ref($a); 342 $a = Value::Real->make($a) unless ref($a);
342 $b = Value::Real->make($b) unless ref($b); 343 $b = Value::Real->make($b) unless ref($b);
343 my $bi = 'i'; 344 my $bi = 'i';
344 return $a->$method($equation) if $b == 0; 345 return $a->$method($equation) if $b == 0;
345 $bi = abs($b)->$method($equation,1) . 'i' if abs($b) != 1; 346 $bi = abs($b)->$method($equation,1) . 'i' if abs($b) ne 1;
346 $bi = '-' . $bi if $b < 0; 347 $bi = '-' . $bi if $b < 0;
347 return $bi if $a == 0; 348 return $bi if $a == 0;
348 $bi = '+' . $bi if $b > 0; 349 $bi = '+' . $bi if $b > 0;
349 $a = $a->$method($equation); $a = "($a)" if $a =~ m/E/i; 350 $a = $a->$method($equation); $a = "($a)" if $a =~ m/E/i;
350 return $a.$bi; 351 return $a.$bi;

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9