| 1 | package Math::Cephes::Polynomial; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw(@EXPORT_OK $VERSION $MAXPOL $FMAXPOL $flag $fflag); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | eval {require Math::Complex; import Math::Complex qw(Re Im)}; | |||||||||||||||||||||||||||
| 6 | 1 | eval {local $^W=0; require Math::Fraction;}; | |||||||||||||||||||||||||||
| 7 | 1 | $MAXPOL = 256; | |||||||||||||||||||||||||||
| 8 | 1 | $flag = 0; | |||||||||||||||||||||||||||
| 9 | 1 | $FMAXPOL = 256; | |||||||||||||||||||||||||||
| 10 | 1 | $fflag = 0; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 13 | 1 | *import = \&Exporter::import; | |||||||||||||||||||||||||||
| 14 | 1 | @EXPORT_OK = qw(poly); | |||||||||||||||||||||||||||
| 15 | 1 | $VERSION = '0.5308'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | require Math::Cephes; | |||||||||||||||||||||||||||
| 18 | 1 | require Math::Cephes::Fraction; | |||||||||||||||||||||||||||
| 19 | 1 | require Math::Cephes::Complex; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 40 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 40 | my ($caller, $arr) = @_; | |||||||||||||||||||||||||||
| 23 | 40 | my $refer = ref($caller); | |||||||||||||||||||||||||||
| 24 | 40 | ▶ | my $class = $refer || $caller; | ||||||||||||||||||||||||||
|
Condition66%2/3
$refer || $caller
MC/DC0%0/2
$refer || $caller
$refer
$caller
Truth table66%2/3
A || B
A= $referB= $caller
| |||||||||||||||||||||||||||||
| 25 | 40 | ▶ | die "Must supply data for the polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$refer or $arr
MC/DC0%0/2
$refer or $arr
$refer
$arr
Truth table66%2/3
A or B
A= $referB= $arr
| |||||||||||||||||||||||||||||
| 26 | unless ($refer or $arr); | ||||||||||||||||||||||||||||
| 27 | 40 | my ($type, $ref, $data, $n); | |||||||||||||||||||||||||||
| 28 | 40 | ▶ | if ($refer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | ($type, $ref, $n) = | ||||||||||||||||||||||||||||
| 30 | 2 | ($caller->{type}, $caller->{ref}, $caller->{n}); | |||||||||||||||||||||||||||
| 31 | 2 | my $cdata = $caller->{data}; | |||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (ref($cdata) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | $data = [ @$cdata ]; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | my ($f, $s) = ($type eq 'fract') ? ('n', 'd') : ('r', 'i'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | $data = {$f => [ @{$cdata->{$f}} ], | |||||||||||||||||||||||||||
| 38 | 1 | $s => [ @{$cdata->{$s}} ], | |||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 38 | ($type, $ref, $data, $n) = get_data($arr); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 40 | bless { type => $type, | |||||||||||||||||||||||||||
| 46 | ref => $ref, | ||||||||||||||||||||||||||||
| 47 | data => $data, | ||||||||||||||||||||||||||||
| 48 | n => $n, | ||||||||||||||||||||||||||||
| 49 | }, $class; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub poly { | ||||||||||||||||||||||||||
|
Subroutine
poly: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | return Math::Cephes::Polynomial->new(shift); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 35 | ▶ | sub coef { | ||||||||||||||||||||||||||
|
Subroutine
coef: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 35 | return $_[0]->{data}; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 39 | ▶ | sub get_data { | ||||||||||||||||||||||||||
|
Subroutine
get_data: called CC=32 SCAR=43.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 39 | my ($arr, $ref_in) = @_; | |||||||||||||||||||||||||||
| 62 | 39 | ▶ | die "Must supply an array reference" unless ref($arr) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 39 | my $n = scalar @$arr - 1; | |||||||||||||||||||||||||||
| 64 | 39 | my $ref = ref($arr->[0]); | |||||||||||||||||||||||||||
| 65 | 39 | ▶ | die "array data must be of type '$ref_in'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ref_in and $ref_in ne $ref
MC/DC0%0/2
defined $ref_in and $ref_in ne $ref
defined $ref_in
$ref_in ne $ref
Truth table66%2/3
A and B
A= defined $ref_inB= $ref_in ne $ref
| |||||||||||||||||||||||||||||
| 66 | if (defined $ref_in and $ref_in ne $ref); | ||||||||||||||||||||||||||||
| 67 | 39 | my ($type, $data); | |||||||||||||||||||||||||||
| 68 | SWITCH: { | ||||||||||||||||||||||||||||
| 69 | 39 | ▶ | not $ref and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 21 | $type = 'scalar'; | |||||||||||||||||||||||||||
| 71 | 21 | foreach (@$arr) { | |||||||||||||||||||||||||||
| 72 | 3124 | ▶ | die 'Found conflicting types in array data' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | if ref($_); | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 21 | $data = $arr; | |||||||||||||||||||||||||||
| 76 | 21 | ▶ | set_max() unless $flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 21 | last SWITCH; | |||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||
| 79 | 18 | ▶ | $ref eq 'Math::Cephes::Complex' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 5 | $type = 'cmplx'; | |||||||||||||||||||||||||||
| 81 | 5 | foreach (@$arr) { | |||||||||||||||||||||||||||
| 82 | 15 | ▶ | die 'Found conflicting types in array data' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | unless ref($_) eq $ref; | ||||||||||||||||||||||||||||
| 84 | 15 | ▶ | die "array data must be of type '$ref_in'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ref_in and $ref_in ne $ref
MC/DC0%0/2
defined $ref_in and $ref_in ne $ref
defined $ref_in
$ref_in ne $ref
Truth table33%1/3
A and B
A= defined $ref_inB= $ref_in ne $ref
| |||||||||||||||||||||||||||||
| 85 | if (defined $ref_in and $ref_in ne $ref); | ||||||||||||||||||||||||||||
| 86 | 15 | push @{$data->{r}}, $_->r; | |||||||||||||||||||||||||||
| 87 | 15 | push @{$data->{i}}, $_->i; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 5 | ▶ | set_max() unless $flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 5 | last SWITCH; | |||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||
| 92 | 13 | ▶ | $ref eq 'Math::Complex' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 3 | $type = 'cmplx'; | |||||||||||||||||||||||||||
| 94 | 3 | foreach (@$arr) { | |||||||||||||||||||||||||||
| 95 | 9 | ▶ | die 'Found conflicting types in array data' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | unless ref($_) eq $ref; | ||||||||||||||||||||||||||||
| 97 | 9 | ▶ | die "array data must be of type '$ref_in'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ref_in and $ref_in ne $ref
MC/DC0%0/2
defined $ref_in and $ref_in ne $ref
defined $ref_in
$ref_in ne $ref
Truth table33%1/3
A and B
A= defined $ref_inB= $ref_in ne $ref
| |||||||||||||||||||||||||||||
| 98 | if (defined $ref_in and $ref_in ne $ref); | ||||||||||||||||||||||||||||
| 99 | 9 | push @{$data->{r}}, Re($_); | |||||||||||||||||||||||||||
| 100 | 9 | push @{$data->{i}}, Im($_); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 3 | ▶ | set_max() unless $flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 3 | last SWITCH; | |||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||
| 105 | 10 | ▶ | $ref eq 'Math::Cephes::Fraction' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 10 | $type = 'fract'; | |||||||||||||||||||||||||||
| 107 | 10 | foreach (@$arr) { | |||||||||||||||||||||||||||
| 108 | 33 | ▶ | die 'Found conflicting types in array data' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | unless ref($_) eq $ref; | ||||||||||||||||||||||||||||
| 110 | 33 | ▶ | die "array data must be of type '$ref_in'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ref_in and $ref_in ne $ref
MC/DC0%0/2
defined $ref_in and $ref_in ne $ref
defined $ref_in
$ref_in ne $ref
Truth table33%1/3
A and B
A= defined $ref_inB= $ref_in ne $ref
| |||||||||||||||||||||||||||||
| 111 | if (defined $ref_in and $ref_in ne $ref); | ||||||||||||||||||||||||||||
| 112 | 33 | my ($gcd, $n, $d) = Math::Cephes::euclid($_->n, $_->d); | |||||||||||||||||||||||||||
| 113 | 33 | push @{$data->{n}}, $n; | |||||||||||||||||||||||||||
| 114 | 33 | push @{$data->{d}}, $d; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 10 | ▶ | set_fmax() unless $fflag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 10 | last SWITCH; | |||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $ref eq 'Math::Fraction' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $type = 'fract'; | |||||||||||||||||||||||||||
| 121 | 0 | foreach (@$arr) { | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | die 'Found conflicting types in array data' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | unless ref($_) eq $ref; | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | die "array data must be of type '$ref_in'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ref_in and $ref_in ne $ref
MC/DC0%0/2
defined $ref_in and $ref_in ne $ref
defined $ref_in
$ref_in ne $ref
Truth table0%0/3
A and B
A= defined $ref_inB= $ref_in ne $ref
| |||||||||||||||||||||||||||||
| 125 | if (defined $ref_in and $ref_in ne $ref); | ||||||||||||||||||||||||||||
| 126 | 0 | push @{$data->{n}}, $_->{frac}->[0]; | |||||||||||||||||||||||||||
| 127 | 0 | push @{$data->{d}}, $_->{frac}->[1]; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | set_fmax() unless $fflag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||
| 132 | 0 | die "Unknown type '$ref' in array data"; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 39 | return ($type, $ref, $data, $n); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | my ($type, $data, $n) = | ||||||||||||||||||||||||||||
| 140 | 0 | ($self->{type}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $d = shift || $n; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $n
MC/DC0%0/2
shift() || $n
shift()
$n
Truth table0%0/3
A || B
A= shift()B= $n
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $d = $n if $d > $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | my $string; | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | for (my $j=0; $j<=$d; $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | my $coef; | |||||||||||||||||||||||||||
| 146 | SWITCH: { | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $type eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | my $n = $data->{n}->[$j]; | |||||||||||||||||||||||||||
| 149 | 0 | my $d = $data->{d}->[$j]; | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $sgn = $n < 0 ? ' -' : ' +'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $coef = $sgn . ($j == 0? '(' : ' (') . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | abs($n) . '/' . abs($d) . ')'; | ||||||||||||||||||||||||||||
| 153 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 154 | }; | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $type eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | my $re = $data->{r}->[$j]; | |||||||||||||||||||||||||||
| 157 | 0 | my $im = $data->{i}->[$j]; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $sgn = $j == 0 ? ' ' : ' + '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $coef = $sgn . '(' . $re . | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 160 | ( (int( $im / abs($im) ) == -1) ? '-' : '+' ) . | ||||||||||||||||||||||||||||
| 161 | ( ($im < 0) ? abs($im) : $im) . 'I)'; | ||||||||||||||||||||||||||||
| 162 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||
| 164 | 0 | my $f = $data->[$j]; | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $sgn = $f < 0 ? ' -' : ' +'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $coef = $j == 0 ? ' ' . $f : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | $sgn . ' ' . abs($f); | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $string .= $coef . ($j > 0 ? "x^$j" : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | return $string . "\n"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 3 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 3 | my ($self, $b) = @_; | |||||||||||||||||||||||||||
| 176 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 177 | 3 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 178 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 179 | ref($b) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 180 | 3 | ▶ | ($b->{type}, $b->{ref}, $b->{data}, $b->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | get_data($b, $aref); | ||||||||||||||||||||||||||||
| 182 | 3 | my $c = []; | |||||||||||||||||||||||||||
| 183 | 3 | my $nc; | |||||||||||||||||||||||||||
| 184 | SWITCH: { | ||||||||||||||||||||||||||||
| 185 | 3 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | $nc = $na > $nb ? $na: $nb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 1 | my $cn = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 188 | 1 | my $cd = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 189 | Math::Cephes::fpoladd_wrap($adata->{n}, $adata->{d}, $na, | ||||||||||||||||||||||||||||
| 190 | 1 | $bdata->{n}, $bdata->{d}, $nb, | |||||||||||||||||||||||||||
| 191 | $cn, $cd, $nc); | ||||||||||||||||||||||||||||
| 192 | 1 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 3 | my ($gcd, $n, $d) = Math::Cephes::euclid($cn->[$i], $cd->[$i]); | |||||||||||||||||||||||||||
| 194 | 3 | ▶ | push @$c, ($aref eq 'Math::Fraction' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | Math::Fraction->new($n, $d) : | ||||||||||||||||||||||||||||
| 196 | Math::Cephes::Fraction->new($n, $d) ); | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 199 | }; | ||||||||||||||||||||||||||||
| 200 | 2 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 1 | ▶ | $nc = $na > $nb ? $na: $nb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 1 | my $cr = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 203 | 1 | my $ci = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 204 | Math::Cephes::poladd($adata->{r}, $na, | ||||||||||||||||||||||||||||
| 205 | 1 | $bdata->{r}, $nb, $cr); | |||||||||||||||||||||||||||
| 206 | Math::Cephes::poladd($adata->{i}, $na, | ||||||||||||||||||||||||||||
| 207 | 1 | $bdata->{i}, $nb, $ci); | |||||||||||||||||||||||||||
| 208 | 1 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 3 | ▶ | push @$c, ($aref eq 'Math::Complex' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | Math::Complex->make($cr->[$i], $ci->[$i]) : | ||||||||||||||||||||||||||||
| 211 | Math::Cephes::Complex->new($cr->[$i], $ci->[$i]) ); | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||
| 215 | 1 | ▶ | $nc = $na > $nb ? $na + 1 : $nb + 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 1 | $c = [split //, 0 x $nc]; | |||||||||||||||||||||||||||
| 217 | 1 | Math::Cephes::poladd($adata, $na, $bdata, $nb, $c); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 3 | ▶ | return wantarray ? (Math::Cephes::Polynomial->new($c), $nc) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | Math::Cephes::Polynomial->new($c); | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 3 | ▶ | sub sub { | ||||||||||||||||||||||||||
|
Subroutine
sub: called CC=12 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 225 | 3 | my ($self, $b) = @_; | |||||||||||||||||||||||||||
| 226 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 227 | 3 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 228 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 229 | ref($b) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 230 | 3 | ▶ | ($b->{type}, $b->{ref}, $b->{data}, $b->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | get_data($b, $aref); | ||||||||||||||||||||||||||||
| 232 | 3 | my $c = []; | |||||||||||||||||||||||||||
| 233 | 3 | my $nc; | |||||||||||||||||||||||||||
| 234 | SWITCH: { | ||||||||||||||||||||||||||||
| 235 | 3 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 1 | ▶ | $nc = $na > $nb ? $na: $nb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 1 | my $cn = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 238 | 1 | my $cd = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 239 | Math::Cephes::fpolsub_wrap($bdata->{n}, $bdata->{d}, $nb, | ||||||||||||||||||||||||||||
| 240 | 1 | $adata->{n}, $adata->{d}, $na, | |||||||||||||||||||||||||||
| 241 | $cn, $cd, $nc); | ||||||||||||||||||||||||||||
| 242 | 1 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 3 | my ($gcd, $n, $d) = Math::Cephes::euclid($cn->[$i], $cd->[$i]); | |||||||||||||||||||||||||||
| 244 | 3 | ▶ | push @$c, ($aref eq 'Math::Fraction' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | Math::Fraction->new($n, $d) : | ||||||||||||||||||||||||||||
| 246 | Math::Cephes::Fraction->new($n, $d) ); | ||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 249 | }; | ||||||||||||||||||||||||||||
| 250 | 2 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 1 | ▶ | $nc = $na > $nb ? $na: $nb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 1 | my $cr = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 253 | 1 | my $ci = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 254 | Math::Cephes::polsub($bdata->{r}, $nb, | ||||||||||||||||||||||||||||
| 255 | 1 | $adata->{r}, $na, $cr); | |||||||||||||||||||||||||||
| 256 | Math::Cephes::polsub($bdata->{i}, $nb, | ||||||||||||||||||||||||||||
| 257 | 1 | $adata->{i}, $na, $ci); | |||||||||||||||||||||||||||
| 258 | 1 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 3 | ▶ | push @$c, ($aref eq 'Math::Complex' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | Math::Complex->make($cr->[$i], $ci->[$i]) : | ||||||||||||||||||||||||||||
| 261 | Math::Cephes::Complex->new($cr->[$i], $ci->[$i]) ); | ||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||
| 265 | 1 | ▶ | $nc = $na > $nb ? $na + 1 : $nb + 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 1 | $c = [split //, 0 x $nc]; | |||||||||||||||||||||||||||
| 267 | 1 | Math::Cephes::polsub($bdata, $nb, $adata, $na, $c); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | 3 | ▶ | return wantarray ? (Math::Cephes::Polynomial->new($c), $nc) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | Math::Cephes::Polynomial->new($c); | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 4 | ▶ | sub mul { | ||||||||||||||||||||||||||
|
Subroutine
mul: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 275 | 4 | my ($self, $b) = @_; | |||||||||||||||||||||||||||
| 276 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 277 | 4 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 278 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 279 | ref($b) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 280 | 4 | ▶ | ($b->{type}, $b->{ref}, $b->{data}, $b->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | get_data($b, $aref); | ||||||||||||||||||||||||||||
| 282 | 4 | my $c = []; | |||||||||||||||||||||||||||
| 283 | 4 | my $nc; | |||||||||||||||||||||||||||
| 284 | SWITCH: { | ||||||||||||||||||||||||||||
| 285 | 4 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 1 | $nc = $na + $nb; | |||||||||||||||||||||||||||
| 287 | 1 | my $cn = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 288 | 1 | my $cd = [split //, 1 x ($nc+1)]; | |||||||||||||||||||||||||||
| 289 | Math::Cephes::fpolmul_wrap($adata->{n}, $adata->{d}, $na, | ||||||||||||||||||||||||||||
| 290 | 1 | $bdata->{n}, $bdata->{d}, $nb, | |||||||||||||||||||||||||||
| 291 | $cn, $cd, $nc); | ||||||||||||||||||||||||||||
| 292 | 1 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 4 | my ($gcd, $n, $d) = Math::Cephes::euclid($cn->[$i], $cd->[$i]); | |||||||||||||||||||||||||||
| 294 | 4 | ▶ | push @$c, ($aref eq 'Math::Fraction' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | Math::Fraction->new($n, $d) : | ||||||||||||||||||||||||||||
| 296 | Math::Cephes::Fraction->new($n, $d) ); | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||
| 300 | 3 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 2 | my $dc = $na + $nb + 3; | |||||||||||||||||||||||||||
| 302 | 2 | my $cr = [split //, 0 x $dc]; | |||||||||||||||||||||||||||
| 303 | 2 | my $ci = [split //, 0 x $dc]; | |||||||||||||||||||||||||||
| 304 | $nc = Math::Cephes::cpmul_wrap($adata->{r}, $adata->{i}, $na+1, | ||||||||||||||||||||||||||||
| 305 | 2 | $bdata->{r}, $bdata->{i}, $nb+1, | |||||||||||||||||||||||||||
| 306 | $cr, $ci, $dc); | ||||||||||||||||||||||||||||
| 307 | 2 | $cr = [ @{$cr}[0..$nc] ]; | |||||||||||||||||||||||||||
| 308 | 2 | $ci = [ @{$ci}[0..$nc] ]; | |||||||||||||||||||||||||||
| 309 | 2 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 8 | ▶ | push @$c, ($aref eq 'Math::Complex' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | Math::Complex->make($cr->[$i], $ci->[$i]) : | ||||||||||||||||||||||||||||
| 312 | Math::Cephes::Complex->new($cr->[$i], $ci->[$i]) ); | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 2 | last SWITCH; | |||||||||||||||||||||||||||
| 315 | }; | ||||||||||||||||||||||||||||
| 316 | 1 | $nc = $na + $nb + 1; | |||||||||||||||||||||||||||
| 317 | 1 | $c = [split //, 0 x $nc]; | |||||||||||||||||||||||||||
| 318 | 1 | Math::Cephes::polmul($adata, $na, $bdata, $nb, $c); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | 4 | ▶ | return wantarray ? (Math::Cephes::Polynomial->new($c), $nc) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | Math::Cephes::Polynomial->new($c); | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 1 | ▶ | sub div { | ||||||||||||||||||||||||||
|
Subroutine
div: called CC=7 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 325 | 1 | my ($self, $b) = @_; | |||||||||||||||||||||||||||
| 326 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 327 | 1 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 328 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 329 | ref($b) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 330 | 1 | ▶ | ($b->{type}, $b->{ref}, $b->{data}, $b->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | get_data($b, $aref); | ||||||||||||||||||||||||||||
| 332 | 1 | my $c = []; | |||||||||||||||||||||||||||
| 333 | 1 | my $nc; | |||||||||||||||||||||||||||
| 334 | SWITCH: { | ||||||||||||||||||||||||||||
| 335 | 1 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 0 | $nc = $MAXPOL; | |||||||||||||||||||||||||||
| 337 | 0 | my $cn = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 338 | 0 | my $cd = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 339 | Math::Cephes::fpoldiv_wrap($adata->{n}, $adata->{d}, $na, | ||||||||||||||||||||||||||||
| 340 | 0 | $bdata->{n}, $bdata->{d}, $nb, | |||||||||||||||||||||||||||
| 341 | $cn, $cd, $nc); | ||||||||||||||||||||||||||||
| 342 | 0 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 0 | my ($gcd, $n, $d) = Math::Cephes::euclid($cn->[$i], $cd->[$i]); | |||||||||||||||||||||||||||
| 344 | 0 | ▶ | push @$c, ($aref eq 'Math::Fraction' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | Math::Fraction->new($n, $d) : | ||||||||||||||||||||||||||||
| 346 | Math::Cephes::Fraction->new($n, $d) ); | ||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 349 | }; | ||||||||||||||||||||||||||||
| 350 | 1 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 0 | die "Cannot do complex division"; | |||||||||||||||||||||||||||
| 352 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 353 | }; | ||||||||||||||||||||||||||||
| 354 | 1 | $nc = $MAXPOL; | |||||||||||||||||||||||||||
| 355 | 1 | $c = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 356 | 1 | Math::Cephes::poldiv($adata, $na, $bdata, $nb, $c); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | 1 | ▶ | return wantarray ? (Math::Cephes::Polynomial->new($c), $nc) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | Math::Cephes::Polynomial->new($c); | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 2 | ▶ | sub clr { | ||||||||||||||||||||||||||
|
Subroutine
clr: called CC=9 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 363 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 364 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 365 | 2 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 366 | 2 | ▶ | set_max() unless $flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 2 | ▶ | my $n = shift || $na; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $na
MC/DC0%0/2
shift() || $na
shift()
$na
Truth table33%1/3
A || B
A= shift()B= $na
| |||||||||||||||||||||||||||||
| 368 | 2 | ▶ | $n = $na if $n > $na; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | SWITCH: { | ||||||||||||||||||||||||||||
| 370 | 2 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 1 | ▶ | for (my $i=0; $i<=$n; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 2 | $self->{data}->{n}->[$i] = 0; | |||||||||||||||||||||||||||
| 373 | 2 | $self->{data}->{d}->[$i] = 1; | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 376 | }; | ||||||||||||||||||||||||||||
| 377 | 1 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | for (my $i=0; $i<=$n; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | $self->{data}->{r}->[$i] = 0; | |||||||||||||||||||||||||||
| 380 | 0 | $self->{data}->{i}->[$i] = 0; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||
| 384 | 1 | ▶ | for (my $i=0; $i<=$n; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | 3 | $self->{data}->[$i] = 0; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 3 | ▶ | sub sbt { | ||||||||||||||||||||||||||
|
Subroutine
sbt: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 391 | 3 | my ($self, $b) = @_; | |||||||||||||||||||||||||||
| 392 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 393 | 3 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 394 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 395 | ref($b) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 396 | 3 | ▶ | ($b->{type}, $b->{ref}, $b->{data}, $b->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | get_data($b, $aref); | ||||||||||||||||||||||||||||
| 398 | 3 | ▶ | set_max() unless $flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 3 | my $c = []; | |||||||||||||||||||||||||||
| 400 | 3 | my $nc; | |||||||||||||||||||||||||||
| 401 | SWITCH: { | ||||||||||||||||||||||||||||
| 402 | 3 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 2 | $nc = ($na+1)*($nb+1); | |||||||||||||||||||||||||||
| 404 | 2 | my $cn = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 405 | 2 | my $cd = [split //, 0 x ($nc+1)]; | |||||||||||||||||||||||||||
| 406 | Math::Cephes::fpolsbt_wrap($bdata->{n}, $bdata->{d}, $nb, | ||||||||||||||||||||||||||||
| 407 | 2 | $adata->{n}, $adata->{d}, $na, | |||||||||||||||||||||||||||
| 408 | $cn, $cd, $nc); | ||||||||||||||||||||||||||||
| 409 | 2 | $nc = $na * $nb; | |||||||||||||||||||||||||||
| 410 | 2 | ▶ | for (my $i=0; $i<=$nc; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 6 | my ($gcd, $n, $d) = Math::Cephes::euclid($cn->[$i], $cd->[$i]); | |||||||||||||||||||||||||||
| 412 | 6 | ▶ | push @$c, ($aref eq 'Math::Fraction' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | Math::Fraction->new($n, $d) : | ||||||||||||||||||||||||||||
| 414 | Math::Cephes::Fraction->new($n, $d) ); | ||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | 2 | last SWITCH; | |||||||||||||||||||||||||||
| 417 | }; | ||||||||||||||||||||||||||||
| 418 | 1 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 0 | die "Cannot do complex substitution"; | |||||||||||||||||||||||||||
| 420 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 421 | }; | ||||||||||||||||||||||||||||
| 422 | 1 | $nc = ($na+1)*($nb+1); | |||||||||||||||||||||||||||
| 423 | 1 | $c = [split //, 0 x $nc]; | |||||||||||||||||||||||||||
| 424 | 1 | Math::Cephes::polsbt($bdata, $nb, $adata, $na, $c); | |||||||||||||||||||||||||||
| 425 | 1 | $nc = $na*$nb; | |||||||||||||||||||||||||||
| 426 | 1 | $c = [@$c[0..$nc]]; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | 3 | ▶ | return wantarray ? (Math::Cephes::Polynomial->new($c), $nc) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | Math::Cephes::Polynomial->new($c); | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 1 | ▶ | sub set_max { | ||||||||||||||||||||||||||
|
Subroutine
set_max: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 433 | 1 | Math::Cephes::polini($MAXPOL); | |||||||||||||||||||||||||||
| 434 | 1 | $flag = 1; | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 1 | ▶ | sub set_fmax { | ||||||||||||||||||||||||||
|
Subroutine
set_fmax: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 438 | 1 | Math::Cephes::fpolini($FMAXPOL); | |||||||||||||||||||||||||||
| 439 | 1 | $fflag = 1; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 10 | ▶ | sub eval { | ||||||||||||||||||||||||||
|
Subroutine
eval: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 443 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 444 | 10 | my $x = 0 || shift; | |||||||||||||||||||||||||||
| 445 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 446 | 10 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 447 | 10 | my $y; | |||||||||||||||||||||||||||
| 448 | SWITCH: { | ||||||||||||||||||||||||||||
| 449 | 10 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 4 | my $xref = ref($x); | |||||||||||||||||||||||||||
| 451 | 4 | $y = Math::Cephes::Fraction->new(0, 1); | |||||||||||||||||||||||||||
| 452 | FRACT: { | ||||||||||||||||||||||||||||
| 453 | 4 | ▶ | not $xref and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | 2 | $x = Math::Cephes::Fraction->new($x, 1); | |||||||||||||||||||||||||||
| 455 | 2 | last FRACT; | |||||||||||||||||||||||||||
| 456 | }; | ||||||||||||||||||||||||||||
| 457 | 2 | ▶ | $xref eq 'Math::Cephes::Fraction' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 2 | last FRACT; | |||||||||||||||||||||||||||
| 459 | }; | ||||||||||||||||||||||||||||
| 460 | 0 | ▶ | $xref eq 'Math::Fraction' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | 0 | $x = Math::Cephes::Fraction->new($x->{frac}->[0], $x->{frac}->[1]); | |||||||||||||||||||||||||||
| 462 | 0 | last FRACT; | |||||||||||||||||||||||||||
| 463 | }; | ||||||||||||||||||||||||||||
| 464 | 0 | die "Unknown data type '$xref' for x"; | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | 4 | Math::Cephes::fpoleva_wrap($adata->{n}, $adata->{d}, $na, $x, $y); | |||||||||||||||||||||||||||
| 467 | 4 | ▶ | $y = Math::Fraction->new($y->n, $y->d) if $aref eq 'Math::Fraction'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | 4 | last SWITCH; | |||||||||||||||||||||||||||
| 469 | }; | ||||||||||||||||||||||||||||
| 470 | 6 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 2 | my $r = Math::Cephes::poleva($adata->{r}, $na, $x); | |||||||||||||||||||||||||||
| 472 | 2 | my $i = Math::Cephes::poleva($adata->{i}, $na, $x); | |||||||||||||||||||||||||||
| 473 | 2 | ▶ | $y = $aref eq 'Math::Complex' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 474 | Math::Complex->make($r, $i) : | ||||||||||||||||||||||||||||
| 475 | Math::Cephes::Complex->new($r, $i); | ||||||||||||||||||||||||||||
| 476 | 2 | last SWITCH; | |||||||||||||||||||||||||||
| 477 | }; | ||||||||||||||||||||||||||||
| 478 | 4 | $y = Math::Cephes::poleva($adata, $na, $x); | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | 10 | return $y; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 9 | ▶ | sub fract_to_real { | ||||||||||||||||||||||||||
|
Subroutine
fract_to_real: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 484 | 9 | my $in = shift; | |||||||||||||||||||||||||||
| 485 | 9 | my $a = []; | |||||||||||||||||||||||||||
| 486 | 9 | my $n = scalar @{$in->{n}} - 1; | |||||||||||||||||||||||||||
| 487 | 9 | ▶ | for (my $i=0; $i<=$n; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | 39 | push @$a, $in->{n}->[$i] / $in->{d}->[$i]; | |||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | 9 | return $a; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 2 | ▶ | sub atn { | ||||||||||||||||||||||||||
|
Subroutine
atn: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 494 | 2 | my ($self, $bin) = @_; | |||||||||||||||||||||||||||
| 495 | 2 | my $type = $self->{type}; | |||||||||||||||||||||||||||
| 496 | 2 | ▶ | die "Cannot take the atan of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | if $type eq 'cmplx'; | ||||||||||||||||||||||||||||
| 498 | 2 | my ($a, $b); | |||||||||||||||||||||||||||
| 499 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 500 | 2 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 501 | 2 | ▶ | die "Cannot take the atan of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 502 | if $atype eq 'cmplx'; | ||||||||||||||||||||||||||||
| 503 | 2 | ▶ | $a = $atype eq 'fract' ? fract_to_real($adata) : $adata; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | my ($btype, $bref, $bdata, $nb) = | ||||||||||||||||||||||||||||
| 506 | ref($bin) eq 'Math::Cephes::Polynomial' ? | ||||||||||||||||||||||||||||
| 507 | 2 | ▶ | ($bin->{type}, $bin->{ref}, $bin->{data}, $bin->{n}) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | get_data($bin); | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 2 | ▶ | die "Cannot take the atan of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 511 | if $btype eq 'cmplx'; | ||||||||||||||||||||||||||||
| 512 | 2 | ▶ | $b = $btype eq 'fract' ? fract_to_real($bdata) : $bdata; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 2 | my $c = [split //, 0 x ($MAXPOL+1)]; | |||||||||||||||||||||||||||
| 515 | 2 | Math::Cephes::polatn($a, $b, $c, 16); | |||||||||||||||||||||||||||
| 516 | 2 | return Math::Cephes::Polynomial->new($c); | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 3 | ▶ | sub sqt { | ||||||||||||||||||||||||||
|
Subroutine
sqt: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 520 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 521 | 3 | my $type = $self->{type}; | |||||||||||||||||||||||||||
| 522 | 3 | ▶ | die "Cannot take the sqrt of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | if $type eq 'cmplx'; | ||||||||||||||||||||||||||||
| 524 | 3 | ▶ | my $a = $type eq 'fract' ? fract_to_real($self->{data}) : $self->coef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 525 | 3 | my $b = [split //, 0 x ($MAXPOL+1)]; | |||||||||||||||||||||||||||
| 526 | 3 | Math::Cephes::polsqt($a, $b, 16); | |||||||||||||||||||||||||||
| 527 | 3 | return Math::Cephes::Polynomial->new($b); | |||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 3 | ▶ | sub sin { | ||||||||||||||||||||||||||
|
Subroutine
sin: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 531 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 532 | 3 | my $type = $self->{type}; | |||||||||||||||||||||||||||
| 533 | 3 | ▶ | die "Cannot take the sin of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 534 | if $type eq 'cmplx'; | ||||||||||||||||||||||||||||
| 535 | 3 | ▶ | my $a = $type eq 'fract' ? fract_to_real($self->{data}) : $self->coef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 536 | 3 | my $b = [split //, 0 x ($MAXPOL+1)]; | |||||||||||||||||||||||||||
| 537 | 3 | Math::Cephes::polsin($a, $b, 16); | |||||||||||||||||||||||||||
| 538 | 3 | return Math::Cephes::Polynomial->new($b); | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 3 | ▶ | sub cos { | ||||||||||||||||||||||||||
|
Subroutine
cos: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 542 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 543 | 3 | my $type = $self->{type}; | |||||||||||||||||||||||||||
| 544 | 3 | ▶ | die "Cannot take the cos of a complex polynomial" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 545 | if $type eq 'cmplx'; | ||||||||||||||||||||||||||||
| 546 | 3 | ▶ | my $a = $type eq 'fract' ? fract_to_real($self->{data}) : $self->coef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 547 | 3 | my $b = [split //, 0 x ($MAXPOL+1)]; | |||||||||||||||||||||||||||
| 548 | 3 | Math::Cephes::polcos($a, $b, 16); | |||||||||||||||||||||||||||
| 549 | 3 | return Math::Cephes::Polynomial->new($b); | |||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 2 | ▶ | sub rts { | ||||||||||||||||||||||||||
|
Subroutine
rts: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 553 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 554 | my ($atype, $aref, $adata, $na) = | ||||||||||||||||||||||||||||
| 555 | 2 | ($self->{type}, $self->{ref}, $self->{data}, $self->{n}); | |||||||||||||||||||||||||||
| 556 | 2 | my ($a, $b, $ret); | |||||||||||||||||||||||||||
| 557 | 2 | my $cof = [split //, 0 x ($na+1)]; | |||||||||||||||||||||||||||
| 558 | 2 | my $r = [split //, 0 x ($na+1)]; | |||||||||||||||||||||||||||
| 559 | 2 | my $i = [split //, 0 x ($na+1)]; | |||||||||||||||||||||||||||
| 560 | SWITCH: { | ||||||||||||||||||||||||||||
| 561 | 2 | ▶ | $atype eq 'fract' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 562 | 1 | $adata = fract_to_real($adata); | |||||||||||||||||||||||||||
| 563 | 1 | $ret = Math::Cephes::polrt_wrap($adata, $cof, $na, $r, $i); | |||||||||||||||||||||||||||
| 564 | 1 | ▶ | for (my $j=0; $j<$na; $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | 6 | push @$b, | |||||||||||||||||||||||||||
| 566 | Math::Cephes::Complex->new($r->[$j], $i->[$j]); | ||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | 1 | last SWITCH; | |||||||||||||||||||||||||||
| 569 | }; | ||||||||||||||||||||||||||||
| 570 | 1 | ▶ | $atype eq 'cmplx' and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 571 | 0 | die "Cannot do complex root finding"; | |||||||||||||||||||||||||||
| 572 | 0 | last SWITCH; | |||||||||||||||||||||||||||
| 573 | }; | ||||||||||||||||||||||||||||
| 574 | 1 | $ret = Math::Cephes::polrt_wrap($adata, $cof, $na, $r, $i); | |||||||||||||||||||||||||||
| 575 | 1 | ▶ | for (my $j=0; $j<$na; $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | 4 | push @$b, | |||||||||||||||||||||||||||
| 577 | Math::Cephes::Complex->new($r->[$j], $i->[$j]); | ||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | 2 | ▶ | return wantarray ? ($ret, $b) : $b; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 1 | 1; | |||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | __END__ | ||||||||||||||||||||||||||||