blib/lib/Math/Cephes/Fraction.pm

filter: Statementstmt 63.5% 75 / 118 Branchbran 41.1% 14 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 14 / 18 Podpod 0.0% 0 / 14 totaltotal 55.9% 103 / 184 CC 18 SCAR 21.4
CC
18
Cov
59%
as_mixed_string
30.0
as_string
20.0
mixed_fract
5.5
CRAP 8.5
« blib/lib/Math/Cephes/Polynomial.pm ↑ Summary blib/lib/Math/Cephes.pm »
1 ############# Class : fract ##############
2 package Math::Cephes::Fraction;
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw(%OWNER @ISA %ITERATORS
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 @EXPORT_OK %EXPORT_TAGS $VERSION);
7  
8 2 require Exporter;
9 2 *import = \&Exporter::import;
10 #my @fract = qw(radd rsub rmul rdiv euclid fract mixed_fract);
11 2 my @fract = qw(euclid fract mixed_fract);
12 2 @EXPORT_OK = (@fract);
13 2 %EXPORT_TAGS = ('fract' => [@fract]);
14  
15 2 $VERSION = '0.5308';
16 #use Math::Cephes qw(new_fract euclid);
17 2 require Math::Cephes;
18 2 @ISA = qw( Math::Cephes );
19  
20 2 %OWNER = ();
21 2 %ITERATORS = ();
22  
23 2 *swig_n_get = *Math::Cephesc::fract_n_get;
24 2 *swig_n_set = *Math::Cephesc::fract_n_set;
25 2 *swig_d_get = *Math::Cephesc::fract_d_get;
26 2 *swig_d_set = *Math::Cephesc::fract_d_set;
27 47 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
28 47 my $pkg = shift;
29 47 my $self = Math::Cephesc::new_fract(@_);
30 47 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 47 0 47
31 }
32  
33 94 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=14.0
34 94 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 47 47 94
35 47 my $self = tied(%{$_[0]});
36 47 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 47 47
37 47 delete $ITERATORS{$self};
38 47 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Math::Cephes::Fraction::OWNER{$self}) 47 0 47
39 47 Math::Cephesc::delete_fract($self);
40 47 delete $OWNER{$self};
41 }
42 }
43  
44 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my $self = shift;
46 0 my $ptr = tied(%$self);
47 0 delete $OWNER{$ptr};
48 }
49  
50 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my $self = shift;
52 0 my $ptr = tied(%$self);
53 0 $OWNER{$ptr} = 1;
54 }
55  
56  
57 2 ▶sub fract {
Subroutine fract: called CC=1 SCAR=0.0
Pod undocumented
58 2 return Math::Cephes::Fraction->new(@_);
59 }
60  
61 45 ▶sub n {
Subroutine n: called CC=2 SCAR=6.9
Pod undocumented
62 45 my ($self, $value) = @_;
63 45 ▶ return $self->{n} unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 43 2 45
64 2 $self->{n} = $value;
65 2 return $value;
66 }
67  
68 45 ▶sub d {
Subroutine d: called CC=2 SCAR=6.9
Pod undocumented
69 45 my ($self, $value) = @_;
70 45 ▶ return $self->{d} unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 43 2 45
71 2 $self->{d} = $value;
72 2 return $value;
73 }
74  
75 3 ▶sub euclid {
Subroutine euclid: called CC=1 SCAR=0.0
Pod undocumented
76 3 return Math::Cephes::euclid($_[0], $_[1]);
77 }
78  
79  
80 2 ▶sub mixed_fract {
Subroutine mixed_fract: called CC=5 SCAR=17.0
Pod undocumented
81 2 my $f = shift;
82 2 my $nin = int($f->{n});
83 2 my $din = int($f->{d});
84 2 my $gcd;
85 2 ▶ if ($din < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($din < 0) 0 2 2
86 0 $din *= -1;
87 0 $nin *= -1;
88 }
89 2 ▶ if (abs($nin) < abs($din)) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $nin < abs $din) { } 1 1 2
90 1 ▶ if ( $nin == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nin == 0) { } 0 1 1
91 0 return (0, 0, 0);
92 }
93 else {
94 1 ($gcd, $nin, $din) = euclid($nin, $din);
95 1 return (0, $nin, $din);
96 }
97 }
98 else {
99 1 my $n = abs($nin) % $din;
100 1 my $w = int($nin / $din);
101 1 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) { } 0 1 1
102 0 return ($w, 0, 1);
103 }
104 else {
105 1 ($gcd, $n, $din) = euclid($n, $din);
106 1 return ($w, $n, $din);
107 }
108 }
109 }
110  
111 0 ▶sub as_string {
Subroutine as_string: not called CC=4 SCAR=30.0
Pod undocumented
112 0 my $f = shift;
113 0 my ($gcd, $string);
114 0 my $num = int($f->{n});
115 0 my $den = int($f->{d});
116 0 ▶ if ( abs($num % $den) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (abs $num % $den == 0) { } 0 0 0
elsif ($num == 0) { } 0 0 0
117 0 my $w = $num / $den;
118 0 $string = "$w";
119 }
120 elsif ($num == 0) {
121 0 $string = '0';
122 }
123 else {
124 0 ▶ if ($den < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($den < 0) 0 0 0
125 0 $num *= -1;
126 0 $den *= -1;
127 }
128 0 ($gcd, $num, $den) = euclid($num, $den);
129 0 $string = "$num/$den";
130 }
131 0 return $string;
132 }
133  
134 0 ▶sub as_mixed_string {
Subroutine as_mixed_string: not called CC=5 SCAR=34.0
Pod undocumented
135 0 my $f = shift;
136 0 my ($gcd, $string);
137 0 my $num = int($f->{n});
138 0 my $den = int($f->{d});
139 0 ▶ if ($den < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($den < 0) 0 0 0
140 0 $den *= -1;
141 0 $num *= -1;
142 }
143 0 ▶ if (abs($num) < abs($den)) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $num < abs $den) { } 0 0 0
144 0 ▶ if ( $num == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 0) { } 0 0 0
145 0 $string = '0';
146 }
147 else {
148 0 ($gcd, $num, $den) = euclid($num, $den);
149 0 $string = "$num/$den";
150 }
151 }
152 else {
153 0 my $n = abs($num) % $den;
154 0 my $w = int($num / $den);
155 0 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) { } 0 0 0
156 0 $string = "$w";
157 }
158 else {
159 0 ($gcd, $num, $den) = euclid($num, $den);
160 0 $string = "$w $n/$den";
161 }
162 }
163 0 return $string;
164 }
165  
166  
167 1 ▶sub radd {
Subroutine radd: called CC=1 SCAR=0.0
Pod undocumented
168 1 my ($f1, $f2) = @_;
169 1 my $f = Math::Cephes::Fraction->new();
170 1 Math::Cephes::radd($f1, $f2, $f);
171 1 return $f;
172 }
173  
174 1 ▶sub rsub {
Subroutine rsub: called CC=1 SCAR=0.0
Pod undocumented
175 1 my ($f1, $f2) = @_;
176 1 my $f = Math::Cephes::Fraction->new();
177 1 Math::Cephes::rsub($f2, $f1, $f);
178 1 return $f;
179 }
180  
181 1 ▶sub rmul {
Subroutine rmul: called CC=1 SCAR=0.0
Pod undocumented
182 1 my ($f1, $f2) = @_;
183 1 my $f = Math::Cephes::Fraction->new();
184 1 Math::Cephes::rmul($f1, $f2, $f);
185 1 return $f;
186 }
187  
188 1 ▶sub rdiv {
Subroutine rdiv: called CC=1 SCAR=0.0
Pod undocumented
189 1 my ($f1, $f2) = @_;
190 1 my $f = Math::Cephes::Fraction->new();
191 1 Math::Cephes::rdiv($f2, $f1, $f);
192 1 return $f;
193 }
194  
195 2 1;
196  
197 __END__
« blib/lib/Math/Cephes/Polynomial.pm ↑ Summary blib/lib/Math/Cephes.pm »