Anonymous user
Roots of a quadratic function: Difference between revisions
m
→version 1: changed some variable names for easier perusing.
m (→version 1: change a comment to use gooder English in the REXX section header.) |
m (→version 1: changed some variable names for easier perusing.) |
||
Line 1,611:
The REXX language doesn't have a '''sqrt''' function, nor does it have complex numbers.
<br>Since "unlimited" decimal precision is part of the language, the NUMERIC DIGITS
<br>was increased (from a default of 9) to 120 to
<br>Note that only 10 digits are shown in the output (precision).
<lang rexx>/*REXX program finds the roots (may be complex) of a quadratic function.*/
Line 1,617:
parse arg a b c . /*get specified arguments: A B C*/
a=a/1; b=b/1; c=c/1 /*normalize the three numbers. */
call quadratic a
numeric digits sqrt(digits())%1 /*reduce digits for human beans. */
r1=r1/1;
if r1j\=0 then r1=r1 || left('+',r1j>0)(r1j/1)"i" /*handle complex num.*/
r2=r2/1 /* " " " " " */▼
if
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────QUADRATIC subroutine────────────────*/
quadratic: parse arg aa
aa2=1
if right(
r1=-bb*aa2; r2=r1;
end
else do /*the roots are real (¬complex).*/
r1=(-bb+
end
return
/*──────────────────────────────────SQRT subroutine─────────────────────*/
sqrt: procedure;
numeric digits 11;
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'E'_%2
do j=0 while p>9; m.j=p; p=p%2+1; end /*calculate DIGITS needed.*/
numeric digits d; return (g/1)i
'''output''' when using the input of: <tt> 1 -10e5 1 </tt>
<pre>
|