1Math::NumSeq::FractionDUisgeirtsC(o3n)tributed Perl DocuMmaetnht:a:tNiuomnSeq::FractionDigits(3)
2
3
4
6 Math::NumSeq::FractionDigits -- the digits of a fraction p/q
7
9 use Math::NumSeq::FractionDigits;
10 my $seq = Math::NumSeq::FractionDigits->new (fraction => '2/11');
11 my ($i, $value) = $seq->next;
12
14 The sequence of digits which are a given fraction. For example 1/7 in
15 decimal, being 0.14285714...
16
17 1, 4, 2, 8, 5, 7, 1, 4, etc
18
19 After any integer part, the fraction digits are a repeating sequence.
20 If the fraction is num/den and is in least terms (num and den have no
21 common factor) then the period is either den-1 or some divisor of
22 den-1.
23
24 A particular a repeating sequence a,b,c,d,a,b,c,d,etc can be cooked up
25 with fraction abcd/9999, the denominator being as many 9s as digits to
26 repeat. For a base other than decimal the "9" is radix-1.
27
29 See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
30 classes.
31
32 "$seq = Math::NumSeq::FractionDigits->new (fraction => $f)"
33 "$seq = Math::NumSeq::FractionDigits->new (fraction => $f, radix =>
34 $r)"
35 Create and return a new sequence object giving the digits of $f.
36 $f is a string "num/den", or a decimal "xx.yy",
37
38 2/29
39 29.125
40 1.5/3.25
41
42 The default sequence values are decimal digits, or the "radix"
43 parameter can select another base. (But the "fraction" parameter
44 is still decimal.)
45
46 If the numerator or denominator of the fraction is bigger than fits
47 Perl integer calculations then "Math::BigInt" is used
48 automatically.
49
50 Random Access
51 "$value = $seq->ith($i)"
52 Return the $i'th digit of the fraction.
53
55 Next
56 For a given num/den, with num < den, the next digit below the radix
57 point is formed by
58
59 num *= radix # now 0 <= num/den < radix
60 quot,rem = num divide den
61 digit = quot # 0 <= digit < radix
62 new num = rem
63
64 Ith
65 For an arbitrary digit i, the repeated num*=radix can be applied by a
66 modular powering
67
68 rpower = radix^i mod den
69 num = num * rpower mod den
70
71 i here acts as a count of how many digits to skip. For example if i=0
72 then rpower=1 and doesn't change the numerator at all. With that big
73 skip the digit is then the same as for "next" above,
74
75 num *= radix # now 0 <= num/den < radix
76 digit = floor(num/den) # 0 <= digit < radix
77
78 The usual modular powering techniques can be applied to calculate
79 radix^i mod den. "Math::BigInt" has a bmodpow which is used in the
80 code if the inputs are big.
81
83 Math::NumSeq, Math::NumSeq::SqrtDigits
84
86 <http://user42.tuxfamily.org/math-numseq/index.html>
87
89 Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019 Kevin Ryde
90
91 Math-NumSeq is free software; you can redistribute it and/or modify it
92 under the terms of the GNU General Public License as published by the
93 Free Software Foundation; either version 3, or (at your option) any
94 later version.
95
96 Math-NumSeq is distributed in the hope that it will be useful, but
97 WITHOUT ANY WARRANTY; without even the implied warranty of
98 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99 General Public License for more details.
100
101 You should have received a copy of the GNU General Public License along
102 with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
103
104
105
106perl v5.32.0 2020-07-28 Math::NumSeq::FractionDigits(3)