Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

atan(0,0) bug

65 views
Skip to first unread message

Doo Jin Cho

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
Scilab produces error for

-->atan(0,0)
!--error 32
singularity of log or tan function

How to deal with it?


Frank Miles

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
In article <7csd1t$j3...@news.ajou.ac.kr>,

You probably need to write your code so that you don't try it,
since this function is not defined for (0,0). Alternatively,
if you don't care about the answer, and the input values are
restricted, and the precision of the answers isn't too critical
{enough disclaimers yet??} you could add some small value to
one or the other component to avoid the origin.

-frank


Wolfgang von Hansen

unread,
Mar 19, 1999, 3:00:00 AM3/19/99
to
In article <7csd1t$j3...@news.ajou.ac.kr> "Doo Jin Cho" <dj...@madang.ajou.ac.kr> writes:
>Scilab produces error for
>
>-->atan(0,0)
> !--error 32
>singularity of log or tan function
>
>How to deal with it?

That expression is undefined from the mathematical point of view, so do not
try to use it. atan(x,y) is used to calculate atan(x/y) but also takes the
signs of x and y into account and y is allowed to be zero. atan(0,0) has 0/0
as subexpression which is undefined; the atan of an undefined value is also
undefined.

Or, to be more concise, you can't compute the azimut of the null vector.

Wolfgang
--
Wolfgang von Hansen, IPF, Universitaet Karlsruhe, Tel. +49 (0)721 608-6993

Doo Jin Cho

unread,
Mar 20, 1999, 3:00:00 AM3/20/99
to
Thanks for your comments. Although I agree about ill-definition of
atan(0,0), it would be better to assign zero instead of producing error. For
example, Matlab and visual c++ give zero for atan2(0,0). It is cumbersome
and against the merit of an vectorized language like scilab for programmers
to care about this problem as you suggested.

Frank Miles <7css2a$508$1...@nntp6.u.washington.edu> wrote:
>Doo Jin Cho <dj...@madang.ajou.ac.kr> wrote:

>>-->atan(0,0)
>> !--error 32
>>singularity of log or tan function
>

HO...@psfc.mit.edu

unread,
Mar 22, 1999, 3:00:00 AM3/22/99
to

There is no reasonable way to choose a default value for atan2(0,0).

If you consider starting at any point on the plane (so atan2(x,y) is well defined)
and moving in a straight line to the origin, atan2 should remain constant.
Therefore any choice for atan2(0,0) is mathematically wrong, and may introduce
an unexpected error in a code that relies on correct mathematical behavior.

The right way is to check if you are on the origin before calling atan2.


Steve

In a previous article, "Doo Jin Cho" <dj...@madang.ajou.ac.kr> wrote:
->Thanks for your comments. Although I agree about ill-definition of
->atan(0,0), it would be better to assign zero instead of producing error. For
->example, Matlab and visual c++ give zero for atan2(0,0). It is cumbersome
->and against the merit of an vectorized language like scilab for programmers
->to care about this problem as you suggested.
->
->Frank Miles <7css2a$508$1...@nntp6.u.washington.edu> wrote:
->>Doo Jin Cho <dj...@madang.ajou.ac.kr> wrote:
->>>-->atan(0,0)
->>> !--error 32
->>>singularity of log or tan function
->>
->>You probably need to write your code so that you don't try it,
->>since this function is not defined for (0,0). Alternatively,
->>if you don't care about the answer, and the input values are
->>restricted, and the precision of the answers isn't too critical
->>{enough disclaimers yet??} you could add some small value to
->>one or the other component to avoid the origin.
->
->
->

0 new messages