octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apple atan2f


From: Jarno Rajahalme
Subject: Re: Apple atan2f
Date: Thu, 11 Nov 2010 10:19:09 +0200


On Nov 11, 2010, at 9:25 , ext Michael D Godfrey wrote:

On 11/10/2010 11:17 PM, Ben Abbott wrote:
Rather than "Intel", I assume you mean "Apple".

Right. I meant Apple/Intel.
I don't think this was intentional, but if it was, I'd qualify it as a bug since it is a violation of the IEEE standard.

Well, not quite a violation of IEEE since there are rounding choices, but almost surely not
a good choice.  I think there is a reference implementation of the elementary functions,
but right now I cannot remember where it is.  It may include specification about rounding
as well as the algorithms.

Michael



See below the related C standard text (as found from http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.htm). Note the paragraph #3, which specifies the range of returned values. Returning single(pi) using the normal rounding rules is simply wrong, as the result is outside of the prescibed range, since single(pi) > pi. Note that it happens that the double representation of PI happens to round towards zero, so double(pi) is in the right range.

Returning a value on the wrong side of PI puts the returned angle to the wrong quadrant of the circle, flipping the sign of the tan function, for example:

single(pi) > PI:

octave:76> tan(double(single(pi)))
ans =  8.74227800037251e-08

rounding towards zero:

octave:77> tan(double(single(pi-1e-7)))
ans = -1.50995799097839e-07
octave:78> 


  242          Committee Draft  --  August 3, 1998   WG14/N843


       7.12.4.4  The atan2 functions

       Synopsis

       [#1]

               #include <math.h>
               double atan2(double y, double x);
               float atan2f(float y, float x);
               long double atan2l(long double y, long double x);

       Description

       [#2] The atan2 functions compute the principal value of  the
       arc  tangent  of  y/x,  using the signs of both arguments to
       determine the quadrant of the return value.  A domain  error
       may occur if both arguments are zero.

       Returns

       [#3]  The  atan2 functions return the arc tangent of y/x, in
       the range [-pi, +pi] radians.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]