1Math::PlanePath::Base::UDsiegritCso(n3t)ributed Perl DocMuamtehn:t:aPtliaonnePath::Base::Digits(3)
2
3
4
6 Math::PlanePath::Base::Digits -- helpers for digit based paths
7
9 use Math::PlanePath::Base::Digits 'digit_split_lowtohigh';
10 foreach my $digit (digit_split_lowtohigh ($n, 16)) {
11 }
12
14 This is a few generic helper functions for paths based on digits or
15 powering.
16
17 They're designed to work on plain Perl integers and floats and there's
18 some special case support for "Math::BigInt".
19
21 Nothing is exported by default but each function below can be as in the
22 usual Exporter style,
23
24 use Math::PlanePath::Base::Digits 'round_down_pow';
25
26 (But not "parameter_info_radix2()", for the reason described below.)
27
29 Generic
30 "($power, $exponent) = round_up_pow ($n, $radix)"
31 "($power, $exponent) = round_down_pow ($n, $radix)"
32 Return the power of $radix equal to or either higher or lower than
33 $n. For example
34
35 ($pow, $exp) = round_down_pow (260, 2);
36 # $pow==512 # the next higher power
37 # $exp==9 # the exponent in that power
38 # 2**9=512 is next above 260
39
40 ($pow, $exp) = round_down_pow (260, 2);
41 # $pow==256 # the next lower power
42 # $exp==8 # the exponent in that power
43 # 2**8=256 is next below 260
44
45 "@digits = digit_split_lowtohigh ($n, $radix)"
46 "@bits = bit_split_lowtohigh ($n)"
47 Return a list of digits from $n in base $radix, or in binary. For
48 example,
49
50 @digits = digit_split_lowtohigh (12345, 10);
51 # @digits = (5,4,3,2,1) # decimal digits low to high
52
53 If "$n==0" then the return is an empty list. The current code
54 expects "$n >= 0".
55
56 "lowtohigh" in the name tries to make it clear which way the digits
57 are returned. "reverse()" can be used to get high to low instead
58 (see "reverse" in perlfunc).
59
60 "bit_split_lowtohigh()" is the same as "digit_split_lowtohigh()"
61 called with radix=2.
62
63 "$n = digit_join_lowtohigh ($arrayref, $radix)"
64 "$n = digit_join_lowtohigh ($arrayref, $radix, $zero)"
65 Return a value made by joining digits from $arrayref in base
66 $radix. For example,
67
68 @digits = (5,4,3,2,1) # decimal digits low to high
69 $n = digit_split_lowtohigh (\@digits, 10);
70 # $n == 12345
71
72 Optional $zero can be a 0 of an overloaded number type such as
73 "Math::BigInt" to give a returned $n of that type.
74
75 Subclassing
76 "$aref = parameter_info_array()"
77 Return an arrayref of a "radix" parameter, default 2. This is
78 designed to be imported into a PlanePath subclass as its
79 "parameter_info_array()" method.
80
81 package Math::PlanePath::MySubclass;
82 use Math::PlanePath::Base::Digits 'parameter_info_array';
83
84 The arrayref is
85
86 [ { name => 'radix',
87 share_key => 'radix_2',
88 display => 'Radix',
89 type => 'integer',
90 minimum => 2,
91 default => 2,
92 width => 3,
93 description => 'Radix (number base).',
94 }
95 ]
96
97 "$href = Math::PlanePath::Base::Digits::parameter_info_radix2()"
98 Return the single "radix" parameter hashref from the info above.
99 This can be used when a subclass wants the radix parameter and
100 other parameters too,
101
102 package Math::PlanePath::MySubclass;
103 use constant parameter_info_array =>
104 [
105 { name => 'something_else',
106 type => 'integer',
107 default => '123',
108 },
109 Math::PlanePath::Base::Digits::parameter_info_radix2(),
110 ];
111
112 If the "description" part should be more specific or more detailed
113 then it could be overridden with for example
114
115 { %{Math::PlanePath::Base::Digits::parameter_info_radix2()},
116 description => 'Radix, for both something and something.',
117 },
118
119 This function is not exportable since it's meant for a one-off call
120 in an initializer and so no need to import it for repeated use.
121
123 Math::PlanePath, Math::PlanePath::Base::Generic
124
125 Math::BigInt
126
128 <http://user42.tuxfamily.org/math-planepath/index.html>
129
131 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Kevin Ryde
132
133 This file is part of Math-PlanePath.
134
135 Math-PlanePath is free software; you can redistribute it and/or modify
136 it under the terms of the GNU General Public License as published by
137 the Free Software Foundation; either version 3, or (at your option) any
138 later version.
139
140 Math-PlanePath is distributed in the hope that it will be useful, but
141 WITHOUT ANY WARRANTY; without even the implied warranty of
142 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
143 General Public License for more details.
144
145 You should have received a copy of the GNU General Public License along
146 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
147
148
149
150perl v5.28.0 2017-12-03 Math::PlanePath::Base::Digits(3)