Pathological floating point problems: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: used a template for the output sections.) |
m (→A sequence that seems to converge to a wrong limit: changed a comment and whitespace.) |
||
Line 2,208: | Line 2,208: | ||
<br>calculations, as well how many decimal digits (past the decimal point) should be displayed. |
<br>calculations, as well how many decimal digits (past the decimal point) should be displayed. |
||
===A sequence that seems to converge to a wrong limit=== |
===A sequence that seems to converge to a wrong limit=== |
||
<lang rexx>/*REXX pgm (pathological FP problem): a sequence that |
<lang rexx>/*REXX pgm (pathological FP problem): a sequence that might converge to a wrong limit. */ |
||
parse arg digs show . /*obtain optional arguments from the CL*/ |
parse arg digs show . /*obtain optional arguments from the CL*/ |
||
if digs=='' | digs=="," then digs= |
if digs=='' | digs=="," then digs= 150 /*Not specified? Then use the default.*/ |
||
if show=='' | show=="," then show= |
if show=='' | show=="," then show= 20 /* " " " " " " */ |
||
numeric digits digs /*have REXX use "digs" decimal digits. */ |
numeric digits digs /*have REXX use "digs" decimal digits. */ |
||
#= 2 4 5 6 7 8 9 20 30 50 100 /*the indices to display value of V.n */ |
#= 2 4 5 6 7 8 9 20 30 50 100 /*the indices to display value of V.n */ |
||
fin=word(#, words(#) ) |
fin= word(#, words(#) ) /*find the last (largest) index number.*/ |
||
w=length(fin) |
w= length(fin) /* " " length (in dec digs) of FIN.*/ |
||
v.1= 2 /*the value of the first V element. */ |
v.1= 2 /*the value of the first V element. */ |
||
v.2=-4 /* " " " " second " " */ |
v.2=-4 /* " " " " second " " */ |
||
do n=3 to fin; nm1= n-1; nm2= n-2 /*compute some values of the V elements*/ |
|||
v.n= 111 - 1130/v.nm1 + 3000/(v.nm1*v.nm2) /* " a value of a " element.*/ |
|||
if wordpos(n, #)\==0 then say 'v.'left(n, w) "=" format(v.n, , show) |
|||
end /*n*/ /*display digs past the dec. point───┘ */ |
|||
/*stick a fork in it, we're all done. */</lang> |
/*stick a fork in it, we're all done. */</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |