1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * These math functions are taken from newlib-nano-2, the newlib/libm/math
5  * directory, available from https://github.com/32bitmicro/newlib-nano-2.
6  *
7  * Appropriate copyright headers are reproduced below.
8  */
9 
10 /* kf_sin.c -- float version of k_sin.c
11  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
12  */
13 
14 /*
15  * ====================================================
16  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
17  *
18  * Developed at SunPro, a Sun Microsystems, Inc. business.
19  * Permission to use, copy, modify, and distribute this
20  * software is freely granted, provided that this notice
21  * is preserved.
22  * ====================================================
23  */
24 
25 #include "fdlibm.h"
26 
27 #ifdef __STDC__
28 static const float
29 #else
30 static float
31 #endif
32 half =  5.0000000000e-01f,/* 0x3f000000 */
33 S1  = -1.6666667163e-01f, /* 0xbe2aaaab */
34 S2  =  8.3333337680e-03f, /* 0x3c088889 */
35 S3  = -1.9841270114e-04f, /* 0xb9500d01 */
36 S4  =  2.7557314297e-06f, /* 0x3638ef1b */
37 S5  = -2.5050759689e-08f, /* 0xb2d72f34 */
38 S6  =  1.5896910177e-10f; /* 0x2f2ec9d3 */
39 
40 #ifdef __STDC__
__kernel_sinf(float x,float y,int iy)41 	float __kernel_sinf(float x, float y, int iy)
42 #else
43 	float __kernel_sinf(x, y, iy)
44 	float x,y; int iy;		/* iy=0 if y is zero */
45 #endif
46 {
47 	float z,r,v;
48 	__int32_t ix;
49 	GET_FLOAT_WORD(ix,x);
50 	ix &= 0x7fffffff;			/* high word of x */
51 	if(ix<0x32000000)			/* |x| < 2**-27 */
52 	   {if((int)x==0) return x;}		/* generate inexact */
53 	z	=  x*x;
54 	v	=  z*x;
55 	r	=  S2+z*(S3+z*(S4+z*(S5+z*S6)));
56 	if(iy==0) return x+v*(S1+z*r);
57 	else      return x-((z*(half*y-v*r)-y)-v*S1);
58 }
59