NumSeq/Modulo.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 105 CC 2 SCAR 8.8
CC
2
Cov
0%
description
6.0
characteristic_integer
2.0
characteristic_modulus
2.0
CRAP 2.4
1 # Copyright 2011, 2012, 2013, 2014, 2016, 2017, 2018, 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 package Math::NumSeq::Modulo;
19 use 5.004;
20 use strict;
21  
22 use vars '$VERSION', '@ISA';
23 $VERSION = 75;
24  
25 use Math::NumSeq;
26 use Math::NumSeq::Base::IterateIth;
27 @ISA = ('Math::NumSeq::Base::IterateIth',
28 'Math::NumSeq');
29  
30 # uncomment this to run the ### lines
31 #use Smart::Comments;
32  
33 # use constant name => Math::NumSeq::__('Modulo');
34 sub description {
35 my ($self) = @_;
36 if (ref $self) {
37 return Math::NumSeq::__('Remainder modulo ') . $self->{'modulus'};
38 } else {
39 return Math::NumSeq::__('Remainder to a given modulus.');
40 }
41 }
42 use constant i_start => 0;
43  
44 use constant characteristic_smaller => 1;
45 use constant characteristic_increasing => 0;
46 sub characteristic_integer {
47 my ($self) = @_;
48 return _is_integer($self->{'modulus'});
49 }
50 sub characteristic_modulus {
51 my ($self) = @_;
52 return $self->{'modulus'};
53 }
54 sub _is_integer {
55 my ($n) = @_;
56 return ($n == int($n));
57 }
58  
59 use constant parameter_info_array =>
60 [ { name => 'modulus',
61 type => 'integer',
62 display => Math::NumSeq::__('Modulus'),
63 default => 13,
64 minimum => 1,
65 width => 3,
66 description => Math::NumSeq::__('Modulus.'),
67 } ];
68  
69 use constant values_min => 0;
70 sub values_max {
71 my ($self) = @_;
72 return abs($self->{'modulus'}) - 1;
73 }
74  
75 {
76 my @oeis_anum = (
77 # OEIS-Catalogue array begin
78 undef, # 0
79 undef, # 1
80 'A000035', # modulus=2 # 0,1,0,1,0,1,etc
81 'A010872', # modulus=3
82 'A010873', # modulus=4
83 'A010874', # modulus=5
84 'A010875', # modulus=6
85 'A010876', # modulus=7
86 'A010877', # modulus=8
87 'A010878', # modulus=9
88 'A010879', # modulus=10
89 'A010880', # modulus=11
90 'A010881', # modulus=12
91 undef, # 13
92 'A070696', # modulus=14
93 'A167463', # modulus=15
94 'A130909', # modulus=16
95  
96 # OEIS-Catalogue array end
97 );
98 $oeis_anum[1] = 'A000004'; # mod 1, 0,0,0,0,etc all zeros
99 # OEIS-Other: A000004 modulus=1
100  
101 sub _modulus_to_anum {
102 my ($modulus) = @_;
103 return ($modulus == int($modulus)
104 && $modulus > 0
105 && $oeis_anum[$modulus]);
106 }
107 }
108  
109 sub oeis_anum {
110 my ($self) = @_;
111 return _modulus_to_anum($self->{'modulus'});
112 }
113  
114 sub ith {
115 my ($self, $i) = @_;
116 ### Modulo ith(): "$i"
117 return $i % $self->{'modulus'};
118 }
119  
120 sub pred {
121 my ($self, $value) = @_;
122 return ($value >= 0
123 && $value < $self->{'modulus'}
124 && $value == int($value));
125 }
126  
127 1;
128 __END__