POK
/home/jaouen/pok_official/pok/trunk/libpok/libm/sin.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Fri Jan 30 14:41:34 2009 
00015  */
00016 
00017 /* @(#)s_sin.c 5.1 93/09/24 */
00018 /*
00019  * ====================================================
00020  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00021  *
00022  * Developed at SunPro, a Sun Microsystems, Inc. business.
00023  * Permission to use, copy, modify, and distribute this
00024  * software is freely granted, provided that this notice
00025  * is preserved.
00026  * ====================================================
00027  */
00028 
00029 /* sin(x)
00030  * Return sine function of x.
00031  *
00032  * kernel function:
00033  *      __kernel_sin            ... sine function on [-pi/4,pi/4]
00034  *      __kernel_cos            ... cose function on [-pi/4,pi/4]
00035  *      __ieee754_rem_pio2      ... argument reduction routine
00036  *
00037  * Method.
00038  *      Let S,C and T denote the sin, cos and tan respectively on
00039  *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
00040  *      in [-pi/4 , +pi/4], and let n = k mod 4.
00041  *      We have
00042  *
00043  *          n        sin(x)      cos(x)        tan(x)
00044  *     ----------------------------------------------------------
00045  *          0          S           C             T
00046  *          1          C          -S            -1/T
00047  *          2         -S          -C             T
00048  *          3         -C           S            -1/T
00049  *     ----------------------------------------------------------
00050  *
00051  * Special cases:
00052  *      Let trig be any of sin, cos, or tan.
00053  *      trig(+-INF)  is NaN, with signals;
00054  *      trig(NaN)    is that NaN;
00055  *
00056  * Accuracy:
00057  *      TRIG(x) returns trig(x) nearly rounded
00058  */
00059 
00060 #ifdef POK_NEEDS_LIBMATH
00061 
00062 #include <libm.h>
00063 #include "namespace.h"
00064 #include "math_private.h"
00065 
00066 #if 0 /* notyet */
00067 #ifdef __weak_alias
00068 __weak_alias(sin, _sin)
00069 #endif
00070 #endif
00071 
00072 double
00073 sin(double x)
00074 {
00075         double y[2],z=0.0;
00076         int32_t n, ix;
00077 
00078     /* High word of x. */
00079         GET_HIGH_WORD(ix,x);
00080 
00081     /* |x| ~< pi/4 */
00082         ix &= 0x7fffffff;
00083         if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
00084 
00085     /* sin(Inf or NaN) is NaN */
00086         else if (ix>=0x7ff00000) return x-x;
00087 
00088     /* argument reduction needed */
00089         else {
00090             n = __ieee754_rem_pio2(x,y);
00091             switch(n&3) {
00092                 case 0: return  __kernel_sin(y[0],y[1],1);
00093                 case 1: return  __kernel_cos(y[0],y[1]);
00094                 case 2: return -__kernel_sin(y[0],y[1],1);
00095                 default:
00096                         return -__kernel_cos(y[0],y[1]);
00097             }
00098         }
00099 }
00100 
00101 #endif