Home » Personal collection » Acorn ADFS disks » Electron_User_Group » EUG_29.ADF » P/Dec-Frac
P/Dec-Frac
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Personal collection » Acorn ADFS disks » Electron_User_Group » EUG_29.ADF |
Filename: | P/Dec-Frac |
Read OK: | ✔ |
File size: | 04C2 bytes |
Load address: | FFFF1D00 |
Exec address: | FFFF8023 |
Duplicates
There are 2 duplicate copies of this file in the archive:
- AEW website » eug » eug_3_5_discs_Eug-29_A-EUG29.adf » U/DECFRAC
- AEW website » eug » eug_5_25_discs_Eug-29_D-EUG29.dsd » U.DECFRAC
- Personal collection » Acorn ADFS disks » Electron_User_Group » EUG_29.ADF » P/Dec-Frac
File contents
10REM >Dec-Frac 20@%=&A0A:mxiv=2^31:mxri=2^32:mxrv=(mxri-1)/(2*mxri)*2^32^3*2^32 30REPEATINPUTLINE"Enter a number:"x$:x=EVALx$:x%=SGNx:x=ABSx 40zl=0:zv=1:zr=2:z%=(ABSx<1ANDx<>0):REPEATzl=zl*2+1:zv=zv*2:zr=zr*2-1 50IFz%THENt=SGNx*zl:b=FNint(t/x):IFx<>t/b THENt=SGNx*zv:b=FNint(t/x):IFx<>t/b THENt=SGNx*zr:b=FNint(t/x) 60IFNOTz%THENb=zl:t=FNint(b*x):IFx<>t/b THENb=zv:t=FNint(b*x):IFx<>t/b THENb=zr:t=FNint(b*x) 70UNTILSGN(x-t/b)=0:t0=1:b0=0:t1=FNint(x):b1=1:IFb<ABSt THENzl=b:zr=t-t1*b:ELSEzl=t:zr=b 80IFABSb>=mxri ANDABSx<1/mxri ORb=1THENGOTO140 90REPEATj=FNint(zl/zr):zv=zl-j*zr:z%=FNcsgn(1,j,x):IFz%<>0ANDj>=1THENPROCupcf(1,j)ELSEIFj<1THENz%=1 100zl=zr:zr=zv:UNTILzv=0ORz%=0:IFj<1THENGOTO140ELSEz%=-FNcsgn(0,1,x):i=0 110REPEATi=i*2+1:UNTILz%<>FNcsgn(1,i,x)ORi>=j:j=2*FNint(i/mxri):i=i/2+(j-(j=0))/2:j=0 120REPEATIFz%=FNcsgn(1,j+i,x)THENj=j+i 130i=i/2:UNTILi=.5ORj+i*2=j:IFFNcsgn(1,j+i*2,x)=0THENPROCupcf(1,j+i*2)ELSEPROCupcf(1,j) 140IFFNcsgn(0,1,x)=0THENt=FNctop(0,1):b=FNcbot(0,1) 150x=x*x%:t=t*x% 160PRINTx" = ";t"/";b" ";x-t/b 170UNTILFALSE 180END 190DEFFNfrac(x)IFABSx>=mxri THEN=0ELSEIFABSx<mxiv THEN=x-INTx:ELSELOCALy:y=mxiv:IFABSx>=y THENREPEATy=y*mxiv:UNTILABSx<y 200REPEATy=y/mxiv:x=x-INT(x/y)*y:UNTILy=1:=x 210DEFFNint(x)=x-FNfrac(x) 220DEFFNctop(i,j)=i*t0+j*t1 230DEFFNcbot(i,j)=i*b0+j*b1 240DEFFNcfrc(i,j)LOCALt,b:t=FNctop(i,j):b=FNcbot(i,j):IFb=0THEN=mxrv*SGNt:ELSE=t/b 250DEFFNcsgn(i,j,x)=SGN(x-FNcfrc(i,j)) 260DEFPROCupcf(i,j)LOCALt,b:t=FNctop(i,j):b=FNcbot(i,j):t0=t1:t1=t:b0=b1:b1=b:ENDPROC
� >Dec-Frac B@%=&A0A:mxiv=2^31:mxri=2^32:mxrv=(mxri-1)/(2*mxri)*2^32^3*2^32 +��"Enter a number:"x$:x=�x$:x%=�x:x=�x (>zl=0:zv=1:zr=2:z%=(�x<1�x<>0):�zl=zl*2+1:zv=zv*2:zr=zr*2-1 2U�z%�t=�x*zl:b=�int(t/x):�x<>t/b �t=�x*zv:b=�int(t/x):�x<>t/b �t=�x*zr:b=�int(t/x) <M�z%�b=zl:t=�int(b*x):�x<>t/b �b=zv:t=�int(b*x):�x<>t/b �b=zr:t=�int(b*x) FJ��(x-t/b)=0:t0=1:b0=0:t1=�int(x):b1=1:�b<�t �zl=b:zr=t-t1*b:�zl=t:zr=b P#�b>=mxri ��x<1/mxri �b=1��tL@ ZN�j=�int(zl/zr):zv=zl-j*zr:z%=�csgn(1,j,x):�z%<>0�j>=1��upcf(1,j)��j<1�z%=1 d:zl=zr:zr=zv:�zv=0�z%=0:�j<1��tL@�z%=-�csgn(0,1,x):i=0 nJ�i=i*2+1:�z%<>�csgn(1,i,x)�i>=j:j=2*�int(i/mxri):i=i/2+(j-(j=0))/2:j=0 x��z%=�csgn(1,j+i,x)�j=j+i �Ei=i/2:�i=.5�j+i*2=j:�csgn(1,j+i*2,x)=0��upcf(1,j+i*2)��upcf(1,j) �-�csgn(0,1,x)=0�t=�ctop(0,1):b=�cbot(0,1) �x=x*x%:t=t*x% ��x" = ";t"/";b" ";x-t/b ��� �� �Mݤfrac(x)�x>=mxri �=0��x<mxiv �=x-�x:��y:y=mxiv:�x>=y ��y=y*mxiv:��x<y �"�y=y/mxiv:x=x-�(x/y)*y:�y=1:=x �ݤint(x)=x-�frac(x) �ݤctop(i,j)=i*t0+j*t1 �ݤcbot(i,j)=i*b0+j*b1 �Aݤcfrc(i,j)�t,b:t=�ctop(i,j):b=�cbot(i,j):�b=0�=mxrv*�t:�=t/b �!ݤcsgn(i,j,x)=�(x-�cfrc(i,j)) E��upcf(i,j)�t,b:t=�ctop(i,j):b=�cbot(i,j):t0=t1:t1=t:b0=b1:b1=b:� �
00000000 0d 00 0a 0f f4 20 3e 44 65 63 2d 46 72 61 63 0d |..... >Dec-Frac.| 00000010 00 14 42 40 25 3d 26 41 30 41 3a 6d 78 69 76 3d |..B@%=&A0A:mxiv=| 00000020 32 5e 33 31 3a 6d 78 72 69 3d 32 5e 33 32 3a 6d |2^31:mxri=2^32:m| 00000030 78 72 76 3d 28 6d 78 72 69 2d 31 29 2f 28 32 2a |xrv=(mxri-1)/(2*| 00000040 6d 78 72 69 29 2a 32 5e 33 32 5e 33 2a 32 5e 33 |mxri)*2^32^3*2^3| 00000050 32 0d 00 1e 2b f5 e8 86 22 45 6e 74 65 72 20 61 |2...+..."Enter a| 00000060 20 6e 75 6d 62 65 72 3a 22 78 24 3a 78 3d a0 78 | number:"x$:x=.x| 00000070 24 3a 78 25 3d b4 78 3a 78 3d 94 78 0d 00 28 3e |$:x%=.x:x=.x..(>| 00000080 7a 6c 3d 30 3a 7a 76 3d 31 3a 7a 72 3d 32 3a 7a |zl=0:zv=1:zr=2:z| 00000090 25 3d 28 94 78 3c 31 80 78 3c 3e 30 29 3a f5 7a |%=(.x<1.x<>0):.z| 000000a0 6c 3d 7a 6c 2a 32 2b 31 3a 7a 76 3d 7a 76 2a 32 |l=zl*2+1:zv=zv*2| 000000b0 3a 7a 72 3d 7a 72 2a 32 2d 31 0d 00 32 55 e7 7a |:zr=zr*2-1..2U.z| 000000c0 25 8c 74 3d b4 78 2a 7a 6c 3a 62 3d a4 69 6e 74 |%.t=.x*zl:b=.int| 000000d0 28 74 2f 78 29 3a e7 78 3c 3e 74 2f 62 20 8c 74 |(t/x):.x<>t/b .t| 000000e0 3d b4 78 2a 7a 76 3a 62 3d a4 69 6e 74 28 74 2f |=.x*zv:b=.int(t/| 000000f0 78 29 3a e7 78 3c 3e 74 2f 62 20 8c 74 3d b4 78 |x):.x<>t/b .t=.x| 00000100 2a 7a 72 3a 62 3d a4 69 6e 74 28 74 2f 78 29 0d |*zr:b=.int(t/x).| 00000110 00 3c 4d e7 ac 7a 25 8c 62 3d 7a 6c 3a 74 3d a4 |.<M..z%.b=zl:t=.| 00000120 69 6e 74 28 62 2a 78 29 3a e7 78 3c 3e 74 2f 62 |int(b*x):.x<>t/b| 00000130 20 8c 62 3d 7a 76 3a 74 3d a4 69 6e 74 28 62 2a | .b=zv:t=.int(b*| 00000140 78 29 3a e7 78 3c 3e 74 2f 62 20 8c 62 3d 7a 72 |x):.x<>t/b .b=zr| 00000150 3a 74 3d a4 69 6e 74 28 62 2a 78 29 0d 00 46 4a |:t=.int(b*x)..FJ| 00000160 fd b4 28 78 2d 74 2f 62 29 3d 30 3a 74 30 3d 31 |..(x-t/b)=0:t0=1| 00000170 3a 62 30 3d 30 3a 74 31 3d a4 69 6e 74 28 78 29 |:b0=0:t1=.int(x)| 00000180 3a 62 31 3d 31 3a e7 62 3c 94 74 20 8c 7a 6c 3d |:b1=1:.b<.t .zl=| 00000190 62 3a 7a 72 3d 74 2d 74 31 2a 62 3a 8b 7a 6c 3d |b:zr=t-t1*b:.zl=| 000001a0 74 3a 7a 72 3d 62 0d 00 50 23 e7 94 62 3e 3d 6d |t:zr=b..P#..b>=m| 000001b0 78 72 69 20 80 94 78 3c 31 2f 6d 78 72 69 20 84 |xri ..x<1/mxri .| 000001c0 62 3d 31 8c e5 8d 74 4c 40 0d 00 5a 4e f5 6a 3d |b=1...tL@..ZN.j=| 000001d0 a4 69 6e 74 28 7a 6c 2f 7a 72 29 3a 7a 76 3d 7a |.int(zl/zr):zv=z| 000001e0 6c 2d 6a 2a 7a 72 3a 7a 25 3d a4 63 73 67 6e 28 |l-j*zr:z%=.csgn(| 000001f0 31 2c 6a 2c 78 29 3a e7 7a 25 3c 3e 30 80 6a 3e |1,j,x):.z%<>0.j>| 00000200 3d 31 8c f2 75 70 63 66 28 31 2c 6a 29 8b e7 6a |=1..upcf(1,j)..j| 00000210 3c 31 8c 7a 25 3d 31 0d 00 64 3a 7a 6c 3d 7a 72 |<1.z%=1..d:zl=zr| 00000220 3a 7a 72 3d 7a 76 3a fd 7a 76 3d 30 84 7a 25 3d |:zr=zv:.zv=0.z%=| 00000230 30 3a e7 6a 3c 31 8c e5 8d 74 4c 40 8b 7a 25 3d |0:.j<1...tL@.z%=| 00000240 2d a4 63 73 67 6e 28 30 2c 31 2c 78 29 3a 69 3d |-.csgn(0,1,x):i=| 00000250 30 0d 00 6e 4a f5 69 3d 69 2a 32 2b 31 3a fd 7a |0..nJ.i=i*2+1:.z| 00000260 25 3c 3e a4 63 73 67 6e 28 31 2c 69 2c 78 29 84 |%<>.csgn(1,i,x).| 00000270 69 3e 3d 6a 3a 6a 3d 32 2a a4 69 6e 74 28 69 2f |i>=j:j=2*.int(i/| 00000280 6d 78 72 69 29 3a 69 3d 69 2f 32 2b 28 6a 2d 28 |mxri):i=i/2+(j-(| 00000290 6a 3d 30 29 29 2f 32 3a 6a 3d 30 0d 00 78 1d f5 |j=0))/2:j=0..x..| 000002a0 e7 7a 25 3d a4 63 73 67 6e 28 31 2c 6a 2b 69 2c |.z%=.csgn(1,j+i,| 000002b0 78 29 8c 6a 3d 6a 2b 69 0d 00 82 45 69 3d 69 2f |x).j=j+i...Ei=i/| 000002c0 32 3a fd 69 3d 2e 35 84 6a 2b 69 2a 32 3d 6a 3a |2:.i=.5.j+i*2=j:| 000002d0 e7 a4 63 73 67 6e 28 31 2c 6a 2b 69 2a 32 2c 78 |..csgn(1,j+i*2,x| 000002e0 29 3d 30 8c f2 75 70 63 66 28 31 2c 6a 2b 69 2a |)=0..upcf(1,j+i*| 000002f0 32 29 8b f2 75 70 63 66 28 31 2c 6a 29 0d 00 8c |2)..upcf(1,j)...| 00000300 2d e7 a4 63 73 67 6e 28 30 2c 31 2c 78 29 3d 30 |-..csgn(0,1,x)=0| 00000310 8c 74 3d a4 63 74 6f 70 28 30 2c 31 29 3a 62 3d |.t=.ctop(0,1):b=| 00000320 a4 63 62 6f 74 28 30 2c 31 29 0d 00 96 11 78 3d |.cbot(0,1)....x=| 00000330 78 2a 78 25 3a 74 3d 74 2a 78 25 0d 00 a0 1b f1 |x*x%:t=t*x%.....| 00000340 78 22 20 3d 20 22 3b 74 22 2f 22 3b 62 22 20 22 |x" = ";t"/";b" "| 00000350 3b 78 2d 74 2f 62 0d 00 aa 06 fd a3 0d 00 b4 05 |;x-t/b..........| 00000360 e0 0d 00 be 4d dd a4 66 72 61 63 28 78 29 e7 94 |....M..frac(x)..| 00000370 78 3e 3d 6d 78 72 69 20 8c 3d 30 8b e7 94 78 3c |x>=mxri .=0...x<| 00000380 6d 78 69 76 20 8c 3d 78 2d a8 78 3a 8b ea 79 3a |mxiv .=x-.x:..y:| 00000390 79 3d 6d 78 69 76 3a e7 94 78 3e 3d 79 20 8c f5 |y=mxiv:..x>=y ..| 000003a0 79 3d 79 2a 6d 78 69 76 3a fd 94 78 3c 79 0d 00 |y=y*mxiv:..x<y..| 000003b0 c8 22 f5 79 3d 79 2f 6d 78 69 76 3a 78 3d 78 2d |.".y=y/mxiv:x=x-| 000003c0 a8 28 78 2f 79 29 2a 79 3a fd 79 3d 31 3a 3d 78 |.(x/y)*y:.y=1:=x| 000003d0 0d 00 d2 17 dd a4 69 6e 74 28 78 29 3d 78 2d a4 |......int(x)=x-.| 000003e0 66 72 61 63 28 78 29 0d 00 dc 19 dd a4 63 74 6f |frac(x)......cto| 000003f0 70 28 69 2c 6a 29 3d 69 2a 74 30 2b 6a 2a 74 31 |p(i,j)=i*t0+j*t1| 00000400 0d 00 e6 19 dd a4 63 62 6f 74 28 69 2c 6a 29 3d |......cbot(i,j)=| 00000410 69 2a 62 30 2b 6a 2a 62 31 0d 00 f0 41 dd a4 63 |i*b0+j*b1...A..c| 00000420 66 72 63 28 69 2c 6a 29 ea 74 2c 62 3a 74 3d a4 |frc(i,j).t,b:t=.| 00000430 63 74 6f 70 28 69 2c 6a 29 3a 62 3d a4 63 62 6f |ctop(i,j):b=.cbo| 00000440 74 28 69 2c 6a 29 3a e7 62 3d 30 8c 3d 6d 78 72 |t(i,j):.b=0.=mxr| 00000450 76 2a b4 74 3a 8b 3d 74 2f 62 0d 00 fa 21 dd a4 |v*.t:.=t/b...!..| 00000460 63 73 67 6e 28 69 2c 6a 2c 78 29 3d b4 28 78 2d |csgn(i,j,x)=.(x-| 00000470 a4 63 66 72 63 28 69 2c 6a 29 29 0d 01 04 45 dd |.cfrc(i,j))...E.| 00000480 f2 75 70 63 66 28 69 2c 6a 29 ea 74 2c 62 3a 74 |.upcf(i,j).t,b:t| 00000490 3d a4 63 74 6f 70 28 69 2c 6a 29 3a 62 3d a4 63 |=.ctop(i,j):b=.c| 000004a0 62 6f 74 28 69 2c 6a 29 3a 74 30 3d 74 31 3a 74 |bot(i,j):t0=t1:t| 000004b0 31 3d 74 3a 62 30 3d 62 31 3a 62 31 3d 62 3a e1 |1=t:b0=b1:b1=b:.| 000004c0 0d ff |..| 000004c2