NumSeq/DigitProduct.pm

filter: Statementstmt 95.7% 67 / 70 Branchbran 75.0% 9 / 12 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 95.0% 19 / 20 Podpod 100% 4 / 4 totaltotal 90.8% 109 / 120 CC 10 SCAR 11.0
CC
10
Cov
91%
pred
7.0
values_max
6.0
ith
3.1
CRAP 3.0
« NumSeq/AllPrimeFactors.pm ↑ Summary NumSeq/Palindromes.pm »
1 # Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Math::NumSeq::DigitProduct;
20 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use List::Util 'reduce';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 $VERSION = 75;
26  
27 2 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use Math::NumSeq::Base::IterateIth;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 @ISA = ('Math::NumSeq::Base::IterateIth',
30 'Math::NumSeq');
31 2 *_is_infinite = \&Math::NumSeq::_is_infinite;
32  
33 2 ▶use Math::NumSeq::Repdigits;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 *_digit_split_lowtohigh = \&Math::NumSeq::Repdigits::_digit_split_lowtohigh;
35  
36  
37 2 ▶use constant name => Math::NumSeq::__('Digit Product');
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use constant description => Math::NumSeq::__('Product of digits a given radix.');
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use constant i_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use constant characteristic_smaller => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use constant characteristic_integer => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 use Math::NumSeq::Base::Digits
45 2 ▶ 'parameter_info_array'; # radix parameter
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 0 ▶sub values_max {
Subroutine values_max: not called CC=2 SCAR=17.9
Pod documented
49 0 my ($self) = @_;
50 0 ▶ return ($self->{'radix'} == 2 ? 1 : undef);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'radix'} == 2 ? : 0 0 0
51 }
52  
53 #------------------------------------------------------------------------------
54 # apparently no ternary or base 4 ...
55  
56 2 my @oeis_anum;
57 # A036987 binary, being 0 if any 0-bits and 1 if all 1-bits,
58 # but it takes i=0 to be an empty product value=1
59  
60 2 $oeis_anum[10] = 'A007954'; # 10 decimal, starting from 0
61 # OEIS-Catalogue: A007954 radix=10
62  
63 2 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=1 SCAR=0.0
Pod documented
64 2 my ($self) = @_;
65 2 return $oeis_anum[$self->{'radix'}];
66 }
67  
68 #------------------------------------------------------------------------------
69  
70 588 ▶sub ith {
Subroutine ith: called CC=3 SCAR=11.2
Pod documented
71 588 my ($self, $i) = @_;
72  
73 588 ▶ if (_is_infinite ($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 588 588
74 0 return $i;
75 }
76 588 ▶ if ($i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 10 578 588
77 10 return 0;
78 }
79 578 ▶ return reduce {$a * $b} _digit_split_lowtohigh($i, $self->{'radix'})
Subroutine __ANON__: called CC=1 SCAR=0.0
80 }
81  
82 59 ▶sub pred {
Subroutine pred: called CC=7 SCAR=19.5
Pod documented
83 59 my ($self, $value) = @_;
84 59 ▶ if (_is_infinite ($value)
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($value) or $value < 0 or $value != int $value) 3 56 59
Condition66%4/6
_is_infinite($value) or $value < 0 or $value != int $value
l!l&&r!l&&!r
3056
_is_infinite($value) or $value < 0
l!l&&r!l&&!r
0356
MC/DC33%1/3
_is_infinite($value) or $value < 0 or $value != int $value
_is_infinite($value) $value < 0 $value != int $value
Truth table50%2/4
A or B or C
A= _is_infinite($value)B= $value < 0C= $value != int $value
ABCresult
1XX1
01X1
0011
0000
85 || $value < 0
86 || $value != int($value)) {
87 3 return 0;
88 }
89 56 my $radix = $self->{'radix'};
90 56 ▶ for (my $i = 2; $i < $radix && $value > 1; $i+=1+($i!=2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $radix and $value > 1) 33 56 89
Condition100%3/3
$i < $radix and $value > 1
!ll&&!rl&&r
312533
MC/DC100%2/2
$i < $radix and $value > 1
$i < $radix $value > 1
Truth table100%3/3
A and B
A= $i < $radixB= $value > 1
ABresult
0X0
100
111
91 33 ▶ until ($value % $i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value % $i) 36 33 69
92 36 $value = int($value/$i);
93 }
94 }
95 56 return ($value <= 1); # remainder
96 }
97  
98 2 1;
99 __END__
« NumSeq/AllPrimeFactors.pm ↑ Summary NumSeq/Palindromes.pm »