line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::SymbolicX::Complex;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1335
|
use 5.006;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
29
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use Math::Symbolic;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp qw/confess cluck/;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
85
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Math::Complex;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Math::Symbolic::Parser;
|
12
|
1
|
|
|
1
|
|
5
|
use Math::Complex;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
957
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Math::SymbolicX::Complex;
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.01';
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Regular expression for floating point numbers.
|
19
|
|
|
|
|
|
|
# Stolen from Math::Complex version 1.34, but since this will be released
|
20
|
|
|
|
|
|
|
# under the same (artistic/perl) license, that should be alright.
|
21
|
|
|
|
|
|
|
my $floatingpoint = qr'\s*([\+\-]?(?:(?:(?:\d+(?:_\d+)*(?:\.\d*(?:_\d+)*)?|\.\d+(?:_\d+)*)(?:[eE][\+\-]?\d+(?:_\d+)*)?)))';
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $opregex = qr/[^0-9e\-\+\*\/\.]/;
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Math::SymbolicX::ParserExtensionFactory (
|
27
|
|
|
|
|
|
|
complex => sub {
|
28
|
2
|
|
|
|
|
5168
|
my $argstring = shift;
|
29
|
2
|
|
|
|
|
7
|
$argstring = _parse_args($argstring);
|
30
|
2
|
|
|
|
|
8
|
my ($re, $im) = split(/,/, $argstring, 2);
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# get numeric representations
|
33
|
2
|
50
|
33
|
|
|
27
|
confess "Could not generate Math::Complex object from '$argstring' "
|
34
|
|
|
|
|
|
|
."in Math::Symbolic parse."
|
35
|
|
|
|
|
|
|
if $re =~ $opregex or $im =~ $opregex;
|
36
|
2
|
|
|
|
|
99
|
$re = eval $re;
|
37
|
2
|
50
|
|
|
|
10
|
confess "Could not generate Math::Complex object from '$argstring' "
|
38
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error Msg.: $@)" if $@;
|
39
|
2
|
|
|
|
|
86
|
$im = eval $im;
|
40
|
2
|
50
|
|
|
|
8
|
confess "Could not generate Math::Complex object from '$argstring' "
|
41
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error Msg.: $@)" if $@;
|
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
13
|
my $object;
|
44
|
2
|
|
|
|
|
4
|
eval {
|
45
|
2
|
|
|
|
|
14
|
$object = Math::Complex->make($re, $im);
|
46
|
|
|
|
|
|
|
};
|
47
|
2
|
50
|
|
|
|
325
|
confess "Could not generate Math::Complex object from '$argstring' "
|
48
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error msg.: '$@')" if $@;
|
49
|
2
|
|
|
|
|
16
|
return Math::Symbolic::Constant->new($object);
|
50
|
|
|
|
|
|
|
},
|
51
|
|
|
|
|
|
|
polar => sub {
|
52
|
2
|
|
|
|
|
4759
|
my $argstring = shift;
|
53
|
2
|
|
|
|
|
7
|
$argstring = _parse_args($argstring);
|
54
|
2
|
|
|
|
|
9
|
my ($r, $arg) = split(/,/, $argstring, 2);
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# get numeric representations
|
57
|
2
|
50
|
33
|
|
|
23
|
confess "Could not generate Math::Complex object from '$argstring' "
|
58
|
|
|
|
|
|
|
."in Math::Symbolic parse."
|
59
|
|
|
|
|
|
|
if $r =~ $opregex or $arg =~ $opregex;
|
60
|
2
|
|
|
|
|
112
|
$r = eval $r;
|
61
|
2
|
50
|
|
|
|
10
|
confess "Could not generate Math::Complex object from '$argstring' "
|
62
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error Msg.: $@)" if $@;
|
63
|
2
|
|
|
|
|
112
|
$arg = eval $arg;
|
64
|
2
|
50
|
|
|
|
9
|
confess "Could not generate Math::Complex object from '$argstring' "
|
65
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error Msg.: $@)" if $@;
|
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
4
|
my $object;
|
68
|
2
|
|
|
|
|
2
|
eval {
|
69
|
2
|
|
|
|
|
13
|
$object = Math::Complex->emake($r, $arg);
|
70
|
|
|
|
|
|
|
};
|
71
|
2
|
50
|
|
|
|
239
|
confess "Could not generate Math::Complex object from '$argstring' "
|
72
|
|
|
|
|
|
|
."in Math::Symbolic parse. (Error msg.: '$@')" if $@;
|
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
12
|
return Math::Symbolic::Constant->new($object);
|
75
|
|
|
|
|
|
|
},
|
76
|
1
|
|
|
1
|
|
943
|
);
|
|
1
|
|
|
|
|
1044
|
|
|
1
|
|
|
|
|
14
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _parse_args {
|
80
|
4
|
|
|
4
|
|
9
|
my $str = shift;
|
81
|
4
|
|
|
|
|
10
|
$str =~ s/\s+//g;
|
82
|
4
|
|
|
|
|
11
|
$str =~ s{pi}{Math::Symbolic::ExportConstants::PI}e;
|
|
2
|
|
|
|
|
18
|
|
83
|
4
|
|
|
|
|
10
|
return $str;
|
84
|
|
|
|
|
|
|
# We tried to be very smart at first, but it turned out to be buggy:
|
85
|
|
|
|
|
|
|
# $str =~ s{
|
86
|
|
|
|
|
|
|
# ((?:$floatingpoint)?)pi
|
87
|
|
|
|
|
|
|
# }
|
88
|
|
|
|
|
|
|
# {
|
89
|
|
|
|
|
|
|
# warn "$1";
|
90
|
|
|
|
|
|
|
# defined($1) && $1 ne ''
|
91
|
|
|
|
|
|
|
# ? $1 * Math::Symbolic::ExportConstants::PI
|
92
|
|
|
|
|
|
|
# : Math::Symbolic::ExportConstants::PI
|
93
|
|
|
|
|
|
|
# }e;
|
94
|
|
|
|
|
|
|
# return $str;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1;
|
98
|
|
|
|
|
|
|
__END__
|