Anonymous user
Roots of a quadratic function: Difference between revisions
m
→version 1: simplified expressions in the subroutine and also the function, added an output case to show different formatting for another REXX.
m (→version 1: simplified expressions in the subroutine and also the function, added an output case to show different formatting for another REXX.) |
|||
Line 1,750:
Since "unlimited" decimal precision is part of the REXX language, the '''numeric digits''' was increased
<br>(from a default of '''9''') to '''200''' to accommodate when a root is closer to zero than the other root.
Note that only ten decimal digits (precision) are shown in the ''displaying'' of the output.
This REXX version supports ''complex numbers'' for the result.
Line 1,772:
quadratic: parse arg aa,bb,cc /*obtain the specified three arguments.*/
$=sqrt(bb**2-4*aa*cc); L=length($) /*compute SQRT (which may be complex).*/
if
return
/*────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x 1 ox; if x=0 then return 0; d=digits()
numeric digits 9; numeric form; h=d+6;
parse value format(x,2,1,,0) 'E0' with g 'E' _ .;
do j=0 while h>9; m.j=h; h=h%2+1;
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5;
numeric digits d;
'''output''' when using the input of: <tt> 1 -10e5 1 </tt>
<pre>
Line 1,792:
root2 = 0.000001
</pre>
The following output is when Regina 3.9.1 REXX is used.
'''output''' when using the input of: <tt> 1 -10e9 1 </tt>
<pre>
Line 1,800 ⟶ 1,802:
root1 = 1.000000000E+10
root2 = 1E-10
</pre>
The following output is when R4 REXX is used.
'''output''' when using the input of: <tt> 1 -10e9 1 </tt>
<pre>
a = 1
b = -1E+10
c = 1
root1 = 1E+10
root2 = 0.0000000001
</pre>
'''output''' when using the input of: <tt> 3 2 1 </tt>
|