The question indicates which areas need to be considered, though I'll add the problem of how to construct a complex value. You can think of it as part of operators, coercions, declarations, or etc., as you like.
First off, the complex number would be represented as a real and imaginary part, each with the same precision as a real number.
(
<x>,
<y>)
denoting a complex number formed from
two reals or integers, <x> and <y>. The complex number has the value
<x>+<y>i, where i is the imaginary.
(
<x>,
<y>)
is not already a legal expression, so
the compiler will be able to recognize it as something
special.
It might, however, leave programmers a little confused, as
func(a, b)
calls func
with two arguments, while
func((a, b))
calls it with a single complex argument.
To really get fancy, we could also allow something like
(
<r>@
<t>)
to specify a complex number in polar
co-ordinates. Of course, then you'd have to decide if <t> is
in radians or degrees. Probably not worth it.
An alternative would be to specify a symbol to represent the
imaginary. Using Algol's multilevel notation, we could just call it i.
It would simply represent the complex number 0+1i.
Then, complex numbers could be formed using the regular arithmetic
operations, plus coercion from real to complex (see below).
For instance, 5.1 + 3.2*
i.
This is perhaps a more elegant solution, but it leaves the problem
of how to write i to the implementor. He might be lazy and make
i
a reserved word, which is a terrible idea. Perhaps #i
would
be tolerable. There doesn't seem to be any wonderful choice for the
notation.
+
, -
, *
and /
are
defined for complex numbers, and yield a complex result.
FORTRAN also has an exponent operator, which will work the same way.
We would also need some way to extract the real and imaginary parts of a complex number as real numbers. The simplest thing is probably a notation like Re(<x>) or Im(<x>) for the real and imaginary parts of <x>, respectively.
=
and <>
make sense for complex; the
other standard relations, <
, <=
, >
and >=
do not.
I would leave it at that. The programmer can use Re and
Im to build any desired ordering.
It might also be desirable to specify a list of "standard" library functions which would work with complex numbers, such as absolute value, or various kinds of orderings.
![]() |