Anonymous user
Roots of unity: Difference between revisions
→{{header|REXX}}: added/changed whitespace and comments, simplified and optimized some functions.
(adding lambdatalk) |
(→{{header|REXX}}: added/changed whitespace and comments, simplified and optimized some functions.) |
||
Line 1,595:
(See the value of the REXX variable '''frac''', 4<sup>th</sup> line).
<lang rexx>/*REXX program computes the K roots of unity (which usually includes complex roots).*/
numeric digits length( pi() )
parse arg n frac . /*get optional arguments from the C.L. */
if n=='' | n=="," then n= 1 /*Not specified? Then use the default.*/
Line 1,601:
start= abs(n) /*assume only one K is wanted. */
if n<0 then start= 1 /*Negative? Then use a range of K's. */
do #=start to abs(n)
do angle=0 by pi*2/# for # /*compute the angle for each root. */
▲ say right(# 'roots of unity', 40, "─") ' (showing' frac "fractional decimal digits)"
if
end /*angle*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
adj: parse arg x; if abs(x) < ('1e-')(d*9%10) then x= 0; return format(x, , frac) / 1
pi: pi=3.141592653589793238462643383279502884197169399375105820974944592307816; return pi
r2r:
/*──────────────────────────────────────────────────────────────────────────────────────*/
do k=2 by 2 until p=z; p=z; _= -_ * $x / (k*(k-1)); z= z + _; end; return z
/*──────────────────────────────────────────────────────────────────────────────────────*/
sin: procedure; parse arg x;
if abs(x)=pi then return 0; z= x; _= x; $x= x * x
do k=2 by 2 until p=z; p=z; _= -_ * $x / (k*(k+1)); z= z + _; end; return z</lang>
|