Subversion Repositories wimsdev

Rev

Rev 17970 | Details | Compare with Previous | 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\
17971 bpr 8
,rational number as a fraction of integer numbers\
17970 bpr 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.
17971 bpr 14
!set slib_comment=do not check if the rational number is written as a \
15
  fraction of integer numbers.
17970 bpr 16
!set slib_example=34/45,tex\
17
34/45\
18
297/670\
19
453/37,tex\
20
453/37\
21
65/12,tex\
17971 bpr 22
65/12\
23
67/66,tex\
24
67/66
17970 bpr 25
 
26
!exit
27
 
28
:proc
29
 
30
!!borner le dénominateur
31
!reset slib_format slib_out
32
!distribute item $wims_read_parm into slib_n,slib_format
33
!default slib_format=raw
34
slib_res=!exec pari algo(x)={my(b,r,s);b=denominator(x);r=valuation(b,2);s=valuation(b,5);\
35
  [max(r,s),znorder(Mod(10,b/2^r/5^s)),x*1.]};\
36
  algo($slib_n)
37
slib_res=!nospace $slib_res
38
slib_rn=$(slib_res[3])
39
slib_rn=!replace internal . by , in $slib_rn
40
slib_test=!charcnt $(slib_rn[2])
41
!if $(slib_res[2]) > $slib_test-1
42
  slib_out=!nospace [$(slib_res[1,2])]
43
  !exit
44
!endif
45
slib_per=!char $(slib_res[1])+1 to $(slib_res[1])+$(slib_res[2]) of $(slib_rn[2])
46
!reset slib_beg
47
!if $(slib_res[1])>0
48
  slib_beg=!char 1 to $(slib_res[1]) of $(slib_rn[2])
49
!endif
50
!if $slib_format=tex
51
  slib_out=[$(slib_res[1,2])],\($(slib_rn[1]).$slib_beg\overline{$slib_per}\)
52
!else
53
  slib_out=[$(slib_res[1,2])],[$(slib_rn[1]),$slib_beg,$slib_per]
54
!endif