Roots of unity: Difference between revisions

Content deleted Content added
m →‎{{header|REXX}}: removed the "style" from the PRE html tags.
Peak (talk | contribs)
jq
Line 593:
}</lang>
 
=={{header|jq}}==
Using the same example as Julia and representing x + i*y as [x,y]:
<lang jq>def nthroots(n):
(8 * (1|atan)) as $twopi
| range(0;n) | (($twopi * .) / n) as $angle | [ ($angle | cos), ($angle | sin) ];
 
nthroots(10)</lang><lang jq>$ uname -a
Darwin Mac-mini 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
 
$ time jq -c -n -f Roots_of_unity.jq
[1,0]
[0.8090169943749475,0.5877852522924731]
[0.30901699437494745,0.9510565162951535]
[-0.30901699437494734,0.9510565162951536]
[-0.8090169943749473,0.5877852522924732]
[-1,1.2246467991473532e-16]
[-0.8090169943749475,-0.587785252292473]
[-0.30901699437494756,-0.9510565162951535]
[0.30901699437494723,-0.9510565162951536]
[0.8090169943749473,-0.5877852522924732]
 
real 0m0.015s
user 0m0.004s
sys 0m0.004s
</lang jq>
=={{header|Julia}}==
<lang julia>nthroots(n::Integer) = [ cospi(2k/n)+sinpi(2k/n)im for k = 0:n-1 ]</lang>