You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Log and Phase functions in the math/cmplx library are too permissive. They should be
defined on the standard branch of the complex logarithm, but are in fact defined on the
whole punctured complex plane. Details follow.
> What does 'go version' print?
go version go1.3.3 linux/amd64
> What steps reproduce the problem?
> If possible, include a link to a program on play.golang.org.
Calculate the complex logarithm of 1, i, -1 and -1. See here:
http://play.golang.org/p/imVbDZGdMw
> What happened?
From what I understand of the comments in the source, the Phase function (used in Log)
should return the arguments of a complex number in the range [-Pi,Pi]. It can not do
this for purely mathematical reasons (see the first paragraph of
http://en.wikipedia.org/wiki/Complex_logarithm#Branches_of_the_complex_logarithm).
> What should have happened instead?
I'm guessing that the authors wanted to define the principal branch of the complex
logarithm; the one that excludes the negative real line. Then
cmplx.Log(complex(-1,0))
should have returned an error or some kind of 'not a number' type.
> Please provide any additional information below.
The Wikipedia article on the complex logarithm:
http://en.wikipedia.org/wiki/Complex_logarithm
Any introductory textbook or course on complex analysis will have all the details.
I'd like to stress that this is really a problem. Since Go has complex numbers and
functions to deal with them built in, users will be inclined to trust and use them. That
the logarithm and phase functions do not have explicit branches selected and in fact
accept all arguments can and will cause very subtle and difficult to find bugs in the
programs of people who will want to use Go for calculations with complex numbers. (Julia
and Mandelbrot fractals are one example of applications of such calculations.) Those
people *will* blame Go for these bugs when they arise.
A possible solution is to decide and say explicitly that the library functions for
complex numbers in Go use the principal branch, and then modify the functions to return
errors when given purely negative real numbers. Users can then roll their own custom
branch logarithms if they want.
Thanks,
gthm
The text was updated successfully, but these errors were encountered:
by gunnarthormagnusson:
The text was updated successfully, but these errors were encountered: