sin.c
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: sin.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/10/30 02:07:09 $
=============================================================================
関数名:sin
-----------------------------------------------------------------------------
書式: #include <math.h>
double sin(double t);
引数: t ラディアン角
戻り値:サイン
説明: 引数 t からサインを求めます。
sin(t) = (t^1/1!) - (t^3/3!) + (t^5/5!) - (t^7/7!)
+- ... t^(2n+1)/(2n+1)!
sin(t) = t (1 + t^2 * (-1/3! + t^2 * (1/5! + t^2 * (-1/7! + .... )))
-----------------------------------------------------------------------------
*/
#include "math.h"
#define S0 (-1.666666666667e-1 ) /* -1/(3!) */
#define S1 ( 8.333333333333e-3 ) /* 1/(5!) */
#define S2 (-1.984126984127e-4 ) /* -1/(7!) */
#define S3 ( 2.755731922399e-6 ) /* 1/(9!) */
#define S4 (-2.505210838544e-8 ) /* -1/(11!) */
#define S5 ( 1.605904383682e-10) /* 1/(13!) */
#define S6 (-7.64716373182e-13 ) /* -1/(15!) */
#define S7 ( 2.811457254346e-15) /* 1/(17!) */
double sin(double t)
{
double q, qq;
long tn;
tn = (t / DVAL_PI) + (t>=0 ? 0.5 : -0.5);
t = t - tn * DVAL_PI;
if (fabs(t) > DBL_EPSILON) {
q = t * t;
qq = q * (S0 + q * (S1 + q * (S2 + q * (S3 + q * (S4 + q * (S5 + q * (S6 + q * S7)))))));
t = t + t * qq;
}
if (tn & 0x01) return -t;
else return t;
}