Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
17970 | bpr | 1 | !if $wims_read_parm!=slib_header |
2 | !goto proc |
||
3 | !endif |
||
4 | slib_author=Bernadette, Perrin-Riou |
||
5 | |||
6 | slib_title=Repeating decimal of a rational |
||
7 | slib_parms=2\ |
||
8 | ,rational number\ |
||
9 | raw,format |
||
10 | slib_out=return [length of the non-periodic decimal part, length of the periodic pattern],\ |
||
11 | [integral part , non-periodic part, periodic pattern] in default format.\ |
||
12 | If the option is <span class="tt">tex</span> the second item is the formatted number\ |
||
13 | with overlined periodic pattern. |
||
14 | !set slib_example=34/45,tex\ |
||
15 | 34/45\ |
||
16 | 297/670\ |
||
17 | 453/37,tex\ |
||
18 | 453/37\ |
||
19 | 65/12,tex\ |
||
20 | 65/12 |
||
21 | |||
22 | !exit |
||
23 | |||
24 | :proc |
||
25 | |||
26 | !!borner le dénominateur |
||
27 | !reset slib_format slib_out |
||
28 | !distribute item $wims_read_parm into slib_n,slib_format |
||
29 | !default slib_format=raw |
||
30 | slib_res=!exec pari algo(x)={my(b,r,s);b=denominator(x);r=valuation(b,2);s=valuation(b,5);\ |
||
31 | [max(r,s),znorder(Mod(10,b/2^r/5^s)),x*1.]};\ |
||
32 | algo($slib_n) |
||
33 | slib_res=!nospace $slib_res |
||
34 | slib_rn=$(slib_res[3]) |
||
35 | slib_rn=!replace internal . by , in $slib_rn |
||
36 | slib_test=!charcnt $(slib_rn[2]) |
||
37 | !if $(slib_res[2]) > $slib_test-1 |
||
38 | slib_out=!nospace [$(slib_res[1,2])] |
||
39 | !exit |
||
40 | !endif |
||
41 | slib_per=!char $(slib_res[1])+1 to $(slib_res[1])+$(slib_res[2]) of $(slib_rn[2]) |
||
42 | !reset slib_beg |
||
43 | !if $(slib_res[1])>0 |
||
44 | slib_beg=!char 1 to $(slib_res[1]) of $(slib_rn[2]) |
||
45 | !endif |
||
46 | !if $slib_format=tex |
||
47 | slib_out=[$(slib_res[1,2])],\($(slib_rn[1]).$slib_beg\overline{$slib_per}\) |
||
48 | !else |
||
49 | slib_out=[$(slib_res[1,2])],[$(slib_rn[1]),$slib_beg,$slib_per] |
||
50 | !endif |