Talk:Roots of unity: Difference between revisions

Seed7 uses a similar convention as Algol68
(Seed7 problems)
 
(Seed7 uses a similar convention as Algol68)
Line 1:
I think the Seed7 output has its real and imaginary parts reversed. (1.000*i)<sup>2</sup> is -1 not 1. --[[User:Mwn3d|Mwn3d]] 07:14, 21 January 2008 (MST)
 
Seed7 uses a similar convention as Algol68:
The i is the separator between real and imaginary part
(well in Algol68 it seems to be an i with an underscore which IIRC is a different alphabet).
The output of -0.5000i+0.8660 means -0.5000+i*0.8660 which might be counter intuitive.
I choosed it that way to make the 'parse' function (which converts a string to a complex) easy implementable as:
<pre>
(**
* Return the conversion of a string to a complex.
*)
const func complex: (attr complex) parse (in string: stri) is func
result
var complex: result is complex.value;
local
var integer: iPos is 0;
begin
iPos := pos(stri, 'i'); # Find the position of the i
if iPos <> 0 then
result.re := float parse (stri[.. pred(iPos)]);
result.im := float parse (stri[succ(iPos) ..]);
else
raise RANGE_ERROR;
end if;
end func;
</pre>
Maybe you have suggestions of how the output of a complex number should look like.
If I write a complex number as -0.5000+i*0.8660 the 'parse' function could be:
<pre>
(**
* Return the conversion of a string to a complex.
*)
const func complex: (attr complex) parse (in string: stri) is func
result
var complex: result is complex.value;
local
var integer: iPos is 0;
begin
iPos := pos(stri, 'i'); # Find the position of the i
if iPos > 1 then
result.re := float parse (stri[.. iPos - 2]);
result.im := float parse (stri[iPos + 2 ..]);
if stri[pred(iPos)] = '-' then
result.im := -result.im;
elsif stri[pred(iPos)] <> '-' then
raise RANGE_ERROR;
end if;
if stri[succ(iPos) len 1] <> "*" then
raise RANGE_ERROR;
end if;
else
raise RANGE_ERROR;
end if;
end func;
</pre>
What do you think? [[User:Thomas Mertes|Thomas Mertes]] 09:35, 21 January 2008 (MST)