Anonymous user
Minkowski question-mark function: Difference between revisions
m
→{{header|REXX}}: increased the number of decimal digits (precision), made code simpler, optimized some code.
No edit summary |
m (→{{header|REXX}}: increased the number of decimal digits (precision), made code simpler, optimized some code.) |
||
Line 803:
{{trans|Phix}}
<lang rexx>/*REXX program uses the Minkowski question─mark function to convert a continued fraction*/
numeric digits
say fmt( mink( 0.5 * (1+sqrt(5) ) ) )
say fmt( minkI(-5/9) ) fmt( (sqrt(13) - 7) / 6)
say fmt( mink( minkI(0.718281828) ) ) fmt( mink( minkI(.1213141516171819) ) )
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
floor: procedure; parse arg x;
fmt: procedure: parse arg
/*──────────────────────────────────────────────────────────────────────────────────────*/
mink: procedure: parse arg x; p= x % 1; if x>1 | x<0 then return p + mink(x-p)
Line 825:
minkI: procedure; parse arg x; p= floor(x); if x>1 | x<0 then return p + minkI(x-p)
if x=1 | x=0 then return x
#= 1 /*#: is the count. */
do until
if
else do; $= $
else if x>1 then do;
else do; $= $
if x==floor(x)
end /*until*/
z= words($)
return 1 / ret
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 847 ⟶ 846:
{{out|output|text= when using the internal default inputs:}}
<pre>
1.66666666666666666666666666673007566392 1.66666666666666666666666666666666666667
-0.56574145408933511781346312208825067563 -0.56574145408933511781346312208825067562
0.71828182799999999999999999999999992890 0.12131415161718190000000000000000000833
</pre>
|