On Tue, Sep 26, 2017 at 06:21:16PM +0200, Jan Stary wrote:

> These (diff below) seem to be obvious typos in k_sin.c,
> but only in comments. The comment that says
> 
>       if x < 2^-27 (hx<0x3e400000), return x with inexact if x!=0
> 
> also puzzles me a bit: what the code does is
> 
>       GET_HIGH_WORD(ix,x);
>       ix &= 0x7fffffff;                       /* high word of x */
>       if(ix<0x3e400000)                       /* |x| < 2**-27 */
>               {if((int)x==0) return x;}       /* generate inexact */
> 
> If the high word of a double x is less than 0x3e400000,
> how could (int)x be anything else than zero?

The result might be zero, but you want the inexact flag to be set in
those cases. I think case 2 describes it correctly: only return 0 with
the inexact flag not set if x equals zero.

        -Otto

> 
> The "if x!= 0" also puzzles me: the sine of zero _is_ zero, exactly.
> What would change with this:
> 
>       if (ix < 0x3e400000)
>               return x;
> 
> What is the role of the iy indicator?
> Is it easier/faster to test the integer indicator for iy == 0
> than it would be to test y == 0 itself? Or is there another reason?
> 
>  Jan
> 
> 
> Index: k_sin.c
> ===================================================================
> RCS file: /cvs/src/lib/libm/src/k_sin.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 k_sin.c
> --- k_sin.c   27 Oct 2009 23:59:30 -0000      1.3
> +++ k_sin.c   26 Sep 2017 16:07:45 -0000
> @@ -10,15 +10,15 @@
>   * ====================================================
>   */
>  
> -/* __kernel_sin( x, y, iy)
> +/* __kernel_sin(x, y, iy)
>   * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
>   * Input x is assumed to be bounded by ~pi/4 in magnitude.
>   * Input y is the tail of x.
> - * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). 
> + * Input iy indicates whether y is 0. (if iy=0, assume y to be 0). 
>   *
>   * Algorithm
>   *   1. Since sin(-x) = -sin(x), we need only to consider positive x. 
> - *   2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
> + *   2. if x < 2^-27 (hx<0x3e400000), return x with inexact if x!=0.
>   *   3. sin(x) is approximated by a polynomial of degree 13 on
>   *      [0,pi/4]
>   *                            3            13

Reply via email to