Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,61 @@
/*NetRexx program to convert decimal numbers to fractions *************
* 16.08.2012 Walter Pachl derived from Rexx Version 2
**********************************************************************/
options replace format comments java crossref savelog symbols
Numeric Digits 10 /* use "only" 10 digs of precision */
ratt('0.9054054054','67/74')
ratt('0.5185185185','14/27')
ratt('0.75' ,'3/4')
ratt('0.905405400',' 693627417/766095958')
ratt('0.9054054054','67/74')
ratt('0.1428571428','1/7')
ratt('35.000','35')
ratt('35.001','35001/1000')
ratt('0.00000000001','?')
ratt('0.000001000001','1/999999')
ratt(0.9054054054,'1/3')
method ratt(d = Rexx,fs = Rexx) public static
fract=rat(d)
Say ' 'd '->' fract
Parse fract no '/' de
If de='' Then x=no
Else x=no/de
If x<>d Then
Say '> '||x 'is different'
method rat(in, high='') public static
/**********************************************************************
* rat(number<,high) returns a fraction or an integer that is equal to
* or approximately equal to number.
* Nominator and denominator must not have more than high digits
* 16.08.2012 Walter Pachl derived from Rexx Version 2
**********************************************************************/
if high=='' then
high=10**(digits - 1) /* maximum nominator/denominator */
x=in /* working copy */
nom=0 /* start values nominator */
den=1 /* denominator */
tnom=1 /* temp nominator */
tden=0 /* temp denominator */
loop While tnom<=high & tden<=high /* nominator... not too large */
n=x.trunc() /* take integer part of x */
z=tnom; /* save temp nominator */
tnom=n*tnom+nom; /* compute new temp nominator */
nom=z /* assign nominator */
z=tden; /* save temp denominator */
tden=n*tden+den /* compute new temp denominato*/
den=z /* assign denominator */
if n=x | tnom/tden=in then do
if tnom>high | tden>high then /* temp value(s) too large */
Leave /* don't use them */
nom=tnom /* otherwise take them as */
den=tden /* final values */
leave /* and end the loop */
end
x=1/(x-n) /* compute x for next round */
end
If den=1 Then Return nom /* an integer */
Else Return nom'/'den /* otherwise a fraction */