source: trunk/libs/newlib/src/newlib/libm/math/s_sin.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.7 KB
Line 
1
2/* @(#)s_sin.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/*
15FUNCTION
16        <<sin>>, <<sinf>>, <<cos>>, <<cosf>>---sine or cosine
17INDEX
18sin
19INDEX
20sinf
21INDEX
22cos
23INDEX
24cosf
25SYNOPSIS
26        #include <math.h>
27        double sin(double <[x]>);
28        float  sinf(float <[x]>);
29        double cos(double <[x]>);
30        float cosf(float <[x]>);
31
32DESCRIPTION
33        <<sin>> and <<cos>> compute (respectively) the sine and cosine
34        of the argument <[x]>.  Angles are specified in radians.
35
36        <<sinf>> and <<cosf>> are identical, save that they take and
37        return <<float>> values.
38
39
40RETURNS
41        The sine or cosine of <[x]> is returned.
42
43PORTABILITY
44        <<sin>> and <<cos>> are ANSI C.
45        <<sinf>> and <<cosf>> are extensions.
46
47QUICKREF
48        sin ansi pure
49        sinf - pure
50*/
51
52/* sin(x)
53 * Return sine function of x.
54 *
55 * kernel function:
56 *      __kernel_sin            ... sine function on [-pi/4,pi/4]
57 *      __kernel_cos            ... cose function on [-pi/4,pi/4]
58 *      __ieee754_rem_pio2      ... argument reduction routine
59 *
60 * Method.
61 *      Let S,C and T denote the sin, cos and tan respectively on
62 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
63 *      in [-pi/4 , +pi/4], and let n = k mod 4.
64 *      We have
65 *
66 *          n        sin(x)      cos(x)        tan(x)
67 *     ----------------------------------------------------------
68 *          0          S           C             T
69 *          1          C          -S            -1/T
70 *          2         -S          -C             T
71 *          3         -C           S            -1/T
72 *     ----------------------------------------------------------
73 *
74 * Special cases:
75 *      Let trig be any of sin, cos, or tan.
76 *      trig(+-INF)  is NaN, with signals;
77 *      trig(NaN)    is that NaN;
78 *
79 * Accuracy:
80 *      TRIG(x) returns trig(x) nearly rounded
81 */
82
83#include "fdlibm.h"
84
85#ifndef _DOUBLE_IS_32BITS
86
87#ifdef __STDC__
88        double sin(double x)
89#else
90        double sin(x)
91        double x;
92#endif
93{
94        double y[2],z=0.0;
95        __int32_t n,ix;
96
97    /* High word of x. */
98        GET_HIGH_WORD(ix,x);
99
100    /* |x| ~< pi/4 */
101        ix &= 0x7fffffff;
102        if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
103
104    /* sin(Inf or NaN) is NaN */
105        else if (ix>=0x7ff00000) return x-x;
106
107    /* argument reduction needed */
108        else {
109            n = __ieee754_rem_pio2(x,y);
110            switch(n&3) {
111                case 0: return  __kernel_sin(y[0],y[1],1);
112                case 1: return  __kernel_cos(y[0],y[1]);
113                case 2: return -__kernel_sin(y[0],y[1],1);
114                default:
115                        return -__kernel_cos(y[0],y[1]);
116            }
117        }
118}
119
120#endif /* _DOUBLE_IS_32BITS */
Note: See TracBrowser for help on using the repository browser.