Roots of unity: Difference between revisions

Roots of unity in various BASIC dialents (BASIC256, True BASIC and Yabasic)
m ((Dialects of BASIC moved to the BASIC section.))
(Roots of unity in various BASIC dialents (BASIC256, True BASIC and Yabasic))
Line 233:
'all the way around the circle at even intervals
LOOP WHILE angle < 2 * PI</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">twopi = 2 * pi
n = 5
 
for m = 0 to n-1
theta = m*twopi/n
real = cos(theta)
imag = sin(theta)
if imag >= 0 then
print ljust(string(real),9,"0"); " + "; ljust(string(imag),13,"0"); "i"
else
print ljust(string(real),9,"0"); " - "; ljust(string(-imag),13,"0"); "i"
end if
next m</syntaxhighlight>
 
==={{header|BBC BASIC}}===
Line 394 ⟶ 409:
For n=3 in exact mode, the results are
<syntaxhighlight lang="ti89b">{-1/2+√(3)/2*i, -1/2-√(3)/2*i, 1}</syntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|BASIC}}
<syntaxhighlight lang="qbasic">LET num_pi = 3.1415926
LET n = 5 !this can be changed for any desired n
LET angle = 0 !start at angle 0
DO
LET real = COS(angle) !real axis is the x axis
IF (ABS(real) < 10^(-5)) THEN !get rid of annoying sci notation
LET real = 0
END IF
LET imag = SIN(angle) !imaginary axis is the y axis
IF (ABS(imag) < 10^(-5)) THEN !get rid of annoying sci notation
LET imag = 0
END IF
PRINT real; "+"; imag; "i" !answer on every line
LET angle = angle+(2*num_pi)/n
!all the way around the circle at even intervals
LOOP WHILE angle < 2*num_pi
END</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="freebasic">twopi = 2 * pi
n = 5
 
for m = 0 to n-1
theta = m*twopi/n
real = cos(theta)
imag = sin(theta)
if imag >= 0 then
print real using("##.########"), " + ", imag using("#.########"), "i"
else
print real using("##.########"), " + ", -imag using("#.########"), "i"
end if
next m</syntaxhighlight>
 
 
=={{header|Ursala}}==
2,122

edits