|
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:
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. |
[Prev in Thread] | Current Thread | [Next in Thread] |